]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - PWG2/FLOW/macros/runFlowTask.C
AliAnaElectron (Jenn):
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTask.C
... / ...
CommitLineData
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
6// RUN SETTINGS
7
8// Flow analysis method can be:(set to kTRUE or kFALSE)
9Bool_t SP = kTRUE;
10Bool_t LYZ1SUM = kTRUE;
11Bool_t LYZ1PROD = kTRUE;
12Bool_t LYZ2SUM = kFALSE;
13Bool_t LYZ2PROD = kFALSE;
14Bool_t LYZEP = kFALSE;
15Bool_t GFC = kTRUE;
16Bool_t QC = kTRUE;
17Bool_t FQD = kTRUE;
18Bool_t MCEP = kTRUE; //not for pp
19
20Bool_t METHODS[] = {SP,LYZ1SUM,LYZ1PROD,LYZ2SUM,LYZ2PROD,LYZEP,GFC,QC,FQD,MCEP};
21
22// Analysis type can be ESD, AOD, MC, ESDMC0, ESDMC1
23const TString type = "ESD";
24
25// Boolean to fill/not fill the QA histograms
26Bool_t QA = kTRUE;
27
28// Boolean to use/not use weights for the Q vector
29Bool_t WEIGHTS[] = {kFALSE,kFALSE,kFALSE}; //Phi, v'(pt), v'(eta)
30
31
32//void runFlowTask(Int_t mode=mLocal, Int_t nRuns = 100,
33 //const Char_t* dataDir="/data/alice2/kolk/PP/LHC09a4/81119", Int_t offset = 0)
34 //const Char_t* dataDir="/data/alice2/kolk/Therminator_midcentral", Int_t offset = 0)
35 //const Char_t* dataDir="/Users/snelling/alice_data/Therminator_midcentral", Int_t offset = 0)
36void runFlowTask(Int_t mode=mPROOF, Int_t nRuns = 100000,
37 //const Char_t* dataDir="/COMMON/COMMON/LHC09a14_0.9TeV_0.5T", Int_t offset = 0)
38 const Char_t* dataDir="/PWG2/akisiel/Therminator_midcentral_ESD", Int_t offset=0)
39 //const Char_t* dataDir="/COMMON/COMMON/LHC09a4_run8158X", Int_t offset = 0)
40
41{
42 TStopwatch timer;
43 timer.Start();
44
45 LoadLibraries(mode);
46
47 if (mode==mLocal || mode == mLocalPAR || mode == mGRID) {
48 if (type!="AOD") { TChain* chain = CreateESDChain(dataDir, nRuns, offset);}
49 else { TChain* chain = CreateAODChain(dataDir, nRuns, offset);}
50 }
51 //____________________________________________//
52 // Make the analysis manager
53 AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
54
55 if (type == "ESD"){
56 AliVEventHandler* esdH = new AliESDInputHandler;
57 mgr->SetInputEventHandler(esdH);
58
59 AliMCEventHandler *mc = new AliMCEventHandler();
60 mgr->SetMCtruthEventHandler(mc);
61 }
62
63 if (type == "AOD"){
64 AliVEventHandler* aodH = new AliAODInputHandler;
65 mgr->SetInputEventHandler(aodH);
66
67 AliMCEventHandler *mc = new AliMCEventHandler();
68 mgr->SetMCtruthEventHandler(mc);
69 }
70
71 if (type == "MC" || type == "ESDMC0" || type == "ESDMC1"){
72 AliVEventHandler* esdH = new AliESDInputHandler;
73 mgr->SetInputEventHandler(esdH);
74
75 AliMCEventHandler *mc = new AliMCEventHandler();
76 mgr->SetMCtruthEventHandler(mc);
77 }
78
79
80 //____________________________________________//
81 // Load the tasks
82 gROOT->LoadMacro("AddTaskFlow.C");
83 AliAnalysisTaskFlowEvent* taskFE = AddTaskFlow(type,METHODS,QA,WEIGHTS);
84
85 //____________________________________________//
86 // Run the analysis
87 if (!mgr->InitAnalysis()) return;
88 mgr->PrintStatus();
89
90 if (mode==mLocal || mode == mLocalPAR) {
91 mgr->StartAnalysis("local",chain);
92 }
93 else if (mode==mPROOF) {
94 mgr->StartAnalysis("proof",dataDir,nRuns,offset);
95 }
96 else if (mode==mGRID) {
97 mgr->StartAnalysis("local",chain);
98 }
99
100 timer.Stop();
101 timer.Print();
102
103}
104
105
106void LoadLibraries(const anaModes mode) {
107
108 //--------------------------------------
109 // Load the needed libraries most of them already loaded by aliroot
110 //--------------------------------------
111 gSystem->Load("libTree.so");
112 gSystem->Load("libGeom.so");
113 gSystem->Load("libVMC.so");
114 gSystem->Load("libXMLIO.so");
115 gSystem->Load("libPhysics.so");
116
117 //----------------------------------------------------------
118 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
119 //----------------------------------------------------------
120 if (mode==mLocal) {
121 //--------------------------------------------------------
122 // If you want to use already compiled libraries
123 // in the aliroot distribution
124 //--------------------------------------------------------
125 gSystem->Load("libSTEERBase");
126 gSystem->Load("libESD");
127 gSystem->Load("libAOD");
128 gSystem->Load("libANALYSIS");
129 gSystem->Load("libANALYSISalice");
130 gSystem->Load("libCORRFW.so");
131 cerr<<"libCORRFW.so loaded..."<<endl;
132 gSystem->Load("libPWG2flowCommon.so");
133 cerr<<"libPWG2flowCommon.so loaded..."<<endl;
134 gSystem->Load("libPWG2flowTasks.so");
135 cerr<<"libPWG2flowTasks.so loaded..."<<endl;
136 }
137
138 else if (mode == mLocalPAR || mode == mGRID) {
139 //--------------------------------------------------------
140 //If you want to use root and par files from aliroot
141 //--------------------------------------------------------
142 SetupPar("STEERBase");
143 SetupPar("ESD");
144 SetupPar("AOD");
145 SetupPar("ANALYSIS");
146 SetupPar("ANALYSISalice");
147 SetupPar("PWG2AOD");
148 SetupPar("CORRFW");
149 SetupPar("PWG2flowCommon");
150 cerr<<"PWG2flowCommon.par loaded..."<<endl;
151 SetupPar("PWG2flowTasks");
152 cerr<<"PWG2flowTasks.par loaded..."<<endl;
153 }
154
155 //---------------------------------------------------------
156 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
157 //---------------------------------------------------------
158 else if (mode==mPROOF) {
159 //
160
161 // set to debug root versus if needed
162 //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a_dbg");
163 //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a");
164
165
166 // Connect to proof
167 // Put appropriate username here
168 // TProof::Reset("proof://snelling@alicecaf.cern.ch");
169 printf("*** Connect to PROOF ***\n");
170 // TProof::Open("abilandz@alicecaf.cern.ch");
171 // TProof::Open("nkolk@alicecaf.cern.ch");
172 TProof::Open("snelling@localhost");
173 // list the data available
174 // gProof->ShowDataSets("/*/*");
175
176 // Enable the STEERBase Package
177 gProof->ClearPackage("STEERBase.par");
178 gProof->UploadPackage("STEERBase.par");
179 gProof->EnablePackage("STEERBase");
180 // Enable the ESD Package
181 gProof->ClearPackage("ESD.par");
182 gProof->UploadPackage("ESD.par");
183 gProof->EnablePackage("ESD");
184 // Enable the AOD Package
185 gProof->ClearPackage("AOD.par");
186 gProof->UploadPackage("AOD.par");
187 gProof->EnablePackage("AOD");
188 // Enable the Analysis Package
189 gProof->ClearPackage("ANALYSIS.par");
190 gProof->UploadPackage("ANALYSIS.par");
191 gProof->EnablePackage("ANALYSIS");
192 // Enable the Analysis Package alice
193 gProof->ClearPackage("ANALYSISalice.par");
194 gProof->UploadPackage("ANALYSISalice.par");
195 gProof->EnablePackage("ANALYSISalice");
196 // Load the PWG2 AOD
197 gProof->ClearPackage("PWG2AOD.par");
198 gProof->UploadPackage("PWG2AOD.par");
199 gProof->EnablePackage("PWG2AOD");
200 // Enable the Correction Framework
201 gProof->ClearPackage("CORRFW.par");
202 gProof->UploadPackage("CORRFW.par");
203 gProof->EnablePackage("CORRFW");
204 // Enable Flow Analysis
205 gProof->ClearPackage("PWG2flowCommon");
206 gProof->UploadPackage("PWG2flowCommon.par");
207 gProof->EnablePackage("PWG2flowCommon");
208 gProof->ClearPackage("PWG2flowTasks");
209 gProof->UploadPackage("PWG2flowTasks.par");
210 gProof->EnablePackage("PWG2flowTasks");
211 //
212 gProof->ShowEnabledPackages();
213 }
214
215}
216
217void SetupPar(char* pararchivename) {
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());
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{
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)
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 }
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()) {
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
345 // add esd file
346 chain->Add(esdfile);
347 }
348
349 in.close();
350 }
351
352 return chain;
353}
354
355
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{
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)
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 }
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()) {
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
436 // add aod file
437 chain->Add(aodfile);
438 }
439
440 in.close();
441 }
442
443 return chain;
444}
445