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