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