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