]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/runFlowTaskCentralityTrain.C
PID cuts + fixes
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTaskCentralityTrain.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 //       (Remark: When using this mode set also Bool_t bUseParFiles = kFALSE; in CreateAlienHandler.C)
7 //mGridPAR: Analyze files on Grid via AliEn plug-in and using par files for FLOW package
8 //          (Remark: when using this mode set also Bool_t bUseParFiles = kTRUE; in CreateAlienHandler.C)
9  
10 // CENTRALITY DEFINITION
11 //Int_t binfirst = 4;  //where do we start numbering bins
12 //Int_t binlast = 6;  //where do we stop numbering bins
13 //const Int_t numberOfCentralityBins = 9;
14 //Int_t centralityArray[numberOfCentralityBins+1] = {41,80,146,245,384,576,835,1203,1471,10000}; // in terms of reference multiplicity
15 Int_t binfirst = 0;  //where do we start numbering bins
16 Int_t binlast = 0;  //where do we stop numbering bins
17 const Int_t numberOfCentralityBins = 1;
18 Int_t centralityArray[numberOfCentralityBins+1] = {41,10000}; // in terms of reference multiplicity
19 TString commonOutputFileName = "outputCentrality"; // e.g.: result for centrality bin 0 will be in the file "outputCentrality0.root", etc
20
21 //void runFlowTaskCentralityTrain(Int_t mode=mLocal, Int_t nRuns = 10, 
22 //Bool_t DATA = kFALSE, const Char_t* dataDir="/Users/snelling/alice_data/Therminator_midcentral", Int_t offset = 0)
23
24 void runFlowTaskCentralityTrain(Int_t mode = mPROOF, Int_t nRuns = 50000000, 
25                  Bool_t DATA = kTRUE, const Char_t* dataDir="/alice/data/LHC10h_000137161_p1_plusplusplus", Int_t offset=0) 
26 //void runFlowTaskCentralityTrain(Int_t mode = mLocal, Int_t nRuns = 50000000, 
27 //                              Bool_t DATA = kTRUE, const Char_t* dataDir="./data/", Int_t offset=0) 
28 //void runFlowTaskCentralityTrain(Int_t mode = mGridPAR, Bool_t DATA = kTRUE)
29 {
30   // Time:
31   TStopwatch timer;
32   timer.Start();
33   // Cross-check user settings before starting:
34   //  CrossCheckUserSettings(DATA);
35   // Load needed libraries:
36   LoadLibraries(mode);
37   // Create and configure the AliEn plug-in:
38   if(mode == mGrid || mode == mGridPAR) 
39     {    
40       gROOT->LoadMacro("CreateAlienHandler.C");
41       AliAnalysisGrid *alienHandler = CreateAlienHandler();  
42       if(!alienHandler) return;
43     }
44   // Chains: 
45   if(mode == mLocal || mode == mLocalPAR) {
46     TChain* chain = CreateESDChain(dataDir, nRuns, offset);
47     //TChain* chain = CreateAODChain(dataDir, nRuns, offset);
48   }
49   
50   // Create analysis manager:
51   AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager"); 
52   // Connect plug-in to the analysis manager:
53   if(mode == mGrid || mode == mGridPAR) 
54     { 
55       mgr->SetGridHandler(alienHandler);
56     }
57   
58   // Event handlers:
59   AliVEventHandler* esdH = new AliESDInputHandler;
60   mgr->SetInputEventHandler(esdH);
61   if (!DATA) {
62     AliMCEventHandler *mc = new AliMCEventHandler();
63     mgr->SetMCtruthEventHandler(mc); 
64   }
65
66   // Task to check the offline trigger:
67   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); 
68   AliPhysicsSelectionTask* physicsSelTask = AddTaskPhysicsSelection(!DATA,0);
69   
70   // Setup analysis per centrality bin:
71   gROOT->LoadMacro("AddTaskFlowCentrality.C");
72   for (Int_t i=binfirst; i<binlast+1; i++)
73   {
74     Int_t lowCentralityBinEdge = centralityArray[i];
75     Int_t highCentralityBinEdge = centralityArray[i+1];
76     Printf("\nWagon for centrality bin %i:",i);
77     AddTaskFlowCentrality( lowCentralityBinEdge,
78                            highCentralityBinEdge,
79                            commonOutputFileName,
80                            i ); 
81   } // end of for (Int_t i=0; i<numberOfCentralityBins; i++)
82
83   // Enable debug printouts:
84   mgr->SetDebugLevel(2);
85   // Run the analysis:
86   if(!mgr->InitAnalysis()) return;  
87   mgr->PrintStatus();
88   if(mode == mLocal || mode == mLocalPAR) {
89     mgr->StartAnalysis("local",chain);
90   } else if(mode == mPROOF) {
91     mgr->StartAnalysis("proof",dataDir,nRuns,offset);
92   } else if(mode == mGrid || mode == mGridPAR) { 
93     mgr->StartAnalysis("grid");
94   }
95
96   // Print real and CPU time used for analysis:
97   timer.Stop();
98   timer.Print();  
99   
100 } // end of void runFlowTaskCentralityTrain(...)
101
102 //===============================================================================================
103 /*
104 void CrossCheckUserSettings(Bool_t bData) 
105 {
106  // Check in this method if the user settings make sense. 
107  if(LYZ1SUM && LYZ2SUM) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
108  if(LYZ1PROD && LYZ2PROD) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
109  if(LYZ2SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
110  if(LYZ1SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
111 } // end of void CrossCheckUserSettings()
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
121   gSystem->Load("libCore");  
122   gSystem->Load("libTree");
123   gSystem->Load("libGeom");
124   gSystem->Load("libVMC");
125   gSystem->Load("libXMLIO");
126   gSystem->Load("libPhysics");
127   gSystem->Load("libXMLParser");
128   gSystem->Load("libProof");
129   
130   if (mode==mLocal || mode==mGrid || mode == mGridPAR || mode == mLocalPAR )
131   {
132     gSystem->Load("libSTEERBase");
133     gSystem->Load("libCDB");
134     gSystem->Load("libRAWDatabase");
135     gSystem->Load("libRAWDatarec");
136     gSystem->Load("libESD");
137     gSystem->Load("libAOD");
138     gSystem->Load("libSTEER");
139     gSystem->Load("libANALYSIS");
140     gSystem->Load("libANALYSISalice");   
141     gSystem->Load("libTOFbase"); 
142     gSystem->Load("libTOFrec"); 
143
144     if (mode == mLocal || mode == mGrid)
145     {
146       gSystem->Load("libPWG2flowCommon"); 
147       gSystem->Load("libPWG2flowTasks"); 
148     }
149     if (mode == mLocalPAR || mode == mGridPAR )
150     {
151       AliAnalysisAlien::SetupPar("PWG2flowCommon");
152       AliAnalysisAlien::SetupPar("PWG2flowTasks");
153     }
154   }
155   
156   //---------------------------------------------------------
157   // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
158   //---------------------------------------------------------
159   else if (mode==mPROOF) {
160     //  set to debug root versus if needed
161     //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a_dbg");
162     //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a");
163     //TProof::Reset("proof://snelling@alicecaf.cern.ch");     
164     // Connect to proof
165     printf("*** Connect to PROOF ***\n");
166     gEnv->SetValue("XSec.GSI.DelegProxy","2");
167     TProof::Open("mkrzewic@alice-caf.cern.ch");
168     //TProof::Open("mkrzewic@skaf.saske.sk");
169      // list the data available
170     //gProof->ShowDataSets("/*/*"); 
171     //gProof->ShowDataSets("/alice/sim/"); //for MC Data
172     //gProof->ShowDataSets("/alice/data/"); //for REAL Data 
173  
174     // Clear the Packages
175     /*    
176     gProof->ClearPackage("STEERBase.par");
177     gProof->ClearPackage("ESD.par");
178     gProof->ClearPackage("AOD.par");
179     */
180     //gProof->ClearPackage("ANALYSIS.par");
181     //gProof->ClearPackage("ANALYSISalice.par");
182     //gProof->ClearPackage("CORRFW.par");
183     
184     gProof->ClearPackage("PWG2flowCommon");
185     gProof->ClearPackage("PWG2flowTasks");
186     
187     // Upload the Packages
188     //gProof->UploadPackage("STEERBase.par");
189     //gProof->UploadPackage("ESD.par");    
190     //gProof->UploadPackage("AOD.par");
191        
192     //gProof->UploadPackage("ANALYSIS.par"); 
193     //gProof->UploadPackage("ANALYSISalice.par");
194     gProof->UploadPackage("CORRFW.par");
195     gProof->UploadPackage("PWG2flowCommon.par");
196     gProof->UploadPackage("PWG2flowTasks.par");
197     gProof->UploadPackage("ALIRECO.par");
198
199     // Enable the Packages 
200     // The global package
201     TList* list = new TList();
202     list->Add(new TNamed("ALIROOT_EXTRA_INCLUDES","RAW:OCDB:STEER:TOF"));
203     gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-07-AN",list);
204     gProof->EnablePackage("ALIRECO");
205     //gProof->EnablePackage("ANALYSIS");
206     //gProof->EnablePackage("ANALYSISalice");
207     //gProof->EnablePackage("CORRFW");
208     gProof->EnablePackage("PWG2flowCommon");
209     gProof->EnablePackage("PWG2flowTasks");
210
211     // Show enables Packages
212     gProof->ShowEnabledPackages();
213   }  
214   
215 } // end of void LoadLibraries(const anaModes mode) 
216
217 // Helper macros for creating chains
218 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
219
220 TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
221 {
222   // creates chain of files in a given directory or file containing a list.
223   // In case of directory the structure is expected as:
224   // <aDataDir>/<dir0>/AliESDs.root
225   // <aDataDir>/<dir1>/AliESDs.root
226   // ...
227   
228   if (!aDataDir)
229     return 0;
230   
231   Long_t id, size, flags, modtime;
232   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
233     {
234       printf("%s not found.\n", aDataDir);
235       return 0;
236     }
237   
238   TChain* chain = new TChain("esdTree");
239   TChain* chaingAlice = 0;
240   
241   if (flags & 2)
242     {
243       TString execDir(gSystem->pwd());
244       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
245       TList* dirList            = baseDir->GetListOfFiles();
246       Int_t nDirs               = dirList->GetEntries();
247       gSystem->cd(execDir);
248       
249       Int_t count = 0;
250       
251       for (Int_t iDir=0; iDir<nDirs; ++iDir)
252         {
253           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
254           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
255             continue;
256           
257           if (offset > 0)
258             {
259               --offset;
260               continue;
261             }
262           
263           if (count++ == aRuns)
264             break;
265           
266           TString presentDirName(aDataDir);
267           presentDirName += "/";
268           presentDirName += presentDir->GetName();        
269           chain->Add(presentDirName + "/AliESDs.root/esdTree");
270           //  cerr<<presentDirName<<endl;
271         }
272       
273     }
274   else
275     {
276       // Open the input stream
277       ifstream in;
278       in.open(aDataDir);
279       
280       Int_t count = 0;
281       
282       // Read the input list of files and add them to the chain
283       TString esdfile;
284       while(in.good()) {
285         in >> esdfile;
286         if (!esdfile.Contains("root")) continue; // protection
287         
288         if (offset > 0)
289           {
290             --offset;
291             continue;
292           }
293         
294         if (count++ == aRuns)
295           break;
296         
297         // add esd file
298         chain->Add(esdfile);
299       }
300       
301       in.close();
302     }
303   
304   return chain;
305
306 } // end of TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
307
308 //===============================================================================================
309
310 TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
311 {
312   // creates chain of files in a given directory or file containing a list.
313   // In case of directory the structure is expected as:
314   // <aDataDir>/<dir0>/AliAOD.root
315   // <aDataDir>/<dir1>/AliAOD.root
316   // ...
317   
318   if (!aDataDir)
319     return 0;
320   
321   Long_t id, size, flags, modtime;
322   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
323     {
324       printf("%s not found.\n", aDataDir);
325       return 0;
326     }
327   
328   TChain* chain = new TChain("aodTree");
329   TChain* chaingAlice = 0;
330   
331   if (flags & 2)
332     {
333       TString execDir(gSystem->pwd());
334       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
335       TList* dirList            = baseDir->GetListOfFiles();
336       Int_t nDirs               = dirList->GetEntries();
337       gSystem->cd(execDir);
338       
339       Int_t count = 0;
340       
341       for (Int_t iDir=0; iDir<nDirs; ++iDir)
342         {
343           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
344           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
345             continue;
346           
347           if (offset > 0)
348             {
349               --offset;
350               continue;
351             }
352           
353           if (count++ == aRuns)
354             break;
355           
356           TString presentDirName(aDataDir);
357           presentDirName += "/";
358           presentDirName += presentDir->GetName();        
359           chain->Add(presentDirName + "/AliAOD.root/aodTree");
360           // cerr<<presentDirName<<endl;
361         }
362       
363     }
364   else
365     {
366       // Open the input stream
367       ifstream in;
368       in.open(aDataDir);
369       
370       Int_t count = 0;
371       
372       // Read the input list of files and add them to the chain
373       TString aodfile;
374       while(in.good()) {
375         in >> aodfile;
376         if (!aodfile.Contains("root")) continue; // protection
377         
378         if (offset > 0)
379           {
380             --offset;
381             continue;
382           }
383         
384         if (count++ == aRuns)
385           break;
386         
387         // add aod file
388         chain->Add(aodfile);
389       }
390       
391       in.close();
392     }
393   
394   return chain;
395
396 } // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
397