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