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