]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/runFlowTaskCentralityTrain.C
coverity fix (Ruben)
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTaskCentralityTrain.C
1 enum anaModes {mLocal,mPROOF,mGrid};
2 //mLocal: Analyze locally files in your computer using aliroot
3 //mPROOF: Analyze CAF files with PROOF
4 //mGrid: Analyze files on Grid via AliEn plug-in and using precompiled FLOW libraries
5
6 // CENTRALITY DEFINITION
7 //Int_t binfirst = 4;  //where do we start numbering bins
8 //Int_t binlast = 6;  //where do we stop numbering bins
9 //const Int_t numberOfCentralityBins = 9;
10 Int_t binfirst = 0;  //where do we start numbering bins
11 Int_t binlast = 8;  //where do we stop numbering bins
12 const Int_t numberOfCentralityBins = 9;
13 Float_t centralityArray[numberOfCentralityBins+1] = {0.,5.,10.,20.,30.,40.,50.,60.,70.,80.}; // in centrality percentile
14 //Int_t centralityArray[numberOfCentralityBins+1] = {41,80,146,245,384,576,835,1203,1471,10000}; // in terms of TPC only reference multiplicity
15
16 TString commonOutputFileName = "outputCentrality"; // e.g.: result for centrality bin 0 will be in the file "outputCentrality0.root", etc
17
18 //void runFlowTaskCentralityTrain(Int_t mode=mLocal, Int_t nEvents = 10,
19 //Bool_t DATA = kFALSE, const Char_t* dataDir="/Users/snelling/alice_data/Therminator_midcentral", Int_t offset = 0)
20
21 void runFlowTaskCentralityTrain( Int_t mode = mPROOF,
22                                  Bool_t useFlowParFiles = kFALSE,
23                                  Bool_t DATA = kTRUE,
24                                  const Char_t* dataDir = "/alice/data/LHC10h_000137162_p1_plusplusplus#esdTree",
25                                  Int_t nEvents = 1e4,
26                                  Int_t offset = 0,
27                                  Bool_t useTender = kFALSE )
28 {
29   // Time:
30   TStopwatch timer;
31   timer.Start();
32   // Cross-check user settings before starting:
33   //  CrossCheckUserSettings(DATA);
34
35   // Load needed libraries:
36   LoadLibraries(mode,useFlowParFiles);
37
38   // Create analysis manager:
39   AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
40
41   // Chains:
42   if(mode == mLocal)
43   {
44     TChain* chain = CreateESDChain(dataDir, nEvents, offset);
45     //TChain* chain = CreateAODChain(dataDir, nEvents, offset);
46   }
47
48   // Connect plug-in to the analysis manager:
49   if(mode == mGrid)
50   {
51     gROOT->LoadMacro("CreateAlienHandler.C");
52     AliAnalysisGrid *alienHandler = CreateAlienHandler(useFlowParFiles);
53     if(!alienHandler) return;
54     mgr->SetGridHandler(alienHandler);
55   }
56
57   // Event handlers:
58   AliVEventHandler* esdH = new AliESDInputHandler;
59   mgr->SetInputEventHandler(esdH);
60   if (!DATA)
61   {
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   AddTaskPhysicsSelection(!DATA);
69
70   //Add the centrality determination task
71   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
72   AliCentralitySelectionTask* centSelTask = AddTaskCentrality();
73   if (!DATA) centSelTask->SetMCInput();
74   if (DATA) centSelTask->SetPass(1);
75
76
77   if (useTender)
78   {
79     //Add the tenders
80     gROOT->LoadMacro("$ALICE_ROOT/PWG2/FLOW/macros/AddTaskTenderFlow.C");
81     AddTaskTenderFlow();
82   }
83
84   // Setup analysis per centrality bin:
85   gROOT->LoadMacro("AddTaskFlowCentrality.C");
86   for (Int_t i=binfirst; i<binlast+1; i++)
87   {
88     Float_t lowCentralityBinEdge = centralityArray[i];
89     Float_t highCentralityBinEdge = centralityArray[i+1];
90     Printf("\nWagon for centrality bin %i: %.0f-%.0f",i,lowCentralityBinEdge,highCentralityBinEdge);
91     AddTaskFlowCentrality( lowCentralityBinEdge,
92                            highCentralityBinEdge,
93                            commonOutputFileName );
94   } // end of for (Int_t i=0; i<numberOfCentralityBins; i++)
95
96   // Enable debug printouts:
97   mgr->SetDebugLevel(2);
98   // Run the analysis:
99   if(!mgr->InitAnalysis()) return;
100   mgr->PrintStatus();
101   if(mode == mLocal)
102   {
103     mgr->StartAnalysis("local",chain);
104   }
105   else if(mode == mPROOF)
106   {
107     mgr->StartAnalysis("proof",dataDir,nEvents,offset);
108   }
109   else if(mode == mGrid)
110   {
111     mgr->StartAnalysis("grid");
112   }
113
114   // Print real and CPU time used for analysis:
115   timer.Stop();
116   timer.Print();
117
118 } // end of void runFlowTaskCentralityTrain(...)
119
120 //===============================================================================================
121 /*
122 void CrossCheckUserSettings(Bool_t bData)
123 {
124  // Check in this method if the user settings make sense.
125  if(LYZ1SUM && LYZ2SUM) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
126  if(LYZ1PROD && LYZ2PROD) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
127  if(LYZ2SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
128  if(LYZ1SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
129 } // end of void CrossCheckUserSettings()
130 */
131 //===============================================================================================
132
133 void LoadLibraries(const anaModes mode, Bool_t useFlowParFiles )
134 {
135   //--------------------------------------
136   // Load the needed libraries most of them already loaded by aliroot
137   //--------------------------------------
138
139   gSystem->Load("libCore");
140   gSystem->Load("libTree");
141   gSystem->Load("libGeom");
142   gSystem->Load("libVMC");
143   gSystem->Load("libXMLIO");
144   gSystem->Load("libPhysics");
145   gSystem->Load("libXMLParser");
146   gSystem->Load("libProof");
147   gSystem->Load("libMinuit");
148
149   if (mode==mLocal || mode==mGrid)
150   {
151     gSystem->Load("libSTEERBase");
152     gSystem->Load("libCDB");
153     gSystem->Load("libRAWDatabase");
154     gSystem->Load("libRAWDatarec");
155     gSystem->Load("libESD");
156     gSystem->Load("libAOD");
157     gSystem->Load("libSTEER");
158     gSystem->Load("libANALYSIS");
159     gSystem->Load("libANALYSISalice");
160     gSystem->Load("libTPCbase");
161     gSystem->Load("libTOFbase");
162     gSystem->Load("libTOFrec");
163     gSystem->Load("libTRDbase");
164     gSystem->Load("libVZERObase");
165     gSystem->Load("libVZEROrec");
166     gSystem->Load("libT0base");
167     gSystem->Load("libT0rec");
168     gSystem->Load("libTENDER");
169     gSystem->Load("libTENDERSupplies");
170
171     if (useFlowParFiles)
172     {
173       AliAnalysisAlien::SetupPar("PWG2flowCommon");
174       AliAnalysisAlien::SetupPar("PWG2flowTasks");
175     }
176     else
177     {
178       gSystem->Load("libPWG2flowCommon");
179       gSystem->Load("libPWG2flowTasks");
180     }
181   }
182   else if (mode==mPROOF)
183   {
184     TList* list = new TList();
185     list->Add(new TNamed("ALIROOT_MODE", "ALIROOT"));
186     if (useFlowParFiles)
187       list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "ANALYSIS:ANALYSISalice:TENDER:TENDERSupplies"));
188     else
189       list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "ANALYSIS:ANALYSISalice:TENDER:TENDERSupplies:PWG2flowCommon:PWG2flowTasks"));
190
191     //list->Add(new TNamed("ALIROOT_EXTRA_INCLUDES","PWG2/FLOW/AliFlowCommon:PWG2/FLOW/AliFlowTasks"));
192
193     // Connect to proof
194     printf("*** Connect to PROOF ***\n");
195     gEnv->SetValue("XSec.GSI.DelegProxy","2");
196     //TProof* proof = TProof::Open("alice-caf.cern.ch");
197     TProof* proof = TProof::Open("skaf.saske.sk");
198
199     // list the data available
200     //gProof->ShowDataSets("/*/*");
201     //gProof->ShowDataSets("/alice/sim/"); //for MC Data
202     //gProof->ShowDataSets("/alice/data/"); //for REAL Data
203
204     proof->ClearPackages();
205     proof->EnablePackage("VO_ALICE@AliRoot::v4-21-14-AN",list);
206
207     if (useFlowParFiles)
208     {
209       gProof->UploadPackage("PWG2flowCommon.par");
210       gProof->UploadPackage("PWG2flowTasks.par");
211     }
212
213     // Show enables Packages
214     gProof->ShowEnabledPackages();
215   }
216 } // end of void LoadLibraries(const anaModes mode)
217
218 // Helper macros for creating chains
219 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
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     {
286       in >> esdfile;
287       if (!esdfile.Contains("root")) continue; // protection
288
289       if (offset > 0)
290       {
291         --offset;
292         continue;
293       }
294
295       if (count++ == aRuns)
296         break;
297
298       // add esd file
299       chain->Add(esdfile);
300     }
301
302     in.close();
303   }
304
305   return chain;
306
307 } // end of TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
308
309 //===============================================================================================
310
311 TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
312 {
313   // creates chain of files in a given directory or file containing a list.
314   // In case of directory the structure is expected as:
315   // <aDataDir>/<dir0>/AliAOD.root
316   // <aDataDir>/<dir1>/AliAOD.root
317   // ...
318
319   if (!aDataDir)
320     return 0;
321
322   Long_t id, size, flags, modtime;
323   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
324   {
325     printf("%s not found.\n", aDataDir);
326     return 0;
327   }
328
329   TChain* chain = new TChain("aodTree");
330   TChain* chaingAlice = 0;
331
332   if (flags & 2)
333   {
334     TString execDir(gSystem->pwd());
335     TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
336     TList* dirList            = baseDir->GetListOfFiles();
337     Int_t nDirs               = dirList->GetEntries();
338     gSystem->cd(execDir);
339
340     Int_t count = 0;
341
342     for (Int_t iDir=0; iDir<nDirs; ++iDir)
343     {
344       TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
345       if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
346         continue;
347
348       if (offset > 0)
349       {
350         --offset;
351         continue;
352       }
353
354       if (count++ == aRuns)
355         break;
356
357       TString presentDirName(aDataDir);
358       presentDirName += "/";
359       presentDirName += presentDir->GetName();
360       chain->Add(presentDirName + "/AliAOD.root/aodTree");
361       // cerr<<presentDirName<<endl;
362     }
363
364   }
365   else
366   {
367     // Open the input stream
368     ifstream in;
369     in.open(aDataDir);
370
371     Int_t count = 0;
372
373     // Read the input list of files and add them to the chain
374     TString aodfile;
375     while(in.good())
376     {
377       in >> aodfile;
378       if (!aodfile.Contains("root")) continue; // protection
379
380       if (offset > 0)
381       {
382         --offset;
383         continue;
384       }
385
386       if (count++ == aRuns)
387         break;
388
389       // add aod file
390       chain->Add(aodfile);
391     }
392
393     in.close();
394   }
395
396   return chain;
397
398 } // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
399