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