Split: fix refs to AddTaskPhysicsSelection.C
[u/mrichter/AliRoot.git] / PWG / muon / runNorm.C
CommitLineData
6eebc585 1
2//--------------------------------------------------------------------------
3// Example macro for running locally AliAnalysisTaskNorm task
4//
5//
6//--------------------------------------------------------------------------
7
8enum {kLocal, kInteractif_xml, kInteractif_ESDList};
9Int_t GetMode(TString inputFileName);
10TChain* CreateChainFromCollection(const char *xmlfile);
11TChain* CreateChainFromAODFile(const char *rootfile,Bool_t isESD);
12TChain* CreateChainFromESDList(const char *esdList);
13TChain* CreateChain(TString inputFileName,Bool_t isESD);
14
15void runNorm(TString inputFileName = "AliAOD.root", Int_t nEvents = 1e6, TString beamConf = "p-Pb", Bool_t isESD = kFALSE, Bool_t isMC = kFALSE, Int_t debugLevel = 0)
16{
17
18 TStopwatch timer;
19 timer.Start();
20
21 // Check runing mode
22 Int_t mode = GetMode(inputFileName);
23 if(mode < 0){
24 Error("runAnalysis","Please provide either an ESD/AOD root file or a collection of ESDs/AODs.");
25 return;
26 }
27
28 // Load common libraries
29 gSystem->Load("libTree");
30 gSystem->Load("libGeom");
31 gSystem->Load("libVMC");
32 gSystem->Load("libPhysics");
33 gSystem->Load("libSTEERBase");
34 // gSystem->Load("libSTEER");
35 gSystem->Load("libESD");
36 gSystem->Load("libAOD");
37 gSystem->Load("libANALYSIS");
38 gSystem->Load("libANALYSISalice");
39 gSystem->Load("libEventMixing");
40 gSystem->Load("libCORRFW");
41 gSystem->Load("libPWGmuon");
42 gSystem->Load("libPWGmuondep");
43
44 gSystem->AddIncludePath(Form("-I\"%s/include\"", gSystem->ExpandPathName("$ALICE_ROOT")));
45 gROOT->ProcessLine(Form(".include %s/include", gSystem->ExpandPathName("$ALICE_ROOT")));
46
47 // Create input chain
48 TChain* chain = CreateChain(inputFileName,isESD);
49 if (!chain) return;
50
51 // Create the analysis manager
52 AliAnalysisManager *mgr = new AliAnalysisManager("MuonTask");
53
54 if ( isESD) {
55 // ESD input handler
56 AliESDInputHandler* esdH = new AliESDInputHandler();
57 esdH->SetReadFriends(kFALSE);
58 mgr->SetInputEventHandler(esdH);
59 }
60 else {
61 // AOD input handler
62 AliAODInputHandler* aodH = new AliAODInputHandler();
63 mgr->SetInputEventHandler(aodH);
64 }
65
66 TString dataType = mgr->GetInputEventHandler()->GetDataType();
67 Info("runLocal",Form("Manager with %s",dataType.Data()));
68
69 // Enable MC event handler for ESDs
70 if ( isMC && isESD ){
71 AliVEventHandler* handler = new AliMCEventHandler;
72 mgr->SetMCtruthEventHandler(handler);
73 }
74
75 // event selection and centrality framework
76 if ( isESD ){
63b6cbd0 77 gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskPhysicsSelection.C");
6eebc585 78 AliPhysicsSelectionTask* physicsSelection = AddTaskPhysicsSelection(isMC);
79 if ( !physicsSelection ) {
80 Error("runLocal","AliPhysicsSelectionTask not created!");
81 return;
82 }
83 }
84 if ( isESD ){
85 // event centrality
1c06a186 86 gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskCentrality.C");
6eebc585 87 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
88 if ( !taskCentrality ) {
89 Error("runLocal on ESD","AliCentralitySelectionTask not created!");
90 return;
91 }
92 if ( isMC ) taskCentrality->SetMCInput();
93 //taskCentrality->SetPass(1); // remember to set the pass you are processing!!!
94 }
95 /*else {
96 //Only on full AOD it is possible to reprocess the centrality framework
1c06a186 97 gROOT->LoadMacro("$ALICE_ROOT/OADB/macros/AddTaskCentrality.C");
6eebc585 98 AliCentralitySelectionTask *taskCentrality = AddTaskCentrality(kTRUE,kTRUE);
99 if ( !taskCentrality ) {
100 Error("runLocal on AOD","AliCentralitySelectionTask not created!");
101 return;
102 }
103 if ( isMC ) taskCentrality->SetMCInput();
104 }*/
105
106 // Example analysis
107 // Create task
108 gROOT->LoadMacro("$ALICE_ROOT/PWG/muon/AddTaskNorm.C");
109 AliAnalysisTaskNorm* task = AddTaskNorm(isESD,isMC,beamConf);
110 if (!task) {
111 Error("runAnalysis","AliAnalysisTaskNorm not created!");
112 return;
113 }
114 task->SetDebugLevel(debugLevel);
115
116 // Enable debug printouts
117 mgr->SetDebugLevel(debugLevel);
118
119 // start local analysis
120 if (mgr->InitAnalysis()) {
121 mgr->PrintStatus();
122 if(debugLevel>=2) mgr->SetNSysInfo(100);
123 mgr->StartAnalysis("local", chain, nEvents);
124 }
125
126 if(debugLevel>=2){
127 mgr->ProfileTask("Task");
128 }
129
130 timer.Stop();
131 timer.Print();
132}
133
134//______________________________________________________________________________
135Int_t GetMode(TString inputFileName)
136{
137 if ( inputFileName.EndsWith(".xml") ) return kInteractif_xml;
138 else if ( inputFileName.EndsWith(".txt") ) return kInteractif_ESDList;
139 else if ( inputFileName.EndsWith(".root") ) return kLocal;
140 return -1;
141}
142
143//______________________________________________________________________________
144TChain* CreateChainFromCollection(const char *xmlfile)
145{
146 // Create a chain from the collection of tags.
147 TAlienCollection* coll = TAlienCollection::Open(xmlfile);
148 if (!coll) {
149 ::Error("CreateChainFromTags", "Cannot create an AliEn collection from %s", xmlfile);
150 return NULL;
151 }
152
153 TGridResult* tagResult = coll->GetGridResult("",kFALSE,kFALSE);
154 AliTagAnalysis *tagAna = new AliTagAnalysis("ESD");
155 tagAna->ChainGridTags(tagResult);
156
157 AliRunTagCuts *runCuts = new AliRunTagCuts();
158 AliLHCTagCuts *lhcCuts = new AliLHCTagCuts();
159 AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
160 AliEventTagCuts *evCuts = new AliEventTagCuts();
161
162 // Check if the cuts configuration file was provided
163 if (!gSystem->AccessPathName("ConfigureCuts.C")) {
164 gROOT->LoadMacro("ConfigureCuts.C");
165 ConfigureCuts(runCuts, lhcCuts, detCuts, evCuts);
166 }
167
168 TChain *chain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evCuts);
169 if (!chain || !chain->GetNtrees()) return NULL;
170 chain->ls();
171 return chain;
172}
173
174//______________________________________________________________________________
175TChain* CreateChainFromAODFile(const char *rootfile, Bool_t isESD)
176{
177 // Create a chain using the root file.
178 TChain* chain = 0;
179 if ( !isESD) chain = new TChain("aodTree");
180 else chain = new TChain("esdTree");
181 chain->Add(rootfile);
182 if (!chain->GetNtrees()) return NULL;
183 chain->ls();
184 return chain;
185}
186
187//______________________________________________________________________________
188TChain* CreateChainFromESDList(const char *esdList)
189{
190 // Create a chain using tags from the run list.
191 TChain* chain = new TChain("esdTree");
192 ifstream inFile(esdList);
193 TString inFileName;
194 if (inFile.is_open()) {
195 while (! inFile.eof() ) {
196 inFileName.ReadLine(inFile,kFALSE);
197 if(!inFileName.EndsWith(".root")) continue;
198 chain->Add(inFileName.Data());
199 }
200 }
201 inFile.close();
202 if (!chain->GetNtrees()) return NULL;
203 chain->ls();
204 return chain;
205}
206
207//______________________________________________________________________________
208TChain* CreateChain(TString inputFileName, Bool_t isESD)
209{
210 printf("*******************************\n");
211 printf("*** Getting the Chain ***\n");
212 printf("*******************************\n");
213 Int_t mode = GetMode(inputFileName);
214 if(mode == kInteractif_xml) return CreateChainFromCollection(inputFileName.Data());
215 else if (mode == kInteractif_ESDList) return CreateChainFromESDList(inputFileName.Data());
216 else if (mode == kLocal) return CreateChainFromAODFile(inputFileName.Data(),isESD);
217 else return NULL;
218}
219