]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FLOW/macros/runFlowTask.C
FMD and ITS additions
[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
ff1a880b 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
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
44e060e0 34void runFlowTask(Int_t mode=mLocal, Int_t nRuns = 1,
238dd515 35//Bool_t DATA = kTRUE, const Char_t* dataDir="/data/alice2/kolk/PP/data/LHC09d/104892/test", Int_t offset = 0)
44e060e0 36 Bool_t DATA = kFALSE, const Char_t* dataDir="/data/alice2/kolk/PP/LHC09d10/104873", Int_t offset = 0)
21f8d9b1 37
f630b0f9 38//void 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)
ff1a880b 41 //Bool_t DATA = kTRUE, const Char_t* dataDir="/alice/data/LHC10b_000115322_p1", Int_t offset=0) // data 7 TeV
f630b0f9 42 //Bool_t DATA = kFALSE, const Char_t* dataDir="/alice/sim/LHC10a18_140012", Int_t offset=0) //perugia0 7 TeV
ff1a880b 43 //Bool_t DATA = kFALSE, const Char_t* dataDir="/alice/sim/LHC10a20_140514", Int_t offset=0) //phojet 7 TeV
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);
44e060e0 77 //if (MCEP) { //Because of FMD task
06f9b526 78 AliMCEventHandler *mc = new AliMCEventHandler();
79 mgr->SetMCtruthEventHandler(mc);
44e060e0 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");
179 cerr<<"libCORRFW loaded..."<<endl;
f630b0f9 180 if (mode==mLocal) {
44e060e0 181 gSystem->Load("libPWG2forward");
182 cerr<<"libPWG2forward loaded..."<<endl;
f630b0f9 183 gSystem->Load("libPWG2flowCommon");
184 cerr<<"libPWG2flowCommon loaded..."<<endl;
185 gSystem->Load("libPWG2flowTasks");
186 cerr<<"libPWG2flowTasks loaded..."<<endl;
187 }
188 if (mode==mGRID) {
189 SetupPar("PWG2flowCommon");
190 cerr<<"PWG2flowCommon.par loaded..."<<endl;
191 SetupPar("PWG2flowTasks");
192 cerr<<"PWG2flowTasks.par loaded..."<<endl;
193 }
93329510 194 }
195
9cc5e012 196 else if (mode == mLocalPAR) {
93329510 197 //--------------------------------------------------------
198 //If you want to use root and par files from aliroot
199 //--------------------------------------------------------
200 SetupPar("STEERBase");
201 SetupPar("ESD");
202 SetupPar("AOD");
203 SetupPar("ANALYSIS");
204 SetupPar("ANALYSISalice");
ff1a880b 205 SetupPar("CORRFW");
93329510 206 SetupPar("PWG2flowCommon");
207 cerr<<"PWG2flowCommon.par loaded..."<<endl;
208 SetupPar("PWG2flowTasks");
209 cerr<<"PWG2flowTasks.par loaded..."<<endl;
210 }
211
212 //---------------------------------------------------------
213 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
214 //---------------------------------------------------------
215 else if (mode==mPROOF) {
216 //
f6cf97c1 217 //gEnv->SetValue("XSec.GSI.DelegProxy","2");
93329510 218 // set to debug root versus if needed
2aa4ebcd 219 //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a_dbg");
edd5904a 220 //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a");
7f7086f7 221 //TProof::Reset("proof://snelling@alicecaf.cern.ch");
93329510 222 // Connect to proof
93329510 223 printf("*** Connect to PROOF ***\n");
238dd515 224 gEnv->SetValue("XSec.GSI.DelegProxy","2");
7f7086f7 225 // Put appropriate username here
226 //TProof::Open("abilandz@alicecaf.cern.ch");
227 //TProof::Open("nkolk@alicecaf.cern.ch");
238dd515 228 //TProof::Open("snelling@localhost");
229 TProof::Open("alice-caf.cern.ch");
bec5e178 230 //TProof::Open("skaf.saske.sk");
231 //TProof::Open("prf000-iep-grid.saske.sk");
232 //Info("runSKAF.C","Loading libs on proof (may take while, around 1 min) ...");
7f7086f7 233 // list the data available
238dd515 234 //gProof->ShowDataSets("/*/*");
235 //gProof->ShowDataSets("/alice/sim/"); //for MC Data
236 //gProof->ShowDataSets("/alice/data/"); //for REAL Data
7f7086f7 237
238 // Clear the Packages
ff1a880b 239 /*
edd5904a 240 gProof->ClearPackage("STEERBase.par");
edd5904a 241 gProof->ClearPackage("ESD.par");
edd5904a 242 gProof->ClearPackage("AOD.par");
edd5904a 243 gProof->ClearPackage("ANALYSIS.par");
edd5904a 244 gProof->ClearPackage("ANALYSISalice.par");
edd5904a 245 gProof->ClearPackage("CORRFW.par");
bec5e178 246
2aa4ebcd 247 gProof->ClearPackage("PWG2flowCommon");
2aa4ebcd 248 gProof->ClearPackage("PWG2flowTasks");
ff1a880b 249 */
7f7086f7 250 // Upload the Packages
251 gProof->UploadPackage("STEERBase.par");
252 gProof->UploadPackage("ESD.par");
253 gProof->UploadPackage("AOD.par");
bec5e178 254
7f7086f7 255 gProof->UploadPackage("ANALYSIS.par");
256 gProof->UploadPackage("ANALYSISalice.par");
7f7086f7 257 gProof->UploadPackage("CORRFW.par");
258 gProof->UploadPackage("PWG2flowCommon.par");
93329510 259 gProof->UploadPackage("PWG2flowTasks.par");
7f7086f7 260
bec5e178 261 // Enable the Packages
262 // The global package
263 //gProof->EnablePackage("aliroot_v4-19-05-AN",kTRUE);
264 // Or separate
265
7f7086f7 266 gProof->EnablePackage("STEERBase");
267 gProof->EnablePackage("ESD");
268 gProof->EnablePackage("AOD");
bec5e178 269
270 // Always needed
7f7086f7 271 gProof->EnablePackage("ANALYSIS");
272 gProof->EnablePackage("ANALYSISalice");
7f7086f7 273 gProof->EnablePackage("CORRFW");
274 gProof->EnablePackage("PWG2flowCommon");
93329510 275 gProof->EnablePackage("PWG2flowTasks");
7f7086f7 276
277 // Show enables Packages
93329510 278 gProof->ShowEnabledPackages();
279 }
280
73160af6 281}
282
283void SetupPar(char* pararchivename) {
93329510 284 //Load par files, create analysis libraries
285 //For testing, if par file already decompressed and modified
286 //classes then do not decompress.
287
288 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
289 TString parpar(Form("%s.par", pararchivename)) ;
290 if ( gSystem->AccessPathName(parpar.Data()) ) {
291 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
292 TString processline(Form(".! make %s", parpar.Data())) ;
293 gROOT->ProcessLine(processline.Data()) ;
294 gSystem->ChangeDirectory(cdir) ;
295 processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
296 gROOT->ProcessLine(processline.Data()) ;
297 }
298 if ( gSystem->AccessPathName(pararchivename) ) {
299 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
300 gROOT->ProcessLine(processline.Data());
301 }
302
303 TString ocwd = gSystem->WorkingDirectory();
304 gSystem->ChangeDirectory(pararchivename);
305
306 // check for BUILD.sh and execute
307 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
308 printf("*******************************\n");
309 printf("*** Building PAR archive ***\n");
310 cout<<pararchivename<<endl;
311 printf("*******************************\n");
312 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
313 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
314 return -1;
315 }
316 }
317 // check for SETUP.C and execute
318 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
319 printf("*******************************\n");
320 printf("*** Setup PAR archive ***\n");
321 cout<<pararchivename<<endl;
322 printf("*******************************\n");
323 gROOT->Macro("PROOF-INF/SETUP.C");
324 }
325
326 gSystem->ChangeDirectory(ocwd.Data());
327 printf("Current dir: %s\n", ocwd.Data());
73160af6 328}
329
330
331// Helper macros for creating chains
332// from: CreateESDChain.C,v 1.10 jgrosseo Exp
333
334TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
335{
93329510 336 // creates chain of files in a given directory or file containing a list.
337 // In case of directory the structure is expected as:
338 // <aDataDir>/<dir0>/AliESDs.root
339 // <aDataDir>/<dir1>/AliESDs.root
340 // ...
341
342 if (!aDataDir)
343 return 0;
344
345 Long_t id, size, flags, modtime;
346 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
347 {
348 printf("%s not found.\n", aDataDir);
349 return 0;
350 }
351
352 TChain* chain = new TChain("esdTree");
353 TChain* chaingAlice = 0;
354
355 if (flags & 2)
356 {
357 TString execDir(gSystem->pwd());
358 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
359 TList* dirList = baseDir->GetListOfFiles();
360 Int_t nDirs = dirList->GetEntries();
361 gSystem->cd(execDir);
362
363 Int_t count = 0;
364
365 for (Int_t iDir=0; iDir<nDirs; ++iDir)
73160af6 366 {
367 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
368 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
369 continue;
370
371 if (offset > 0)
372 {
373 --offset;
374 continue;
375 }
376
377 if (count++ == aRuns)
378 break;
379
380 TString presentDirName(aDataDir);
381 presentDirName += "/";
382 presentDirName += presentDir->GetName();
383 chain->Add(presentDirName + "/AliESDs.root/esdTree");
384 // cerr<<presentDirName<<endl;
385 }
93329510 386
387 }
388 else
389 {
390 // Open the input stream
391 ifstream in;
392 in.open(aDataDir);
393
394 Int_t count = 0;
395
396 // Read the input list of files and add them to the chain
397 TString esdfile;
398 while(in.good()) {
73160af6 399 in >> esdfile;
400 if (!esdfile.Contains("root")) continue; // protection
401
402 if (offset > 0)
403 {
404 --offset;
405 continue;
406 }
407
408 if (count++ == aRuns)
409 break;
410
93329510 411 // add esd file
73160af6 412 chain->Add(esdfile);
93329510 413 }
414
415 in.close();
416 }
417
418 return chain;
73160af6 419}
420
93329510 421
73160af6 422// Helper macros for creating chains
423// from: CreateESDChain.C,v 1.10 jgrosseo Exp
424
425TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
426{
93329510 427 // creates chain of files in a given directory or file containing a list.
428 // In case of directory the structure is expected as:
429 // <aDataDir>/<dir0>/AliAOD.root
430 // <aDataDir>/<dir1>/AliAOD.root
431 // ...
432
433 if (!aDataDir)
434 return 0;
435
436 Long_t id, size, flags, modtime;
437 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
438 {
439 printf("%s not found.\n", aDataDir);
440 return 0;
441 }
442
443 TChain* chain = new TChain("aodTree");
444 TChain* chaingAlice = 0;
445
446 if (flags & 2)
447 {
448 TString execDir(gSystem->pwd());
449 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
450 TList* dirList = baseDir->GetListOfFiles();
451 Int_t nDirs = dirList->GetEntries();
452 gSystem->cd(execDir);
453
454 Int_t count = 0;
455
456 for (Int_t iDir=0; iDir<nDirs; ++iDir)
73160af6 457 {
458 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
459 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
460 continue;
461
462 if (offset > 0)
463 {
464 --offset;
465 continue;
466 }
467
468 if (count++ == aRuns)
469 break;
470
471 TString presentDirName(aDataDir);
472 presentDirName += "/";
473 presentDirName += presentDir->GetName();
474 chain->Add(presentDirName + "/AliAOD.root/aodTree");
475 // cerr<<presentDirName<<endl;
476 }
93329510 477
478 }
479 else
480 {
481 // Open the input stream
482 ifstream in;
483 in.open(aDataDir);
484
485 Int_t count = 0;
486
487 // Read the input list of files and add them to the chain
488 TString aodfile;
489 while(in.good()) {
73160af6 490 in >> aodfile;
491 if (!aodfile.Contains("root")) continue; // protection
492
493 if (offset > 0)
494 {
495 --offset;
496 continue;
497 }
498
499 if (count++ == aRuns)
500 break;
501
93329510 502 // add aod file
73160af6 503 chain->Add(aodfile);
93329510 504 }
505
506 in.close();
507 }
508
509 return chain;
73160af6 510}
511