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