]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/runFlowTask.C
1.) Added mode "mGridPAR" in runFlowTask.C and runFlowTaskCentralityTrain.C to run...
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTask.C
1 enum anaModes {mLocal,mLocalPAR,mPROOF,mGrid,mGridPAR};
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 //mGrid: Analyze files on Grid via AliEn plug-in and using precompiled FLOW libraries
6 //mGridPAR: Analyze files on Grid via AliEn plug-in and using par files for FLOW package
7
8 // RUN SETTINGS
9 // Flow analysis method can be:(set to kTRUE or kFALSE)
10 Bool_t MCEP     = kTRUE;  // correlation with Monte Carlo reaction plane
11 Bool_t SP       = kTRUE;  // scalar product method (similar to eventplane method)
12 Bool_t GFC      = kTRUE;  // cumulants based on generating function
13 Bool_t QC       = kTRUE;  // cumulants using Q vectors
14 Bool_t FQD      = kTRUE;  // fit of the distribution of the Q vector (only integrated v)
15 Bool_t LYZ1SUM  = kTRUE;  // Lee Yang Zeroes using sum generating function (integrated v)
16 Bool_t LYZ1PROD = kTRUE;  // Lee Yang Zeroes using product generating function (integrated v)
17 Bool_t LYZ2SUM  = kFALSE; // Lee Yang Zeroes using sum generating function (second pass differential v)
18 Bool_t LYZ2PROD = kFALSE; // Lee Yang Zeroes using product generating function (second pass differential v)
19 Bool_t LYZEP    = kFALSE; // Lee Yang Zeroes Event plane using sum generating function (gives eventplane + weight)
20 Bool_t MH       = kTRUE;  // azimuthal correlators in mixed harmonics  
21 Bool_t NL       = kFALSE;  // nested loops (for instance distribution of phi1-phi2 for all distinct pairs)
22
23 Bool_t METHODS[] = {SP,LYZ1SUM,LYZ1PROD,LYZ2SUM,LYZ2PROD,LYZEP,GFC,QC,FQD,MCEP,MH,NL};
24
25 // Analysis type can be ESD, AOD, MC, ESDMCkineESD, ESDMCkineMC, MK
26 const TString type = "ESD";
27
28 // Boolean to fill/not fill the QA histograms
29 Bool_t QA = kFALSE;   
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 //void runFlowTask(Int_t mode=mLocal, Int_t nRuns = 2, 
35 //Bool_t DATA = kTRUE, const Char_t* dataDir="/data/alice2/kolk/PP/data/LHC09d/104892/test", Int_t offset = 0)
36 //Bool_t DATA = kFALSE, const Char_t* dataDir="/data/alice3/ab/sim/LHC10d4", Int_t offset = 0) // pythia
37 //              Bool_t DATA = kFALSE, const Char_t* dataDir="/data/alice2/kolk/PP/LHC09d10/104873", Int_t offset = 0)
38
39 //void runFlowTask(Int_t mode = mPROOF, Int_t nRuns = 50000000, 
40                  //Bool_t DATA = kFALSE, const Char_t* dataDir="/PWG2/akisiel/Therminator_midcentral_ESD", Int_t offset=0)
41                  //Bool_t DATA = kFALSE, const Char_t* dataDir="/PWG2/akisiel/LHC10d6_0.9TeV_EPOS_12502X", Int_t offset=0)
42                  //Bool_t DATA = kFALSE, const Char_t* dataDir="/alice/sim/LHC10d2_117048", Int_t offset=0) //phojet 7 TeV               
43                  //Bool_t DATA = kTRUE, const Char_t* dataDir="/alice/data/LHC09d_000104792_p6", Int_t offset=0) //data 0.9 TeV
44                  //Bool_t DATA = kFALSE, const Char_t* dataDir="/PWG4/morsch/HIJING_CENT_4EV", Int_t offset=0) //hijing Pb Pb pilot
45
46 void runFlowTask(Int_t mode = mGrid, Bool_t DATA = kFALSE)
47 {
48   // Time:
49   TStopwatch timer;
50   timer.Start();
51   // Cross-check user settings before starting:
52   CrossCheckUserSettings(DATA);
53   // Load needed libraries:
54   LoadLibraries(mode);
55   // Create and configure the AliEn plug-in:
56   if(mode == mGrid || mode == mGridPAR) 
57   {
58    gROOT->LoadMacro("CreateAlienHandler.C");
59    AliAnalysisGrid *alienHandler = CreateAlienHandler();  
60    if (!alienHandler) return;
61   }
62   // Chains:   
63   if(mode==mLocal || mode == mLocalPAR)
64   {
65    if (type!="AOD") { TChain* chain = CreateESDChain(dataDir, nRuns, offset);}
66    else { TChain* chain = CreateAODChain(dataDir, nRuns, offset);}
67   }
68  
69   // Create analysis manager:
70   AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
71   // Connect plug-in to the analysis manager:
72   if(mode == mGrid || mode == mGridPAR) 
73   { 
74    mgr->SetGridHandler(alienHandler);
75   }
76   // Event handlers:
77   if(type == "ESD")
78   {
79    AliVEventHandler* esdH = new AliESDInputHandler;
80    mgr->SetInputEventHandler(esdH);
81    if(MCEP) 
82    { 
83     AliMCEventHandler *mc = new AliMCEventHandler();
84     mgr->SetMCtruthEventHandler(mc); 
85    }
86   } // end of if(type == "ESD")  
87   if(type == "AOD")
88   {
89    AliVEventHandler* aodH = new AliAODInputHandler;
90    mgr->SetInputEventHandler(aodH); 
91    if(MCEP) 
92    { 
93     AliMCEventHandler *mc = new AliMCEventHandler();
94     mgr->SetMCtruthEventHandler(mc);
95    } 
96   } // end of if(type == "AOD")  
97   if(type == "MC" || type == "ESDMCkineESD" || type == "ESDMCkineMC")
98   {
99    AliVEventHandler* esdH = new AliESDInputHandler;
100    mgr->SetInputEventHandler(esdH); 
101    AliMCEventHandler *mc = new AliMCEventHandler();
102    mgr->SetMCtruthEventHandler(mc); 
103   } // end of  if(type == "MC" || type == "ESDMCkineESD" || type == "ESDMCkineMC")
104   // Load the analysis task:
105   gROOT->LoadMacro("AddTaskFlow.C");
106   AliAnalysisTaskFlowEvent* taskFE = AddTaskFlow(type,METHODS,QA,WEIGHTS);
107   // Task to check the offline trigger:
108   if(mode == mLocal || mode == mGrid || mode == mGridPAR) 
109   {
110    gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); 
111   } else if (mode == mPROOF || mode == mLocalPAR) 
112     {
113      gROOT->LoadMacro("AddTaskPhysicsSelection.C"); 
114     }
115   AliPhysicsSelectionTask* physicsSelTask = AddTaskPhysicsSelection();
116   if(!DATA){physicsSelTask->GetPhysicsSelection()->SetAnalyzeMC();}
117   // Enable debug printouts:
118   mgr->SetDebugLevel(2);
119
120   // Run the analysis:
121   if(!mgr->InitAnalysis()){return;}
122   mgr->PrintStatus(); 
123   if(mode == mLocal || mode == mLocalPAR) 
124   {
125    mgr->StartAnalysis("local",chain);
126   } else if(mode == mPROOF) 
127     {
128      mgr->StartAnalysis("proof",dataDir,nRuns,offset);
129     } else if(mode == mGrid || mode == mGridPAR) 
130       { 
131        mgr->StartAnalysis("grid");
132       }
133   // Print real and CPU time used for analysis:  
134   timer.Stop();
135   timer.Print();
136   
137 } // end of void runFlowTask(...)
138
139 //===============================================================================================
140
141 void CrossCheckUserSettings(Bool_t bData) 
142 {
143  // Check in this method if the user settings make sense.
144  
145  if(MCEP==kTRUE && bData==kTRUE)
146  {
147   cout<<endl;
148   cout<<"WARNING: In real datasets there is no Monte Carlo information available !!!!"<<endl;
149   cout<<"         Set for real data analysis DATA = kTRUE and MCEP = kFALSE in the macro."<<endl;
150   cout<<endl;
151   exit(0);
152  }
153  
154  if(LYZ1SUM && LYZ2SUM) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
155  if(LYZ1PROD && LYZ2PROD) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
156  if(LYZ2SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
157  if(LYZ1SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
158
159 } // end of void CrossCheckUserSettings()
160
161 //===============================================================================================
162
163 void LoadLibraries(const anaModes mode) 
164 {  
165   //--------------------------------------
166   // Load the needed libraries most of them already loaded by aliroot
167   //--------------------------------------
168   gSystem->Load("libTree");
169   gSystem->Load("libGeom");
170   gSystem->Load("libVMC");
171   gSystem->Load("libXMLIO");
172   gSystem->Load("libPhysics");
173   
174   //----------------------------------------------------------
175   // >>>>>>>>>>> Local mode <<<<<<<<<<<<<< 
176   //----------------------------------------------------------
177   if (mode==mLocal || mode==mGrid || mode == mGridPAR) {
178     //--------------------------------------------------------
179     // If you want to use already compiled libraries 
180     // in the aliroot distribution
181     //--------------------------------------------------------
182     gSystem->Load("libSTEERBase");
183     gSystem->Load("libESD");
184     gSystem->Load("libAOD");
185     gSystem->Load("libANALYSIS");
186     gSystem->Load("libANALYSISalice");
187     gSystem->Load("libCORRFW");
188     gSystem->Load("libPWG2forward");
189     if(mode==mLocal || mode==mGrid)
190     {
191      gSystem->Load("libPWG2flowCommon");
192      cerr<<"libPWG2flowCommon loaded..."<<endl;
193      gSystem->Load("libPWG2flowTasks");
194      cerr<<"libPWG2flowTasks loaded..."<<endl;
195     }
196     if(mode==mGridPAR) 
197     {
198      SetupPar("PWG2flowCommon");
199      cerr<<"PWG2flowCommon.par loaded..."<<endl;
200      SetupPar("PWG2flowTasks");
201      cerr<<"PWG2flowTasks.par loaded..."<<endl;
202     }
203   }
204   
205   else if (mode == mLocalPAR) {
206     //--------------------------------------------------------
207     //If you want to use root and par files from aliroot
208     //--------------------------------------------------------  
209     SetupPar("STEERBase");
210     SetupPar("ESD");
211     SetupPar("AOD");
212     SetupPar("ANALYSIS");
213     SetupPar("ANALYSISalice");
214         SetupPar("CORRFW");
215     SetupPar("PWG2flowCommon");
216     cerr<<"PWG2flowCommon.par loaded..."<<endl;
217     SetupPar("PWG2flowTasks");
218     cerr<<"PWG2flowTasks.par loaded..."<<endl;
219   }
220   
221   //---------------------------------------------------------
222   // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
223   //---------------------------------------------------------
224   else if (mode==mPROOF) {
225     //
226     //gEnv->SetValue("XSec.GSI.DelegProxy","2");    
227     //  set to debug root versus if needed
228     //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a_dbg");
229     //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a");
230     //TProof::Reset("proof://snelling@alicecaf.cern.ch");     
231     // Connect to proof
232     printf("*** Connect to PROOF ***\n");
233     gEnv->SetValue("XSec.GSI.DelegProxy","2");
234     // Put appropriate username here
235     //TProof::Open("abilandz@alicecaf.cern.ch");
236     //TProof::Open("nkolk@alicecaf.cern.ch");
237     //TProof::Open("snelling@localhost");
238     TProof::Open("alice-caf.cern.ch");
239     //TProof::Open("skaf.saske.sk");
240     //TProof::Open("prf000-iep-grid.saske.sk");
241     //Info("runSKAF.C","Loading libs on proof (may take while, around 1 min) ...");
242     // list the data available
243     //gProof->ShowDataSets("/*/*"); 
244     //gProof->ShowDataSets("/alice/sim/"); //for MC Data
245     //gProof->ShowDataSets("/alice/data/"); //for REAL Data 
246  
247     // Clear the Packages
248     
249     gProof->ClearPackage("STEERBase.par");
250     gProof->ClearPackage("ESD.par");
251     gProof->ClearPackage("AOD.par");
252     gProof->ClearPackage("ANALYSIS.par");
253     gProof->ClearPackage("ANALYSISalice.par");
254     gProof->ClearPackage("CORRFW.par");
255     
256     gProof->ClearPackage("PWG2flowCommon");
257     gProof->ClearPackage("PWG2flowTasks");
258     
259     // Upload the Packages
260     gProof->UploadPackage("STEERBase.par");
261     gProof->UploadPackage("ESD.par");    
262     gProof->UploadPackage("AOD.par");
263        
264     gProof->UploadPackage("ANALYSIS.par"); 
265     gProof->UploadPackage("ANALYSISalice.par");
266     gProof->UploadPackage("CORRFW.par");
267     gProof->UploadPackage("PWG2flowCommon.par");
268     gProof->UploadPackage("PWG2flowTasks.par");
269
270     // Enable the Packages 
271     // The global package
272     //gProof->EnablePackage("aliroot_v4-19-05-AN",kTRUE);
273     // Or separate
274     
275     gProof->EnablePackage("STEERBase");
276     gProof->EnablePackage("ESD");
277     gProof->EnablePackage("AOD");
278     
279     // Always needed
280     gProof->EnablePackage("ANALYSIS");
281     gProof->EnablePackage("ANALYSISalice");
282     gProof->EnablePackage("CORRFW");
283     gProof->EnablePackage("PWG2flowCommon");
284     gProof->EnablePackage("PWG2flowTasks");
285
286     // Show enables Packages
287     gProof->ShowEnabledPackages();
288   }  
289   
290 } // end of void LoadLibraries(const anaModes mode)
291
292 //===============================================================================================
293
294 void SetupPar(char* pararchivename) {
295   //Load par files, create analysis libraries
296   //For testing, if par file already decompressed and modified
297   //classes then do not decompress.
298   
299   TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; 
300   TString parpar(Form("%s.par", pararchivename)) ; 
301   if ( gSystem->AccessPathName(parpar.Data()) ) {
302     gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
303     TString processline(Form(".! make %s", parpar.Data())) ; 
304     gROOT->ProcessLine(processline.Data()) ;
305     gSystem->ChangeDirectory(cdir) ; 
306     processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
307     gROOT->ProcessLine(processline.Data()) ;
308   } 
309   if ( gSystem->AccessPathName(pararchivename) ) {  
310     TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
311     gROOT->ProcessLine(processline.Data());
312   }
313   
314   TString ocwd = gSystem->WorkingDirectory();
315   gSystem->ChangeDirectory(pararchivename);
316   
317   // check for BUILD.sh and execute
318   if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
319     printf("*******************************\n");
320     printf("*** Building PAR archive    ***\n");
321     cout<<pararchivename<<endl;
322     printf("*******************************\n");
323     if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
324       Error("runProcess","Cannot Build the PAR Archive! - Abort!");
325       return -1;
326     }
327   }
328   // check for SETUP.C and execute
329   if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
330     printf("*******************************\n");
331     printf("*** Setup PAR archive       ***\n");
332     cout<<pararchivename<<endl;
333     printf("*******************************\n");
334     gROOT->Macro("PROOF-INF/SETUP.C");
335   }
336   
337   gSystem->ChangeDirectory(ocwd.Data());
338   printf("Current dir: %s\n", ocwd.Data());
339
340 } // end of void SetupPar(char* pararchivename) 
341
342 //===============================================================================================
343
344 // Helper macros for creating chains
345 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
346
347 TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
348 {
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>/AliESDs.root
352   // <aDataDir>/<dir1>/AliESDs.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("esdTree");
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)
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 + "/AliESDs.root/esdTree");
397           //  cerr<<presentDirName<<endl;
398         }
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 esdfile;
411       while(in.good()) {
412         in >> esdfile;
413         if (!esdfile.Contains("root")) continue; // protection
414         
415         if (offset > 0)
416           {
417             --offset;
418             continue;
419           }
420         
421         if (count++ == aRuns)
422           break;
423         
424         // add esd file
425         chain->Add(esdfile);
426       }
427       
428       in.close();
429     }
430   
431   return chain;
432
433 } // end of TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
434
435 //===============================================================================================
436
437 TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
438 {
439   // creates chain of files in a given directory or file containing a list.
440   // In case of directory the structure is expected as:
441   // <aDataDir>/<dir0>/AliAOD.root
442   // <aDataDir>/<dir1>/AliAOD.root
443   // ...
444   
445   if (!aDataDir)
446     return 0;
447   
448   Long_t id, size, flags, modtime;
449   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
450     {
451       printf("%s not found.\n", aDataDir);
452       return 0;
453     }
454   
455   TChain* chain = new TChain("aodTree");
456   TChain* chaingAlice = 0;
457   
458   if (flags & 2)
459     {
460       TString execDir(gSystem->pwd());
461       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
462       TList* dirList            = baseDir->GetListOfFiles();
463       Int_t nDirs               = dirList->GetEntries();
464       gSystem->cd(execDir);
465       
466       Int_t count = 0;
467       
468       for (Int_t iDir=0; iDir<nDirs; ++iDir)
469         {
470           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
471           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
472             continue;
473           
474           if (offset > 0)
475             {
476               --offset;
477               continue;
478             }
479           
480           if (count++ == aRuns)
481             break;
482           
483           TString presentDirName(aDataDir);
484           presentDirName += "/";
485           presentDirName += presentDir->GetName();        
486           chain->Add(presentDirName + "/AliAOD.root/aodTree");
487           // cerr<<presentDirName<<endl;
488         }
489       
490     }
491   else
492     {
493       // Open the input stream
494       ifstream in;
495       in.open(aDataDir);
496       
497       Int_t count = 0;
498       
499       // Read the input list of files and add them to the chain
500       TString aodfile;
501       while(in.good()) {
502         in >> aodfile;
503         if (!aodfile.Contains("root")) continue; // protection
504         
505         if (offset > 0)
506           {
507             --offset;
508             continue;
509           }
510         
511         if (count++ == aRuns)
512           break;
513         
514         // add aod file
515         chain->Add(aodfile);
516       }
517       
518       in.close();
519     }
520   
521   return chain;
522
523 } // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
524