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