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