Updated version (Marek)
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTask.C
CommitLineData
73160af6 1enum anaModes {mLocal,mLocalPAR,mPROOF,mGRID};
2//mLocal: Analyze locally files in your computer using aliroot
3//mLocalPAR: Analyze locally files in your computer using root + PAR files
4//mPROOF: Analyze CAF files with PROOF
5
73160af6 6// RUN SETTINGS
93329510 7
73160af6 8// Flow analysis method can be:(set to kTRUE or kFALSE)
21f8d9b1 9Bool_t MCEP = kFALSE; // correlation with Monte Carlo reaction plane
2b6139a1 10Bool_t SP = kTRUE; // scalar product method (similar to eventplane method)
61e0c8c0 11Bool_t GFC = kTRUE; // cumulants based on generating function
12Bool_t QC = kTRUE; // cumulants using Q vectors
13Bool_t FQD = kTRUE; // fit of the distribution of the Q vector (only integrated v)
14Bool_t LYZ1SUM = kTRUE; // Lee Yang Zeroes using sum generating function (integrated v)
15Bool_t LYZ1PROD = kTRUE; // Lee Yang Zeroes using product generating function (integrated v)
2b6139a1 16Bool_t LYZ2SUM = kFALSE; // Lee Yang Zeroes using sum generating function (second pass differential v)
17Bool_t LYZ2PROD = kFALSE; // Lee Yang Zeroes using product generating function (second pass differential v)
18Bool_t LYZEP = kFALSE; // Lee Yang Zeroes Event plane using sum generating function (gives eventplane + weight)
61e0c8c0 19Bool_t MH = kTRUE; // azimuthal correlators in mixed harmonics
21f8d9b1 20Bool_t NL = kFALSE; // nested loops (for instance distribution of phi1-phi2 for all distinct pairs)
c741f5d0 21
67a6b178 22Bool_t METHODS[] = {SP,LYZ1SUM,LYZ1PROD,LYZ2SUM,LYZ2PROD,LYZEP,GFC,QC,FQD,MCEP,MH,NL};
93329510 23
940a5ed1 24// Analysis type can be ESD, AOD, MC, ESDMCkineESD, ESDMCkineMC
93329510 25const TString type = "ESD";
73160af6 26
27// Boolean to fill/not fill the QA histograms
93329510 28Bool_t QA = kTRUE;
73160af6 29
93329510 30// Boolean to use/not use weights for the Q vector
31Bool_t WEIGHTS[] = {kFALSE,kFALSE,kFALSE}; //Phi, v'(pt), v'(eta)
73160af6 32
33
238dd515 34//void runFlowTask(Int_t mode=mLocal, Int_t nRuns = 1,
35//Bool_t DATA = kTRUE, const Char_t* dataDir="/data/alice2/kolk/PP/data/LHC09d/104892/test", Int_t offset = 0)
36 //Bool_t DATA = kFALSE, const Char_t* dataDir="/data/alice2/kolk/PP/LHC09d10/104873", Int_t offset = 0)
21f8d9b1 37
238dd515 38void runFlowTask(Int_t mode = mPROOF, Int_t nRuns = 50000000,
21f8d9b1 39 //Bool_t DATA = kFALSE, const Char_t* dataDir="/PWG2/akisiel/Therminator_midcentral_ESD", Int_t offset=0)
40 //Bool_t DATA = kFALSE, const Char_t* dataDir="/COMMON/COMMON/LHC09a4_run8101X", Int_t offset = 0)
41 //Bool_t DATA = kFALSE, const Char_t* dataDir="/PWG2/akisiel/LHC10d6_0.9TeV_EPOS_12502X", Int_t offset=0)
42 //Bool_t DATA = kTRUE, const Char_t* dataDir="/PWG0/jgrosseo/run000104892_pass4", Int_t offset=0)
43 //Bool_t DATA = kTRUE, const Char_t* dataDir="/PWG0/jgrosseo/run000104867_90_92_pass4", Int_t offset=0)
44 //Bool_t DATA = kFALSE, const Char_t* dataDir="/ALICE/pp010000/MC_LHC09a4_81xxx", Int_t offset=0)
45 //Bool_t DATA = kFALSE, const Char_t* dataDir="/COMMON/COMMON/LHC10a8_run104867_8", Int_t offset=0)
238dd515 46 Bool_t DATA = kTRUE, const Char_t* dataDir="/alice/data/LHC10b_000115322_p1", Int_t offset=0)
61e0c8c0 47//void runFlowTask(Int_t mode = mGRID, Bool_t DATA = kTRUE)
73160af6 48{
73160af6 49 TStopwatch timer;
50 timer.Start();
93329510 51
61e0c8c0 52 CrossCheckUserSettings(DATA);
53
73160af6 54 LoadLibraries(mode);
9cc5e012 55
56 if (mode == mGRID) {
57 // Create and configure the alien handler plugin
58 gROOT->LoadMacro("CreateAlienHandler.C");
59 AliAnalysisGrid *alienHandler = CreateAlienHandler();
60 if (!alienHandler) return;
61 }
93329510 62
9cc5e012 63 if (mode==mLocal || mode == mLocalPAR) {
93329510 64 if (type!="AOD") { TChain* chain = CreateESDChain(dataDir, nRuns, offset);}
73160af6 65 else { TChain* chain = CreateAODChain(dataDir, nRuns, offset);}
66 }
73160af6 67 //____________________________________________//
68 // Make the analysis manager
69 AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
9cc5e012 70
71 if (mode == mGRID) {
72 // Connect plug-in to the analysis manager
73 mgr->SetGridHandler(alienHandler);
74 }
75
73160af6 76 if (type == "ESD"){
77 AliVEventHandler* esdH = new AliESDInputHandler;
78 mgr->SetInputEventHandler(esdH);
06f9b526 79 if (MCEP) {
80 AliMCEventHandler *mc = new AliMCEventHandler();
81 mgr->SetMCtruthEventHandler(mc);
82 }
93329510 83 }
73160af6 84
85 if (type == "AOD"){
86 AliVEventHandler* aodH = new AliAODInputHandler;
87 mgr->SetInputEventHandler(aodH);
06f9b526 88 if (MCEP) {
89 AliMCEventHandler *mc = new AliMCEventHandler();
90 mgr->SetMCtruthEventHandler(mc);
91 }
93329510 92 }
73160af6 93
940a5ed1 94 if (type == "MC" || type == "ESDMCkineESD" || type == "ESDMCkineMC"){
73160af6 95 AliVEventHandler* esdH = new AliESDInputHandler;
96 mgr->SetInputEventHandler(esdH);
97
98 AliMCEventHandler *mc = new AliMCEventHandler();
4a1a86a5 99 mgr->SetMCtruthEventHandler(mc);
100 }
61e0c8c0 101
73160af6 102 //____________________________________________//
b0569f96 103 // Load the analysis task
93329510 104 gROOT->LoadMacro("AddTaskFlow.C");
105 AliAnalysisTaskFlowEvent* taskFE = AddTaskFlow(type,METHODS,QA,WEIGHTS);
b0569f96 106
bec5e178 107
61e0c8c0 108 // Task to check the offline trigger
21f8d9b1 109 if (mode == mLocal || mode == mGRID) {
110 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); }
111 else if (mode == mPROOF || mode == mLocalPAR) {
112 gROOT->LoadMacro("AddTaskPhysicsSelection.C"); }
b0569f96 113 AliPhysicsSelectionTask* physicsSelTask = AddTaskPhysicsSelection();
114 if (!DATA) {physicsSelTask->GetPhysicsSelection()->SetAnalyzeMC();}
bec5e178 115
9cc5e012 116
117 // Enable debug printouts
118 mgr->SetDebugLevel(2);
119
120
93329510 121 //____________________________________________//
73160af6 122 // Run the analysis
73160af6 123 if (!mgr->InitAnalysis()) return;
124 mgr->PrintStatus();
125
21f8d9b1 126 if (mode == mLocal || mode == mLocalPAR) {
73160af6 127 mgr->StartAnalysis("local",chain);
128 }
21f8d9b1 129 else if (mode == mPROOF) {
73160af6 130 mgr->StartAnalysis("proof",dataDir,nRuns,offset);
131 }
21f8d9b1 132 else if (mode == mGRID) {
9cc5e012 133 mgr->StartAnalysis("grid");
73160af6 134 }
135
136 timer.Stop();
137 timer.Print();
93329510 138
73160af6 139}
140
61e0c8c0 141void CrossCheckUserSettings(Bool_t bData)
142{
143 // Check in this method if the user settings make sense.
144
145 if(MCEP==kTRUE && bData==kTRUE)
146 {
147 cout<<endl;
148 cout<<"WARNING: In real datasets there is no Monte Carlo information available !!!!"<<endl;
149 cout<<" Set for real data analysis DATA = kTRUE and MCEP = kFALSE in the macro."<<endl;
150 cout<<endl;
151 exit(0);
152 }
153
154} // end of void CrossCheckUserSettings()
73160af6 155
93329510 156void LoadLibraries(const anaModes mode) {
157
158 //--------------------------------------
159 // Load the needed libraries most of them already loaded by aliroot
160 //--------------------------------------
5d040cf3 161 gSystem->Load("libTree");
162 gSystem->Load("libGeom");
163 gSystem->Load("libVMC");
164 gSystem->Load("libXMLIO");
165 gSystem->Load("libPhysics");
93329510 166
167 //----------------------------------------------------------
168 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
169 //----------------------------------------------------------
9cc5e012 170 if (mode==mLocal || mode==mGRID) {
93329510 171 //--------------------------------------------------------
172 // If you want to use already compiled libraries
173 // in the aliroot distribution
174 //--------------------------------------------------------
175 gSystem->Load("libSTEERBase");
176 gSystem->Load("libESD");
177 gSystem->Load("libAOD");
178 gSystem->Load("libANALYSIS");
179 gSystem->Load("libANALYSISalice");
5d040cf3 180 gSystem->Load("libCORRFW");
181 cerr<<"libCORRFW loaded..."<<endl;
182 gSystem->Load("libPWG2flowCommon");
183 cerr<<"libPWG2flowCommon loaded..."<<endl;
184 gSystem->Load("libPWG2flowTasks");
185 cerr<<"libPWG2flowTasks loaded..."<<endl;
93329510 186 }
187
9cc5e012 188 else if (mode == mLocalPAR) {
93329510 189 //--------------------------------------------------------
190 //If you want to use root and par files from aliroot
191 //--------------------------------------------------------
192 SetupPar("STEERBase");
193 SetupPar("ESD");
194 SetupPar("AOD");
195 SetupPar("ANALYSIS");
196 SetupPar("ANALYSISalice");
197 SetupPar("PWG2AOD");
198 SetupPar("CORRFW");
199 SetupPar("PWG2flowCommon");
200 cerr<<"PWG2flowCommon.par loaded..."<<endl;
201 SetupPar("PWG2flowTasks");
202 cerr<<"PWG2flowTasks.par loaded..."<<endl;
203 }
204
205 //---------------------------------------------------------
206 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
207 //---------------------------------------------------------
208 else if (mode==mPROOF) {
209 //
f6cf97c1 210 //gEnv->SetValue("XSec.GSI.DelegProxy","2");
93329510 211 // set to debug root versus if needed
2aa4ebcd 212 //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a_dbg");
edd5904a 213 //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a");
7f7086f7 214 //TProof::Reset("proof://snelling@alicecaf.cern.ch");
93329510 215 // Connect to proof
93329510 216 printf("*** Connect to PROOF ***\n");
238dd515 217 gEnv->SetValue("XSec.GSI.DelegProxy","2");
7f7086f7 218 // Put appropriate username here
219 //TProof::Open("abilandz@alicecaf.cern.ch");
220 //TProof::Open("nkolk@alicecaf.cern.ch");
238dd515 221 //TProof::Open("snelling@localhost");
222 TProof::Open("alice-caf.cern.ch");
bec5e178 223 //TProof::Open("skaf.saske.sk");
224 //TProof::Open("prf000-iep-grid.saske.sk");
225 //Info("runSKAF.C","Loading libs on proof (may take while, around 1 min) ...");
7f7086f7 226 // list the data available
238dd515 227 //gProof->ShowDataSets("/*/*");
228 //gProof->ShowDataSets("/alice/sim/"); //for MC Data
229 //gProof->ShowDataSets("/alice/data/"); //for REAL Data
7f7086f7 230
231 // Clear the Packages
bec5e178 232
edd5904a 233 gProof->ClearPackage("STEERBase.par");
edd5904a 234 gProof->ClearPackage("ESD.par");
edd5904a 235 gProof->ClearPackage("AOD.par");
bec5e178 236 gProof->ClearPackage("PWG2AOD.par");
edd5904a 237 gProof->ClearPackage("ANALYSIS.par");
edd5904a 238 gProof->ClearPackage("ANALYSISalice.par");
edd5904a 239 gProof->ClearPackage("CORRFW.par");
bec5e178 240
2aa4ebcd 241 gProof->ClearPackage("PWG2flowCommon");
2aa4ebcd 242 gProof->ClearPackage("PWG2flowTasks");
bec5e178 243
7f7086f7 244 // Upload the Packages
245 gProof->UploadPackage("STEERBase.par");
246 gProof->UploadPackage("ESD.par");
247 gProof->UploadPackage("AOD.par");
bec5e178 248 gProof->UploadPackage("PWG2AOD.par");
249
7f7086f7 250 gProof->UploadPackage("ANALYSIS.par");
251 gProof->UploadPackage("ANALYSISalice.par");
7f7086f7 252 gProof->UploadPackage("CORRFW.par");
253 gProof->UploadPackage("PWG2flowCommon.par");
93329510 254 gProof->UploadPackage("PWG2flowTasks.par");
7f7086f7 255
bec5e178 256 // Enable the Packages
257 // The global package
258 //gProof->EnablePackage("aliroot_v4-19-05-AN",kTRUE);
259 // Or separate
260
7f7086f7 261 gProof->EnablePackage("STEERBase");
262 gProof->EnablePackage("ESD");
263 gProof->EnablePackage("AOD");
bec5e178 264 gProof->EnablePackage("PWG2AOD");
265
266 // Always needed
7f7086f7 267 gProof->EnablePackage("ANALYSIS");
268 gProof->EnablePackage("ANALYSISalice");
7f7086f7 269 gProof->EnablePackage("CORRFW");
270 gProof->EnablePackage("PWG2flowCommon");
93329510 271 gProof->EnablePackage("PWG2flowTasks");
7f7086f7 272
273 // Show enables Packages
93329510 274 gProof->ShowEnabledPackages();
275 }
276
73160af6 277}
278
279void SetupPar(char* pararchivename) {
93329510 280 //Load par files, create analysis libraries
281 //For testing, if par file already decompressed and modified
282 //classes then do not decompress.
283
284 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
285 TString parpar(Form("%s.par", pararchivename)) ;
286 if ( gSystem->AccessPathName(parpar.Data()) ) {
287 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
288 TString processline(Form(".! make %s", parpar.Data())) ;
289 gROOT->ProcessLine(processline.Data()) ;
290 gSystem->ChangeDirectory(cdir) ;
291 processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
292 gROOT->ProcessLine(processline.Data()) ;
293 }
294 if ( gSystem->AccessPathName(pararchivename) ) {
295 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
296 gROOT->ProcessLine(processline.Data());
297 }
298
299 TString ocwd = gSystem->WorkingDirectory();
300 gSystem->ChangeDirectory(pararchivename);
301
302 // check for BUILD.sh and execute
303 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
304 printf("*******************************\n");
305 printf("*** Building PAR archive ***\n");
306 cout<<pararchivename<<endl;
307 printf("*******************************\n");
308 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
309 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
310 return -1;
311 }
312 }
313 // check for SETUP.C and execute
314 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
315 printf("*******************************\n");
316 printf("*** Setup PAR archive ***\n");
317 cout<<pararchivename<<endl;
318 printf("*******************************\n");
319 gROOT->Macro("PROOF-INF/SETUP.C");
320 }
321
322 gSystem->ChangeDirectory(ocwd.Data());
323 printf("Current dir: %s\n", ocwd.Data());
73160af6 324}
325
326
327// Helper macros for creating chains
328// from: CreateESDChain.C,v 1.10 jgrosseo Exp
329
330TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
331{
93329510 332 // creates chain of files in a given directory or file containing a list.
333 // In case of directory the structure is expected as:
334 // <aDataDir>/<dir0>/AliESDs.root
335 // <aDataDir>/<dir1>/AliESDs.root
336 // ...
337
338 if (!aDataDir)
339 return 0;
340
341 Long_t id, size, flags, modtime;
342 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
343 {
344 printf("%s not found.\n", aDataDir);
345 return 0;
346 }
347
348 TChain* chain = new TChain("esdTree");
349 TChain* chaingAlice = 0;
350
351 if (flags & 2)
352 {
353 TString execDir(gSystem->pwd());
354 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
355 TList* dirList = baseDir->GetListOfFiles();
356 Int_t nDirs = dirList->GetEntries();
357 gSystem->cd(execDir);
358
359 Int_t count = 0;
360
361 for (Int_t iDir=0; iDir<nDirs; ++iDir)
73160af6 362 {
363 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
364 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
365 continue;
366
367 if (offset > 0)
368 {
369 --offset;
370 continue;
371 }
372
373 if (count++ == aRuns)
374 break;
375
376 TString presentDirName(aDataDir);
377 presentDirName += "/";
378 presentDirName += presentDir->GetName();
379 chain->Add(presentDirName + "/AliESDs.root/esdTree");
380 // cerr<<presentDirName<<endl;
381 }
93329510 382
383 }
384 else
385 {
386 // Open the input stream
387 ifstream in;
388 in.open(aDataDir);
389
390 Int_t count = 0;
391
392 // Read the input list of files and add them to the chain
393 TString esdfile;
394 while(in.good()) {
73160af6 395 in >> esdfile;
396 if (!esdfile.Contains("root")) continue; // protection
397
398 if (offset > 0)
399 {
400 --offset;
401 continue;
402 }
403
404 if (count++ == aRuns)
405 break;
406
93329510 407 // add esd file
73160af6 408 chain->Add(esdfile);
93329510 409 }
410
411 in.close();
412 }
413
414 return chain;
73160af6 415}
416
93329510 417
73160af6 418// Helper macros for creating chains
419// from: CreateESDChain.C,v 1.10 jgrosseo Exp
420
421TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
422{
93329510 423 // creates chain of files in a given directory or file containing a list.
424 // In case of directory the structure is expected as:
425 // <aDataDir>/<dir0>/AliAOD.root
426 // <aDataDir>/<dir1>/AliAOD.root
427 // ...
428
429 if (!aDataDir)
430 return 0;
431
432 Long_t id, size, flags, modtime;
433 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
434 {
435 printf("%s not found.\n", aDataDir);
436 return 0;
437 }
438
439 TChain* chain = new TChain("aodTree");
440 TChain* chaingAlice = 0;
441
442 if (flags & 2)
443 {
444 TString execDir(gSystem->pwd());
445 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
446 TList* dirList = baseDir->GetListOfFiles();
447 Int_t nDirs = dirList->GetEntries();
448 gSystem->cd(execDir);
449
450 Int_t count = 0;
451
452 for (Int_t iDir=0; iDir<nDirs; ++iDir)
73160af6 453 {
454 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
455 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
456 continue;
457
458 if (offset > 0)
459 {
460 --offset;
461 continue;
462 }
463
464 if (count++ == aRuns)
465 break;
466
467 TString presentDirName(aDataDir);
468 presentDirName += "/";
469 presentDirName += presentDir->GetName();
470 chain->Add(presentDirName + "/AliAOD.root/aodTree");
471 // cerr<<presentDirName<<endl;
472 }
93329510 473
474 }
475 else
476 {
477 // Open the input stream
478 ifstream in;
479 in.open(aDataDir);
480
481 Int_t count = 0;
482
483 // Read the input list of files and add them to the chain
484 TString aodfile;
485 while(in.good()) {
73160af6 486 in >> aodfile;
487 if (!aodfile.Contains("root")) continue; // protection
488
489 if (offset > 0)
490 {
491 --offset;
492 continue;
493 }
494
495 if (count++ == aRuns)
496 break;
497
93329510 498 // add aod file
73160af6 499 chain->Add(aodfile);
93329510 500 }
501
502 in.close();
503 }
504
505 return chain;
73160af6 506}
507