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