]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/FLOW/macros/runTaskFlowOnMC.C
Merge branch 'master' of http://git.cern.ch/pub/AliRoot
[u/mrichter/AliRoot.git] / PWGCF / FLOW / macros / runTaskFlowOnMC.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 = 1;  //where do we start numbering bins
11 //Int_t binlast = 2;  //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 = "output"; // e.g.: result for centrality bin 0 will be in the file "outputCentrality0.root", etc
17
18 void runTaskFlowOnMC(Int_t harmonic = 2,
19                      Double_t gImpactParameterMin = 0.0,
20                      Double_t gImpactParameterMax = 100.0,
21                      Int_t gRefMultMin = 0,
22                      Int_t gRefMultMax = 100,
23                      Double_t etaMax = 1.3,
24                      Double_t ptMin = 0.05,
25                      Double_t ptMax = 20.0,
26                      Int_t chargePOI = 0,
27                      Int_t mode = mLocal, 
28                      Bool_t useFlowParFiles = kFALSE,
29                      Bool_t useTender = kFALSE) {
30   // Time:
31   TStopwatch timer;
32   timer.Start();
33
34   // Load needed libraries:
35   LoadLibraries(mode,useFlowParFiles);
36   
37   //Fix the filename
38   commonOutputFileName += ".etaMax.";
39   commonOutputFileName += etaMax;
40   commonOutputFileName += ".harmonics.";
41   commonOutputFileName += harmonic;
42
43   // Create analysis manager:
44   AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
45
46   // Chains:
47   if(mode == mLocal) {
48     TChain *chain = new TChain("TE");
49     chain->Add("galice.root");
50   }
51
52   // Connect plug-in to the analysis manager:
53   if(mode == mGrid) {
54     gROOT->LoadMacro("CreateAlienHandler.C");
55     AliAnalysisGrid *alienHandler = CreateAlienHandler();
56     if(!alienHandler) return;
57     mgr->SetGridHandler(alienHandler);
58   }
59
60   // Event handlers:
61   AliVEventHandler* esdH = new AliESDInputHandler;
62   mgr->SetInputEventHandler(esdH);
63   AliMCEventHandler *mc = new AliMCEventHandler();
64   mc->SetReadTR(kFALSE);
65   mgr->SetMCtruthEventHandler(mc);
66   
67   if (useTender) {
68     //Add the tenders
69     gROOT->LoadMacro("$ALICE_ROOT/PWG2/FLOW/macros/AddTaskTenderFlow.C");
70     AddTaskTenderFlow();
71   }
72
73   // Setup analysis per centrality bin:
74   gROOT->LoadMacro("AddTaskFlowOnMC.C");
75   AddTaskFlowOnMC(commonOutputFileName,
76                   etaMax,
77                   ptMin,
78                   ptMax,
79                   chargePOI,
80                   harmonic,
81                   gImpactParameterMin,
82                   gImpactParameterMax,
83                   gRefMultMin,
84                   gRefMultMax);
85
86   // Enable debug printouts:
87   mgr->SetDebugLevel(2);
88   // Run the analysis:
89   if(!mgr->InitAnalysis()) return;
90   mgr->PrintStatus();
91   if(mode == mLocal) {
92     mgr->StartAnalysis("local",chain);
93   }
94   else if(mode == mPROOF) {
95     mgr->StartAnalysis("proof",dataDir,nEvents,offset);
96   }
97   else if(mode == mGrid) {
98     mgr->StartAnalysis("grid");
99   }
100
101   // Print real and CPU time used for analysis:
102   timer.Stop();
103   timer.Print();
104
105 } // end of void runTaskFlowOnMC(...)
106
107 //===============================================================================================
108 /*
109 void CrossCheckUserSettings(Bool_t bData)
110 {
111  // Check in this method if the user settings make sense.
112  if(LYZ1SUM && LYZ2SUM) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
113  if(LYZ1PROD && LYZ2PROD) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
114  if(LYZ2SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
115  if(LYZ1SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
116 } // end of void CrossCheckUserSettings()
117 */
118 //===============================================================================================
119
120 void LoadLibraries(const anaModes mode, Bool_t useFlowParFiles ) {
121   //--------------------------------------
122   // Load the needed libraries most of them already loaded by aliroot
123   //--------------------------------------
124
125   gSystem->Load("libCore");
126   gSystem->Load("libTree");
127   gSystem->Load("libGeom");
128   gSystem->Load("libVMC");
129   gSystem->Load("libXMLIO");
130   gSystem->Load("libPhysics");
131   gSystem->Load("libXMLParser");
132   gSystem->Load("libProof");
133   gSystem->Load("libMinuit");
134
135   if (mode==mLocal || mode==mGrid)
136   {
137     gSystem->Load("libSTEERBase");
138     gSystem->Load("libCDB");
139     gSystem->Load("libRAWDatabase");
140     gSystem->Load("libRAWDatarec");
141     gSystem->Load("libESD");
142     gSystem->Load("libAOD");
143     gSystem->Load("libSTEER");
144     gSystem->Load("libANALYSIS");
145     gSystem->Load("libANALYSISalice");
146     gSystem->Load("libTPCbase");
147     gSystem->Load("libTOFbase");
148     gSystem->Load("libTOFsim");
149     gSystem->Load("libTOFrec");
150     gSystem->Load("libTRDbase");
151     gSystem->Load("libVZERObase");
152     gSystem->Load("libVZEROrec");
153     gSystem->Load("libT0base");
154     gSystem->Load("libT0rec");
155     gSystem->Load("libTENDER");
156     gSystem->Load("libTENDERSupplies");
157
158     if (useFlowParFiles)
159     {
160       AliAnalysisAlien::SetupPar("PWGflowBase");
161       AliAnalysisAlien::SetupPar("PWGflowTasks");
162     }
163     else
164     {
165       gSystem->Load("libPWGflowBase");
166       gSystem->Load("libPWGflowTasks");
167     }
168   }
169   else if (mode==mPROOF)
170   {
171     TList* list = new TList();
172     list->Add(new TNamed("ALIROOT_MODE", "ALIROOT"));
173     if (useFlowParFiles)
174       list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "ANALYSIS:ANALYSISalice:TENDER:TENDERSupplies"));
175     else
176       list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "ANALYSIS:ANALYSISalice:TENDER:TENDERSupplies:PWG2flowCommon:PWG2flowTasks"));
177
178     //list->Add(new TNamed("ALIROOT_EXTRA_INCLUDES","PWG2/FLOW/AliFlowCommon:PWG2/FLOW/AliFlowTasks"));
179
180     // Connect to proof
181     printf("*** Connect to PROOF ***\n");
182     gEnv->SetValue("XSec.GSI.DelegProxy","2");
183     //TProof* proof = TProof::Open("alice-caf.cern.ch");
184     TProof* proof = TProof::Open("skaf.saske.sk");
185
186     // list the data available
187     //gProof->ShowDataSets("/*/*");
188     //gProof->ShowDataSets("/alice/sim/"); //for MC Data
189     //gProof->ShowDataSets("/alice/data/"); //for REAL Data
190
191     proof->ClearPackages();
192     proof->EnablePackage("VO_ALICE@AliRoot::v4-21-14-AN",list);
193
194     if (useFlowParFiles)
195     {
196       gProof->UploadPackage("PWG2flowCommon.par");
197       gProof->UploadPackage("PWG2flowTasks.par");
198     }
199
200     // Show enables Packages
201     gProof->ShowEnabledPackages();
202   }
203 } // end of void LoadLibraries(const anaModes mode)
204
205 // Helper macros for creating chains
206 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
207 TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
208 {
209   // creates chain of files in a given directory or file containing a list.
210   // In case of directory the structure is expected as:
211   // <aDataDir>/<dir0>/AliESDs.root
212   // <aDataDir>/<dir1>/AliESDs.root
213   // ...
214
215   if (!aDataDir)
216     return 0;
217
218   Long_t id, size, flags, modtime;
219   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
220   {
221     printf("%s not found.\n", aDataDir);
222     return 0;
223   }
224
225   TChain* chain = new TChain("esdTree");
226   TChain* chaingAlice = 0;
227
228   if (flags & 2)
229   {
230     TString execDir(gSystem->pwd());
231     TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
232     TList* dirList            = baseDir->GetListOfFiles();
233     Int_t nDirs               = dirList->GetEntries();
234     gSystem->cd(execDir);
235
236     Int_t count = 0;
237
238     for (Int_t iDir=0; iDir<nDirs; ++iDir)
239     {
240       TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
241       if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
242         continue;
243
244       if (offset > 0)
245       {
246         --offset;
247         continue;
248       }
249
250       if (count++ == aRuns)
251         break;
252
253       TString presentDirName(aDataDir);
254       presentDirName += "/";
255       presentDirName += presentDir->GetName();
256       chain->Add(presentDirName + "/AliESDs.root/esdTree");
257       //  cerr<<presentDirName<<endl;
258     }
259
260   }
261   else
262   {
263     // Open the input stream
264     ifstream in;
265     in.open(aDataDir);
266
267     Int_t count = 0;
268
269     // Read the input list of files and add them to the chain
270     TString esdfile;
271     while(in.good())
272     {
273       in >> esdfile;
274       if (!esdfile.Contains("root")) continue; // protection
275
276       if (offset > 0)
277       {
278         --offset;
279         continue;
280       }
281
282       if (count++ == aRuns)
283         break;
284
285       // add esd file
286       chain->Add(esdfile);
287     }
288
289     in.close();
290   }
291
292   return chain;
293
294 } // end of TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
295
296 //===============================================================================================
297
298 TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
299 {
300   // creates chain of files in a given directory or file containing a list.
301   // In case of directory the structure is expected as:
302   // <aDataDir>/<dir0>/AliAOD.root
303   // <aDataDir>/<dir1>/AliAOD.root
304   // ...
305
306   if (!aDataDir)
307     return 0;
308
309   Long_t id, size, flags, modtime;
310   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
311   {
312     printf("%s not found.\n", aDataDir);
313     return 0;
314   }
315
316   TChain* chain = new TChain("aodTree");
317   TChain* chaingAlice = 0;
318
319   if (flags & 2)
320   {
321     TString execDir(gSystem->pwd());
322     TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
323     TList* dirList            = baseDir->GetListOfFiles();
324     Int_t nDirs               = dirList->GetEntries();
325     gSystem->cd(execDir);
326
327     Int_t count = 0;
328
329     for (Int_t iDir=0; iDir<nDirs; ++iDir)
330     {
331       TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
332       if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
333         continue;
334
335       if (offset > 0)
336       {
337         --offset;
338         continue;
339       }
340
341       if (count++ == aRuns)
342         break;
343
344       TString presentDirName(aDataDir);
345       presentDirName += "/";
346       presentDirName += presentDir->GetName();
347       chain->Add(presentDirName + "/AliAOD.root/aodTree");
348       // cerr<<presentDirName<<endl;
349     }
350
351   }
352   else
353   {
354     // Open the input stream
355     ifstream in;
356     in.open(aDataDir);
357
358     Int_t count = 0;
359
360     // Read the input list of files and add them to the chain
361     TString aodfile;
362     while(in.good())
363     {
364       in >> aodfile;
365       if (!aodfile.Contains("root")) continue; // protection
366
367       if (offset > 0)
368       {
369         --offset;
370         continue;
371       }
372
373       if (count++ == aRuns)
374         break;
375
376       // add aod file
377       chain->Add(aodfile);
378     }
379
380     in.close();
381   }
382
383   return chain;
384
385 } // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
386