hooks for PMD flow analysis
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTaskCentralityTrain.C
CommitLineData
a0bbd58e 1enum anaModes {mLocal,mPROOF,mGrid};
daf66719 2//mLocal: Analyze locally files in your computer using aliroot
daf66719 3//mPROOF: Analyze CAF files with PROOF
5c09ff70 4//mGrid: Analyze files on Grid via AliEn plug-in and using precompiled FLOW libraries
a0bbd58e 5
5c09ff70 6// CENTRALITY DEFINITION
55c53ddd 7//Int_t binfirst = 4; //where do we start numbering bins
8//Int_t binlast = 6; //where do we stop numbering bins
9//const Int_t numberOfCentralityBins = 9;
55c53ddd 10Int_t binfirst = 0; //where do we start numbering bins
7d9ab4fb 11Int_t binlast = 8; //where do we stop numbering bins
12const Int_t numberOfCentralityBins = 9;
13Float_t centralityArray[numberOfCentralityBins+1] = {0.,5.,10.,20.,30.,40.,50.,60.,70.,80.}; // in centrality percentile
441ea1cf 14//Int_t centralityArray[numberOfCentralityBins+1] = {41,80,146,245,384,576,835,1203,1471,10000}; // in terms of TPC only reference multiplicity
7d9ab4fb 15
5c09ff70 16TString commonOutputFileName = "outputCentrality"; // e.g.: result for centrality bin 0 will be in the file "outputCentrality0.root", etc
daf66719 17
a0bbd58e 18//void runFlowTaskCentralityTrain(Int_t mode=mLocal, Int_t nEvents = 10,
8544d490 19//Bool_t DATA = kFALSE, const Char_t* dataDir="/Users/snelling/alice_data/Therminator_midcentral", Int_t offset = 0)
daf66719 20
a0bbd58e 21void runFlowTaskCentralityTrain( Int_t mode = mPROOF,
22 Bool_t useFlowParFiles = kFALSE,
23 Bool_t DATA = kTRUE,
2b1eaa10 24 const Char_t* dataDir = "/alice/data/LHC10h_000137162_p1_plusplusplus#esdTree",
a0bbd58e 25 Int_t nEvents = 1e4,
2b1eaa10 26 Int_t offset = 0,
27 Bool_t useTender = kFALSE )
daf66719 28{
5c09ff70 29 // Time:
daf66719 30 TStopwatch timer;
31 timer.Start();
5c09ff70 32 // Cross-check user settings before starting:
d178bd1f 33 // CrossCheckUserSettings(DATA);
a0bbd58e 34
5c09ff70 35 // Load needed libraries:
a0bbd58e 36 LoadLibraries(mode,useFlowParFiles);
37
20717aa6 38 // Create analysis manager:
39 AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
a0bbd58e 40
41 // Chains:
42 if(mode == mLocal)
43 {
44 TChain* chain = CreateESDChain(dataDir, nEvents, offset);
45 //TChain* chain = CreateAODChain(dataDir, nEvents, offset);
46 }
47
5c09ff70 48 // Connect plug-in to the analysis manager:
a0bbd58e 49 if(mode == mGrid)
50 {
20717aa6 51 gROOT->LoadMacro("CreateAlienHandler.C");
52 AliAnalysisGrid *alienHandler = CreateAlienHandler(useFlowParFiles);
53 if(!alienHandler) return;
a0bbd58e 54 mgr->SetGridHandler(alienHandler);
55 }
56
5c09ff70 57 // Event handlers:
d178bd1f 58 AliVEventHandler* esdH = new AliESDInputHandler;
59 mgr->SetInputEventHandler(esdH);
a0bbd58e 60 if (!DATA)
61 {
55c53ddd 62 AliMCEventHandler *mc = new AliMCEventHandler();
a0bbd58e 63 mgr->SetMCtruthEventHandler(mc);
55c53ddd 64 }
65
32b846cd 66 // Task to check the offline trigger:
a0bbd58e 67 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
7d9ab4fb 68 AddTaskPhysicsSelection(!DATA);
69
9bfaa57c 70 //Add the centrality determination task
71 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
72 AddTaskCentrality();
73
2b1eaa10 74 if (useTender)
75 {
76 //Add the tenders
77 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FLOW/macros/AddTaskTenderFlow.C");
78 AddTaskTenderFlow();
79 }
3abf7ecc 80
5c09ff70 81 // Setup analysis per centrality bin:
32b846cd 82 gROOT->LoadMacro("AddTaskFlowCentrality.C");
4033eebf 83 for (Int_t i=binfirst; i<binlast+1; i++)
84 {
85 Float_t lowCentralityBinEdge = centralityArray[i];
86 Float_t highCentralityBinEdge = centralityArray[i+1];
87 Printf("\nWagon for centrality bin %i: %.0f-%.0f",i,lowCentralityBinEdge,highCentralityBinEdge);
88 AddTaskFlowCentrality( lowCentralityBinEdge,
89 highCentralityBinEdge,
90 commonOutputFileName );
91 } // end of for (Int_t i=0; i<numberOfCentralityBins; i++)
d178bd1f 92
5c09ff70 93 // Enable debug printouts:
daf66719 94 mgr->SetDebugLevel(2);
5c09ff70 95 // Run the analysis:
a0bbd58e 96 if(!mgr->InitAnalysis()) return;
daf66719 97 mgr->PrintStatus();
a0bbd58e 98 if(mode == mLocal)
99 {
d178bd1f 100 mgr->StartAnalysis("local",chain);
a0bbd58e 101 }
102 else if(mode == mPROOF)
103 {
104 mgr->StartAnalysis("proof",dataDir,nEvents,offset);
105 }
106 else if(mode == mGrid)
107 {
d178bd1f 108 mgr->StartAnalysis("grid");
109 }
110
5c09ff70 111 // Print real and CPU time used for analysis:
daf66719 112 timer.Stop();
a0bbd58e 113 timer.Print();
114
5c09ff70 115} // end of void runFlowTaskCentralityTrain(...)
116
117//===============================================================================================
d178bd1f 118/*
a0bbd58e 119void CrossCheckUserSettings(Bool_t bData)
daf66719 120{
a0bbd58e 121 // Check in this method if the user settings make sense.
5c09ff70 122 if(LYZ1SUM && LYZ2SUM) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
123 if(LYZ1PROD && LYZ2PROD) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
124 if(LYZ2SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
125 if(LYZ1SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
daf66719 126} // end of void CrossCheckUserSettings()
d178bd1f 127*/
5c09ff70 128//===============================================================================================
129
a0bbd58e 130void LoadLibraries(const anaModes mode, Bool_t useFlowParFiles )
5c09ff70 131{
daf66719 132 //--------------------------------------
133 // Load the needed libraries most of them already loaded by aliroot
134 //--------------------------------------
f33c7420 135
a0bbd58e 136 gSystem->Load("libCore");
32b846cd 137 gSystem->Load("libTree");
daf66719 138 gSystem->Load("libGeom");
139 gSystem->Load("libVMC");
140 gSystem->Load("libXMLIO");
141 gSystem->Load("libPhysics");
32b846cd 142 gSystem->Load("libXMLParser");
143 gSystem->Load("libProof");
3abf7ecc 144 gSystem->Load("libMinuit");
a0bbd58e 145
146 if (mode==mLocal || mode==mGrid)
32b846cd 147 {
daf66719 148 gSystem->Load("libSTEERBase");
32b846cd 149 gSystem->Load("libCDB");
150 gSystem->Load("libRAWDatabase");
151 gSystem->Load("libRAWDatarec");
daf66719 152 gSystem->Load("libESD");
153 gSystem->Load("libAOD");
32b846cd 154 gSystem->Load("libSTEER");
daf66719 155 gSystem->Load("libANALYSIS");
a0bbd58e 156 gSystem->Load("libANALYSISalice");
2b1eaa10 157 gSystem->Load("libTPCbase");
a0bbd58e 158 gSystem->Load("libTOFbase");
159 gSystem->Load("libTOFrec");
bdd1ed02 160 gSystem->Load("libTRDbase");
161 gSystem->Load("libVZERObase");
162 gSystem->Load("libVZEROrec");
163 gSystem->Load("libT0base");
a0bbd58e 164 gSystem->Load("libT0rec");
3abf7ecc 165 gSystem->Load("libTENDER");
bdd1ed02 166 gSystem->Load("libTENDERSupplies");
32b846cd 167
a0bbd58e 168 if (useFlowParFiles)
5c09ff70 169 {
32b846cd 170 AliAnalysisAlien::SetupPar("PWG2flowCommon");
171 AliAnalysisAlien::SetupPar("PWG2flowTasks");
daf66719 172 }
a0bbd58e 173 else
174 {
175 gSystem->Load("libPWG2flowCommon");
176 gSystem->Load("libPWG2flowTasks");
177 }
daf66719 178 }
a0bbd58e 179 else if (mode==mPROOF)
180 {
181 TList* list = new TList();
182 list->Add(new TNamed("ALIROOT_MODE", "ALIROOT"));
183 if (useFlowParFiles)
184 list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "ANALYSIS:ANALYSISalice:TENDER:TENDERSupplies"));
185 else
186 list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "ANALYSIS:ANALYSISalice:TENDER:TENDERSupplies:PWG2flowCommon:PWG2flowTasks"));
187
188 //list->Add(new TNamed("ALIROOT_EXTRA_INCLUDES","PWG2/FLOW/AliFlowCommon:PWG2/FLOW/AliFlowTasks"));
189
daf66719 190 // Connect to proof
191 printf("*** Connect to PROOF ***\n");
192 gEnv->SetValue("XSec.GSI.DelegProxy","2");
a0bbd58e 193 //TProof* proof = TProof::Open("alice-caf.cern.ch");
194 TProof* proof = TProof::Open("skaf.saske.sk");
195
196 // list the data available
197 //gProof->ShowDataSets("/*/*");
daf66719 198 //gProof->ShowDataSets("/alice/sim/"); //for MC Data
a0bbd58e 199 //gProof->ShowDataSets("/alice/data/"); //for REAL Data
200
201 proof->ClearPackages();
202 proof->EnablePackage("VO_ALICE@AliRoot::v4-21-14-AN",list);
203
204 if (useFlowParFiles)
205 {
206 gProof->UploadPackage("PWG2flowCommon.par");
207 gProof->UploadPackage("PWG2flowTasks.par");
208 }
daf66719 209
210 // Show enables Packages
211 gProof->ShowEnabledPackages();
a0bbd58e 212 }
213} // end of void LoadLibraries(const anaModes mode)
5c09ff70 214
daf66719 215// Helper macros for creating chains
216// from: CreateESDChain.C,v 1.10 jgrosseo Exp
daf66719 217TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
218{
219 // creates chain of files in a given directory or file containing a list.
220 // In case of directory the structure is expected as:
221 // <aDataDir>/<dir0>/AliESDs.root
222 // <aDataDir>/<dir1>/AliESDs.root
223 // ...
a0bbd58e 224
daf66719 225 if (!aDataDir)
226 return 0;
a0bbd58e 227
daf66719 228 Long_t id, size, flags, modtime;
229 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
a0bbd58e 230 {
231 printf("%s not found.\n", aDataDir);
232 return 0;
233 }
234
daf66719 235 TChain* chain = new TChain("esdTree");
236 TChain* chaingAlice = 0;
a0bbd58e 237
daf66719 238 if (flags & 2)
a0bbd58e 239 {
240 TString execDir(gSystem->pwd());
241 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
242 TList* dirList = baseDir->GetListOfFiles();
243 Int_t nDirs = dirList->GetEntries();
244 gSystem->cd(execDir);
245
246 Int_t count = 0;
247
248 for (Int_t iDir=0; iDir<nDirs; ++iDir)
daf66719 249 {
a0bbd58e 250 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
251 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
252 continue;
253
254 if (offset > 0)
255 {
256 --offset;
257 continue;
258 }
259
260 if (count++ == aRuns)
261 break;
262
263 TString presentDirName(aDataDir);
264 presentDirName += "/";
265 presentDirName += presentDir->GetName();
266 chain->Add(presentDirName + "/AliESDs.root/esdTree");
267 // cerr<<presentDirName<<endl;
daf66719 268 }
a0bbd58e 269
270 }
daf66719 271 else
a0bbd58e 272 {
273 // Open the input stream
274 ifstream in;
275 in.open(aDataDir);
276
277 Int_t count = 0;
278
279 // Read the input list of files and add them to the chain
280 TString esdfile;
281 while(in.good())
daf66719 282 {
a0bbd58e 283 in >> esdfile;
284 if (!esdfile.Contains("root")) continue; // protection
285
286 if (offset > 0)
287 {
288 --offset;
289 continue;
daf66719 290 }
a0bbd58e 291
292 if (count++ == aRuns)
293 break;
294
295 // add esd file
296 chain->Add(esdfile);
daf66719 297 }
a0bbd58e 298
299 in.close();
300 }
301
daf66719 302 return chain;
daf66719 303
5c09ff70 304} // end of TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
daf66719 305
5c09ff70 306//===============================================================================================
daf66719 307
308TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
309{
310 // creates chain of files in a given directory or file containing a list.
311 // In case of directory the structure is expected as:
312 // <aDataDir>/<dir0>/AliAOD.root
313 // <aDataDir>/<dir1>/AliAOD.root
314 // ...
a0bbd58e 315
daf66719 316 if (!aDataDir)
317 return 0;
a0bbd58e 318
daf66719 319 Long_t id, size, flags, modtime;
320 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
a0bbd58e 321 {
322 printf("%s not found.\n", aDataDir);
323 return 0;
324 }
325
daf66719 326 TChain* chain = new TChain("aodTree");
327 TChain* chaingAlice = 0;
a0bbd58e 328
daf66719 329 if (flags & 2)
a0bbd58e 330 {
331 TString execDir(gSystem->pwd());
332 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
333 TList* dirList = baseDir->GetListOfFiles();
334 Int_t nDirs = dirList->GetEntries();
335 gSystem->cd(execDir);
336
337 Int_t count = 0;
338
339 for (Int_t iDir=0; iDir<nDirs; ++iDir)
daf66719 340 {
a0bbd58e 341 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
342 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
343 continue;
344
345 if (offset > 0)
346 {
347 --offset;
348 continue;
349 }
350
351 if (count++ == aRuns)
352 break;
353
354 TString presentDirName(aDataDir);
355 presentDirName += "/";
356 presentDirName += presentDir->GetName();
357 chain->Add(presentDirName + "/AliAOD.root/aodTree");
358 // cerr<<presentDirName<<endl;
daf66719 359 }
a0bbd58e 360
361 }
daf66719 362 else
a0bbd58e 363 {
364 // Open the input stream
365 ifstream in;
366 in.open(aDataDir);
367
368 Int_t count = 0;
369
370 // Read the input list of files and add them to the chain
371 TString aodfile;
372 while(in.good())
daf66719 373 {
a0bbd58e 374 in >> aodfile;
375 if (!aodfile.Contains("root")) continue; // protection
376
377 if (offset > 0)
378 {
379 --offset;
380 continue;
daf66719 381 }
a0bbd58e 382
383 if (count++ == aRuns)
384 break;
385
386 // add aod file
387 chain->Add(aodfile);
daf66719 388 }
a0bbd58e 389
390 in.close();
391 }
392
daf66719 393 return chain;
5c09ff70 394
395} // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
daf66719 396