AliPhysics  bba8f44 (bba8f44)
TestAliEmcalTrackSelection.cxx
Go to the documentation of this file.
1 // clang-format off
2 /************************************************************************************
3  * Copyright (C) 2017, Copyright Holders of the ALICE Collaboration *
4  * All rights reserved. *
5  * *
6  * Redistribution and use in source and binary forms, with or without *
7  * modification, are permitted provided that the following conditions are met: *
8  * * Redistributions of source code must retain the above copyright *
9  * notice, this list of conditions and the following disclaimer. *
10  * * Redistributions in binary form must reproduce the above copyright *
11  * notice, this list of conditions and the following disclaimer in the *
12  * documentation and/or other materials provided with the distribution. *
13  * * Neither the name of the <organization> nor the *
14  * names of its contributors may be used to endorse or promote products *
15  * derived from this software without specific prior written permission. *
16  * *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
20  * DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
27  ************************************************************************************/
28 // clang-format on
29 #include <iostream>
30 
31 #include <THistManager.h>
32 #include <TObjArray.h>
33 
34 #include "AliAODEvent.h"
35 #include "AliAODTrack.h"
36 #include "AliAnalysisManager.h"
37 #include "AliESDtrackCuts.h"
39 #include "AliLog.h"
40 
42 
47 
48 namespace PWG {
49 namespace EMCAL {
51  : AliAnalysisTaskEmcalLight(), fPeriod(), fTestSuite(nullptr), fTestResults(nullptr) {}
52 
55 
57  if (fTestSuite)
58  delete fTestSuite;
59 }
60 
63 
65 
66  fTestResults = new THistManager("testresults");
67  for (auto test : *fTestSuite)
68  fTestResults->CreateTH1(Form("TestStatus%s", test->GetName()), Form("Test Status %s", test->GetName()), 2, -0.5,
69  1.5);
70  for (auto hist : *fTestResults->GetListOfHistograms())
71  fOutput->Add(hist);
72 
73  PostData(1, fOutput);
74 }
75 
77  for (auto test : *fTestSuite) {
78  fTestResults->FillTH1(Form("TestStatus%s", test->GetName()),
79  EvaluateTest(static_cast<TestImplAliEmcalTrackSelection*>(test)) ? 1 : 0);
80  }
81  return kTRUE;
82 }
83 
85  if (!fTestSuite) {
86  fTestSuite = new TObjArray;
87  fTestSuite->SetOwner(true);
88  }
89  AliInfoStream() << "Adding test " << test->GetName() << std::endl;
90  fTestSuite->Add(test);
91 }
92 
97 }
98 
100  AliInfoStream() << "Evaluating test " << test->GetName() << std::endl;
101  return test->RunTest(static_cast<AliAODEvent*>(fInputEvent));
102 }
103 
105  AliAnalysisManager* mgr = AliAnalysisManager::GetAnalysisManager();
106  if (!mgr) {
107  std::cerr << "TestAliEmcalTrackSelection::AddTestEmcalTrackSelection: No "
108  "analysis manager found. Not adding test!\n";
109  return nullptr;
110  }
111 
113  mgr->AddTask(test);
114 
115  TString outputdir(mgr->GetCommonFileName());
116  outputdir += ":TestResults" + TString(name);
117 
118  mgr->ConnectInput(test, 0, mgr->GetCommonInputContainer());
119  mgr->ConnectOutput(
120  test, 1,
121  mgr->CreateContainer(Form("TestResults%s", name), TList::Class(), AliAnalysisManager::kOutputContainer, outputdir));
122 
123  return test;
124 }
125 
127 
129  : TNamed(name, ""), fTrackSelection(nullptr) {}
130 
132  if (fTrackSelection)
133  delete fTrackSelection;
134 }
135 
137  int nfailure(0);
138  for (int itrk = 0; itrk < ev->GetNumberOfTracks(); itrk++) {
139  auto track = static_cast<AliAODTrack*>(ev->GetTrack(itrk));
140  auto sel = fTrackSelection->IsTrackAccepted(track);
141  auto truth = IsTrueTrack(track);
142  if (sel != truth)
143  nfailure++;
144  }
145 
146  return nfailure == 0;
147 }
148 
150  : TestImplAliEmcalTrackSelection(), fRefCuts(nullptr) {}
151 
156  fRefCuts = AliESDtrackCuts::GetStandardITSPureSATrackCuts2010(true);
157 }
158 
160  if (fRefCuts)
161  delete fRefCuts;
162 }
163 
164 bool TestImplAliEmcalTrackSelectionITSpure::IsTrueTrack(const AliAODTrack* const trk) const {
165  if (!(trk->GetStatus() & AliVTrack::kITSpureSA))
166  return false; // addditional test - make sure track is a true stand alone
167  // track
168  if (!(trk->GetStatus() & AliVTrack::kITSrefit))
169  return false;
170 
171  if (!fRefCuts->AcceptVTrack(trk))
172  return false;
173  return true;
174 }
175 
180 }
181 
182 bool TestImplAliEmcalTrackSelectionHybrid::IsTrueTrack(const AliAODTrack* const track) const {
183  return track->IsHybridGlobalConstrainedGlobal();
184 }
185 
190 }
191 
192 bool TestImplAliEmcalTrackSelectionTPConly::IsTrueTrack(const AliAODTrack* const track) const {
193  return track->IsHybridTPCConstrainedGlobal();
194 }
195 }
196 }
virtual bool IsTrueTrack(const AliAODTrack *trk) const
virtual void GenerateTrackCuts(ETrackFilterType_t type, const char *period="")=0
Interface for track cut generators.
bool EvaluateTest(TestImplAliEmcalTrackSelection *test)
Namespace for EMCAL framework classes and task.
AliEmcalTrackSelection * fTrackSelection
Object to be tested.
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
Base task in the EMCAL framework (lighter version of AliAnalysisTaskEmcal)
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
Create a new TH1 within the container.
virtual bool IsTrueTrack(const AliAODTrack *const trk) const
Namespace for PWG framework classes.
static TestAliEmcalTrackSelection * AddTestAliEmcalTrackSelection(const char *name)
Implement virtual track selection for AOD analysis.
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
Fill a 1D histogram within the container.
virtual PWG::EMCAL::AliEmcalTrackSelResultPtr IsTrackAccepted(AliVTrack *const trk)=0
Interface for track selection code.
Container class for histograms.
Definition: THistManager.h:99
void test(int runnumber=195345)
void AddTestImpl(TestImplAliEmcalTrackSelection *test)
virtual bool IsTrueTrack(const AliAODTrack *const trk) const =0
virtual bool IsTrueTrack(const AliAODTrack *const trk) const