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