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