AliPhysics  5b5fbb3 (5b5fbb3)
TestAliEmcalAODFilterBitCuts.cxx
Go to the documentation of this file.
1 /************************************************************************************
2  * Copyright (C) 2017, Copyright Holders of the ALICE Collaboration *
3  * All rights reserved. *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions are met: *
7  * * Redistributions of source code must retain the above copyright *
8  * notice, this list of conditions and the following disclaimer. *
9  * * Redistributions in binary form must reproduce the above copyright *
10  * notice, this list of conditions and the following disclaimer in the *
11  * documentation and/or other materials provided with the distribution. *
12  * * Neither the name of the <organization> nor the *
13  * names of its contributors may be used to endorse or promote products *
14  * derived from this software without specific prior written permission. *
15  * *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
19  * DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26  ************************************************************************************/
27 #include "AliAnalysisManager.h"
28 #include "AliAODEvent.h"
29 #include "AliAODTrack.h"
31 #include "AliLog.h"
32 #include <THistManager.h>
33 #include <TList.h>
34 #include <TObjArray.h>
35 #include <TString.h>
36 #include <iostream>
37 
39 
42 ClassImp(PWG::EMCAL::TestImplAliEmcalAODFilterBitCuts)
43 ClassImp(PWG::EMCAL::TestImplAliEmcalAODFilterBitCutsTPCconstrained)
44 ClassImp(PWG::EMCAL::TestImplAliEmcalAODFilterBitCutsHybrid)
46 
47 namespace PWG {
48 namespace EMCAL {
49 
50 TestAliEmcalAODFilterBitCuts::TestAliEmcalAODFilterBitCuts() :
52  fTestSuite(nullptr),
53  fTestStatus(nullptr)
54 {
55 
56 }
57 
59  AliAnalysisTaskEmcalLight(name, kTRUE),
62 {
64 }
65 
67  if(fTestSuite) delete fTestSuite;
68 }
69 
71  if(!fTestSuite) fTestSuite = new TObjArray;
72  fTestSuite->SetOwner(kTRUE);
73  AliInfoStream() << "Adding test: " << test->GetName() << std::endl;
74  fTestSuite->Add(test);
75 }
76 
79 
80  fTestStatus = new THistManager("testStatus");
81  for(auto t : *fTestSuite) fTestStatus->CreateTH1(Form("TestResult%s", t->GetName()), Form("Result Test %s", t->GetName()), 2, -0.5, 1.5);
82  for(auto h : *fTestStatus->GetListOfHistograms()) fOutput->Add(h);
83 
84  PostData(1, fOutput);
85 }
86 
88  AliAODEvent *ev = dynamic_cast<AliAODEvent *>(fInputEvent);
89  if(!ev) return false;
90  for(auto test : *fTestSuite) EvaluateTest(static_cast<TestImplAliEmcalAODFilterBitCuts *>(test), ev);
91  return true;
92 }
93 
95  AliInfoStream() << "Running test: " << test->GetName() << std::endl;
96  fTestStatus->FillTH1(Form("TestResult%s", test->GetName()), test->RunTest(ev) ? 1 : 0);
97 }
98 
102 }
103 
105  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
106  if(!mgr){
107  std::cerr << "TestAliEmcalAODFilterBitCuts: No Analysis manager\n";
108  return nullptr;
109  }
110 
112  mgr->AddTask(test);
113 
114  TString outname(mgr->GetCommonFileName());
115  outname += TString::Format(":%s", testname);
116 
117  mgr->ConnectInput(test, 0, mgr->GetCommonInputContainer());
118  mgr->ConnectOutput(test, 1, mgr->CreateContainer(Form("Histos%s", testname), TList::Class(), AliAnalysisManager::kOutputContainer, outname));
119  return test;
120 }
121 
123  TNamed(),
124  fTestObject(nullptr)
125 {
126 }
127 
129  TNamed(name, ""),
131 {
132 }
133 
135  if(fTestObject) delete fTestObject;
136 }
137 
139  int nerror(0);
140  for(int itrk = 0; itrk < ev->GetNumberOfTracks(); itrk++){
141  AliAODTrack *trk = static_cast<AliAODTrack *>(ev->GetTrack(itrk));
142  bool truth = this->IsTrueTrack(trk), test = fTestObject->IsSelected(trk);
143  if(truth != test) nerror++;
144  }
145  return nerror != 0;
146 }
147 
150 {
151  fTestObject = new AliEmcalAODFilterBitCuts(Form("CutsTest%s", name), "Test cuts");
152  fTestObject->SetStatusBits(static_cast<ULong_t>(AliAODTrack::kIsTPCConstrained));
153 }
154 
156  return track->IsTPCConstrained();
157 }
158 
161 {
162  fTestObject = new AliEmcalAODFilterBitCuts(Form("CutsTest%s", name), "Test cuts");
163  fTestObject->SetStatusBits(static_cast<ULong_t>(AliAODTrack::kIsHybridGCG | AliAODTrack::kIsHybridTPCCG));
165 }
166 
167 bool TestImplAliEmcalAODFilterBitCutsHybrid::IsTrueTrack(const AliAODTrack *track) const {
168  return track->IsHybridGlobalConstrainedGlobal() || track->IsHybridTPCConstrainedGlobal();
169 }
170 
171 } /* namespace EMCAL */
172 } /* namespace PWG */
static TestAliEmcalAODFilterBitCuts * AddTestAliEmcalAODFilterBitCuts(const char *testname)
THistManager * fTestStatus
Histograms with test results.
virtual bool IsTrueTrack(const AliAODTrack *const trk) const
void SetSelectionMode(SelectionMode_t mode)
Set the selection mode.
TObjArray * fTestSuite
Test suite to be executed.
Namespace for EMCAL framework classes and task.
virtual bool IsTrueTrack(const AliAODTrack *const trk) const =0
void EvaluateTest(TestImplAliEmcalAODFilterBitCuts *test, const AliAODEvent *const ev)
void AddTestImpl(TestImplAliEmcalAODFilterBitCuts *test)
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.
Namespace for PWG framework classes.
AliEmcalAODFilterBitCuts * fTestObject
Object to be tested.
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
Fill a 1D histogram within the container.
Unit test for AOD hybrid track cuts.
Implementation of the AOD filter bit selection as virtual cut class.
Container class for histograms.
Definition: THistManager.h:99
void SetStatusBits(ULong_t statusbits, Bool_t doReset=false)
Set the track status bits to be checked.
void test(int runnumber=195345)
virtual bool IsTrueTrack(const AliAODTrack *const trk) const