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