]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/runFlowTask.C
add some comments
[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     gProof->ClearPackage("STEERBase.par");
185     gProof->ClearPackage("ESD.par");
186     gProof->ClearPackage("AOD.par");
187     gProof->ClearPackage("ANALYSIS.par");
188     gProof->ClearPackage("ANALYSISalice.par");
189     gProof->ClearPackage("PWG2AOD.par");
190     gProof->ClearPackage("CORRFW.par");
191     gProof->ClearPackage("PWG2flowCommon");
192     gProof->ClearPackage("PWG2flowTasks");
193
194
195     // Upload the Packages
196     gProof->UploadPackage("STEERBase.par");
197     gProof->UploadPackage("ESD.par");    
198     gProof->UploadPackage("AOD.par");
199     gProof->UploadPackage("ANALYSIS.par"); 
200     gProof->UploadPackage("ANALYSISalice.par");
201     gProof->UploadPackage("PWG2AOD.par");
202     gProof->UploadPackage("CORRFW.par");
203     gProof->UploadPackage("PWG2flowCommon.par");
204     gProof->UploadPackage("PWG2flowTasks.par");
205
206     // Enable the Packages
207     gProof->EnablePackage("STEERBase");
208     gProof->EnablePackage("ESD");
209     gProof->EnablePackage("AOD");
210     gProof->EnablePackage("ANALYSIS");
211     gProof->EnablePackage("ANALYSISalice");
212     gProof->EnablePackage("PWG2AOD");
213     gProof->EnablePackage("CORRFW");
214     gProof->EnablePackage("PWG2flowCommon");
215     gProof->EnablePackage("PWG2flowTasks");
216
217     // Show enables Packages
218     gProof->ShowEnabledPackages();
219   }  
220   
221 }
222
223 void SetupPar(char* pararchivename) {
224   //Load par files, create analysis libraries
225   //For testing, if par file already decompressed and modified
226   //classes then do not decompress.
227   
228   TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; 
229   TString parpar(Form("%s.par", pararchivename)) ; 
230   if ( gSystem->AccessPathName(parpar.Data()) ) {
231     gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
232     TString processline(Form(".! make %s", parpar.Data())) ; 
233     gROOT->ProcessLine(processline.Data()) ;
234     gSystem->ChangeDirectory(cdir) ; 
235     processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
236     gROOT->ProcessLine(processline.Data()) ;
237   } 
238   if ( gSystem->AccessPathName(pararchivename) ) {  
239     TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
240     gROOT->ProcessLine(processline.Data());
241   }
242   
243   TString ocwd = gSystem->WorkingDirectory();
244   gSystem->ChangeDirectory(pararchivename);
245   
246   // check for BUILD.sh and execute
247   if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
248     printf("*******************************\n");
249     printf("*** Building PAR archive    ***\n");
250     cout<<pararchivename<<endl;
251     printf("*******************************\n");
252     if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
253       Error("runProcess","Cannot Build the PAR Archive! - Abort!");
254       return -1;
255     }
256   }
257   // check for SETUP.C and execute
258   if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
259     printf("*******************************\n");
260     printf("*** Setup PAR archive       ***\n");
261     cout<<pararchivename<<endl;
262     printf("*******************************\n");
263     gROOT->Macro("PROOF-INF/SETUP.C");
264   }
265   
266   gSystem->ChangeDirectory(ocwd.Data());
267   printf("Current dir: %s\n", ocwd.Data());
268 }
269
270
271 // Helper macros for creating chains
272 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
273
274 TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
275 {
276   // creates chain of files in a given directory or file containing a list.
277   // In case of directory the structure is expected as:
278   // <aDataDir>/<dir0>/AliESDs.root
279   // <aDataDir>/<dir1>/AliESDs.root
280   // ...
281   
282   if (!aDataDir)
283     return 0;
284   
285   Long_t id, size, flags, modtime;
286   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
287     {
288       printf("%s not found.\n", aDataDir);
289       return 0;
290     }
291   
292   TChain* chain = new TChain("esdTree");
293   TChain* chaingAlice = 0;
294   
295   if (flags & 2)
296     {
297       TString execDir(gSystem->pwd());
298       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
299       TList* dirList            = baseDir->GetListOfFiles();
300       Int_t nDirs               = dirList->GetEntries();
301       gSystem->cd(execDir);
302       
303       Int_t count = 0;
304       
305       for (Int_t iDir=0; iDir<nDirs; ++iDir)
306         {
307           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
308           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
309             continue;
310           
311           if (offset > 0)
312             {
313               --offset;
314               continue;
315             }
316           
317           if (count++ == aRuns)
318             break;
319           
320           TString presentDirName(aDataDir);
321           presentDirName += "/";
322           presentDirName += presentDir->GetName();        
323           chain->Add(presentDirName + "/AliESDs.root/esdTree");
324           //  cerr<<presentDirName<<endl;
325         }
326       
327     }
328   else
329     {
330       // Open the input stream
331       ifstream in;
332       in.open(aDataDir);
333       
334       Int_t count = 0;
335       
336       // Read the input list of files and add them to the chain
337       TString esdfile;
338       while(in.good()) {
339         in >> esdfile;
340         if (!esdfile.Contains("root")) continue; // protection
341         
342         if (offset > 0)
343           {
344             --offset;
345             continue;
346           }
347         
348         if (count++ == aRuns)
349           break;
350         
351         // add esd file
352         chain->Add(esdfile);
353       }
354       
355       in.close();
356     }
357   
358   return chain;
359 }
360
361
362 // Helper macros for creating chains
363 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
364
365 TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
366 {
367   // creates chain of files in a given directory or file containing a list.
368   // In case of directory the structure is expected as:
369   // <aDataDir>/<dir0>/AliAOD.root
370   // <aDataDir>/<dir1>/AliAOD.root
371   // ...
372   
373   if (!aDataDir)
374     return 0;
375   
376   Long_t id, size, flags, modtime;
377   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
378     {
379       printf("%s not found.\n", aDataDir);
380       return 0;
381     }
382   
383   TChain* chain = new TChain("aodTree");
384   TChain* chaingAlice = 0;
385   
386   if (flags & 2)
387     {
388       TString execDir(gSystem->pwd());
389       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
390       TList* dirList            = baseDir->GetListOfFiles();
391       Int_t nDirs               = dirList->GetEntries();
392       gSystem->cd(execDir);
393       
394       Int_t count = 0;
395       
396       for (Int_t iDir=0; iDir<nDirs; ++iDir)
397         {
398           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
399           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
400             continue;
401           
402           if (offset > 0)
403             {
404               --offset;
405               continue;
406             }
407           
408           if (count++ == aRuns)
409             break;
410           
411           TString presentDirName(aDataDir);
412           presentDirName += "/";
413           presentDirName += presentDir->GetName();        
414           chain->Add(presentDirName + "/AliAOD.root/aodTree");
415           // cerr<<presentDirName<<endl;
416         }
417       
418     }
419   else
420     {
421       // Open the input stream
422       ifstream in;
423       in.open(aDataDir);
424       
425       Int_t count = 0;
426       
427       // Read the input list of files and add them to the chain
428       TString aodfile;
429       while(in.good()) {
430         in >> aodfile;
431         if (!aodfile.Contains("root")) continue; // protection
432         
433         if (offset > 0)
434           {
435             --offset;
436             continue;
437           }
438         
439         if (count++ == aRuns)
440           break;
441         
442         // add aod file
443         chain->Add(aodfile);
444       }
445       
446       in.close();
447     }
448   
449   return chain;
450 }
451