]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/runFlowTask.C
reorganize ClearPackage, UploadPackage EnablePackage
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTask.C
1 enum anaModes {mLocal,mLocalPAR,mPROOF,mGRID};
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
6 // RUN SETTINGS
7
8 // Flow analysis method can be:(set to kTRUE or kFALSE)
9 Bool_t SP       = kTRUE;
10 Bool_t LYZ1SUM  = kTRUE;
11 Bool_t LYZ1PROD = kTRUE;
12 Bool_t LYZ2SUM  = kFALSE;
13 Bool_t LYZ2PROD = kFALSE;
14 Bool_t LYZEP    = kFALSE;
15 Bool_t GFC      = kTRUE;
16 Bool_t QC       = kTRUE;
17 Bool_t FQD      = kTRUE;
18 Bool_t MCEP     = kTRUE; //not for pp 
19
20 Bool_t METHODS[] = {SP,LYZ1SUM,LYZ1PROD,LYZ2SUM,LYZ2PROD,LYZEP,GFC,QC,FQD,MCEP};
21
22 // Analysis type can be ESD, AOD, MC, ESDMC0, ESDMC1
23 const TString type = "ESD";
24
25 // Boolean to fill/not fill the QA histograms
26 Bool_t QA = kTRUE;   
27
28 // Boolean to use/not use weights for the Q vector
29 Bool_t WEIGHTS[] = {kFALSE,kFALSE,kFALSE}; //Phi, v'(pt), v'(eta)
30
31
32 //void runFlowTask(Int_t mode=mLocal, Int_t nRuns = 100, 
33                  //const Char_t* dataDir="/data/alice2/kolk/PP/LHC09a4/81119", Int_t offset = 0)
34                  //const Char_t* dataDir="/data/alice2/kolk/Therminator_midcentral", Int_t offset = 0)
35                  //const Char_t* dataDir="/Users/snelling/alice_data/Therminator_midcentral", Int_t offset = 0)
36 void runFlowTask(Int_t mode=mPROOF, Int_t nRuns = 1000000, 
37                  //const Char_t* dataDir="/COMMON/COMMON/LHC09a14_0.9TeV_0.5T", Int_t offset = 0)
38                  //const Char_t* dataDir="/COMMON/COMMON/LHC08c11_10TeV_0.5T", Int_t offset = 0)
39                  //const Char_t* dataDir="/PWG2/akisiel/Therminator_midcentral_ESD", Int_t offset=0)
40                  const Char_t* dataDir="/COMMON/COMMON/LHC09a4_run8101X", Int_t offset = 0)
41
42
43 {
44   TStopwatch timer;
45   timer.Start();
46   
47   LoadLibraries(mode);
48   
49   if (mode==mLocal || mode == mLocalPAR || mode == mGRID) {
50     if (type!="AOD") { TChain* chain = CreateESDChain(dataDir, nRuns, offset);}
51     else { TChain* chain = CreateAODChain(dataDir, nRuns, offset);}
52   }
53   //____________________________________________//
54   // Make the analysis manager
55   AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
56   
57   if (type == "ESD"){
58     AliVEventHandler* esdH = new AliESDInputHandler;
59     mgr->SetInputEventHandler(esdH);
60     
61     AliMCEventHandler *mc = new AliMCEventHandler();
62     mgr->SetMCtruthEventHandler(mc); 
63   }
64   
65   if (type == "AOD"){
66     AliVEventHandler* aodH = new AliAODInputHandler;
67     mgr->SetInputEventHandler(aodH); 
68     
69     AliMCEventHandler *mc = new AliMCEventHandler();
70     mgr->SetMCtruthEventHandler(mc); 
71   }
72   
73   if (type == "MC" || type == "ESDMC0" || type == "ESDMC1"){
74     AliVEventHandler* esdH = new AliESDInputHandler;
75     mgr->SetInputEventHandler(esdH);
76     
77     AliMCEventHandler *mc = new AliMCEventHandler();
78     mgr->SetMCtruthEventHandler(mc); 
79   }
80   
81   
82   //____________________________________________//
83   // Load the tasks
84   gROOT->LoadMacro("AddTaskFlow.C");
85   AliAnalysisTaskFlowEvent* taskFE = AddTaskFlow(type,METHODS,QA,WEIGHTS);
86     
87   //____________________________________________//
88   // Run the analysis
89   if (!mgr->InitAnalysis()) return;
90   mgr->PrintStatus();
91   
92   if (mode==mLocal || mode == mLocalPAR) {
93     mgr->StartAnalysis("local",chain);
94   }
95   else if (mode==mPROOF) {
96     mgr->StartAnalysis("proof",dataDir,nRuns,offset);
97   }
98   else if (mode==mGRID) { 
99     mgr->StartAnalysis("local",chain);
100   }
101   
102   timer.Stop();
103   timer.Print();
104   
105 }
106
107
108 void LoadLibraries(const anaModes mode) {
109   
110   //--------------------------------------
111   // Load the needed libraries most of them already loaded by aliroot
112   //--------------------------------------
113   gSystem->Load("libTree.so");
114   gSystem->Load("libGeom.so");
115   gSystem->Load("libVMC.so");
116   gSystem->Load("libXMLIO.so");
117   gSystem->Load("libPhysics.so");
118   
119   //----------------------------------------------------------
120   // >>>>>>>>>>> Local mode <<<<<<<<<<<<<< 
121   //----------------------------------------------------------
122   if (mode==mLocal) {
123     //--------------------------------------------------------
124     // If you want to use already compiled libraries 
125     // in the aliroot distribution
126     //--------------------------------------------------------
127     gSystem->Load("libSTEERBase");
128     gSystem->Load("libESD");
129     gSystem->Load("libAOD");
130     gSystem->Load("libANALYSIS");
131     gSystem->Load("libANALYSISalice");
132     gSystem->Load("libCORRFW.so");
133     cerr<<"libCORRFW.so loaded..."<<endl;
134     gSystem->Load("libPWG2flowCommon.so");
135     cerr<<"libPWG2flowCommon.so loaded..."<<endl;
136     gSystem->Load("libPWG2flowTasks.so");
137     cerr<<"libPWG2flowTasks.so loaded..."<<endl;
138   }
139   
140   else if (mode == mLocalPAR || mode == mGRID) {
141     //--------------------------------------------------------
142     //If you want to use root and par files from aliroot
143     //--------------------------------------------------------  
144     SetupPar("STEERBase");
145     SetupPar("ESD");
146     SetupPar("AOD");
147     SetupPar("ANALYSIS");
148     SetupPar("ANALYSISalice");
149     SetupPar("PWG2AOD");
150     SetupPar("CORRFW");
151     SetupPar("PWG2flowCommon");
152     cerr<<"PWG2flowCommon.par loaded..."<<endl;
153     SetupPar("PWG2flowTasks");
154     cerr<<"PWG2flowTasks.par loaded..."<<endl;
155   }
156   
157   //---------------------------------------------------------
158   // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
159   //---------------------------------------------------------
160   else if (mode==mPROOF) {
161     //
162     
163     //  set to debug root versus if needed
164     //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a_dbg");
165     //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a");
166     
167     //TProof::Reset("proof://snelling@alicecaf.cern.ch");     
168     // Connect to proof
169     printf("*** Connect to PROOF ***\n");
170     // Put appropriate username here
171     //TProof::Open("abilandz@alicecaf.cern.ch");
172     //TProof::Open("nkolk@alicecaf.cern.ch");
173     TProof::Open("snelling@localhost");
174     // list the data available
175     //gProof->ShowDataSets("/*/*");  
176  
177     // Clear the Packages
178     gProof->ClearPackage("STEERBase.par");
179     gProof->ClearPackage("ESD.par");
180     gProof->ClearPackage("AOD.par");
181     gProof->ClearPackage("ANALYSIS.par");
182     gProof->ClearPackage("ANALYSISalice.par");
183     gProof->ClearPackage("PWG2AOD.par");
184     gProof->ClearPackage("CORRFW.par");
185     gProof->ClearPackage("PWG2flowCommon");
186     gProof->ClearPackage("PWG2flowTasks");
187
188
189     // Upload the Packages
190     gProof->UploadPackage("STEERBase.par");
191     gProof->UploadPackage("ESD.par");    
192     gProof->UploadPackage("AOD.par");
193     gProof->UploadPackage("ANALYSIS.par"); 
194     gProof->UploadPackage("ANALYSISalice.par");
195     gProof->UploadPackage("PWG2AOD.par");
196     gProof->UploadPackage("CORRFW.par");
197     gProof->UploadPackage("PWG2flowCommon.par");
198     gProof->UploadPackage("PWG2flowTasks.par");
199
200     // Enable the Packages
201     gProof->EnablePackage("STEERBase");
202     gProof->EnablePackage("ESD");
203     gProof->EnablePackage("AOD");
204     gProof->EnablePackage("ANALYSIS");
205     gProof->EnablePackage("ANALYSISalice");
206     gProof->EnablePackage("PWG2AOD");
207     gProof->EnablePackage("CORRFW");
208     gProof->EnablePackage("PWG2flowCommon");
209     gProof->EnablePackage("PWG2flowTasks");
210
211     // Show enables Packages
212     gProof->ShowEnabledPackages();
213   }  
214   
215 }
216
217 void SetupPar(char* pararchivename) {
218   //Load par files, create analysis libraries
219   //For testing, if par file already decompressed and modified
220   //classes then do not decompress.
221   
222   TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; 
223   TString parpar(Form("%s.par", pararchivename)) ; 
224   if ( gSystem->AccessPathName(parpar.Data()) ) {
225     gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
226     TString processline(Form(".! make %s", parpar.Data())) ; 
227     gROOT->ProcessLine(processline.Data()) ;
228     gSystem->ChangeDirectory(cdir) ; 
229     processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
230     gROOT->ProcessLine(processline.Data()) ;
231   } 
232   if ( gSystem->AccessPathName(pararchivename) ) {  
233     TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
234     gROOT->ProcessLine(processline.Data());
235   }
236   
237   TString ocwd = gSystem->WorkingDirectory();
238   gSystem->ChangeDirectory(pararchivename);
239   
240   // check for BUILD.sh and execute
241   if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
242     printf("*******************************\n");
243     printf("*** Building PAR archive    ***\n");
244     cout<<pararchivename<<endl;
245     printf("*******************************\n");
246     if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
247       Error("runProcess","Cannot Build the PAR Archive! - Abort!");
248       return -1;
249     }
250   }
251   // check for SETUP.C and execute
252   if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
253     printf("*******************************\n");
254     printf("*** Setup PAR archive       ***\n");
255     cout<<pararchivename<<endl;
256     printf("*******************************\n");
257     gROOT->Macro("PROOF-INF/SETUP.C");
258   }
259   
260   gSystem->ChangeDirectory(ocwd.Data());
261   printf("Current dir: %s\n", ocwd.Data());
262 }
263
264
265 // Helper macros for creating chains
266 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
267
268 TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
269 {
270   // creates chain of files in a given directory or file containing a list.
271   // In case of directory the structure is expected as:
272   // <aDataDir>/<dir0>/AliESDs.root
273   // <aDataDir>/<dir1>/AliESDs.root
274   // ...
275   
276   if (!aDataDir)
277     return 0;
278   
279   Long_t id, size, flags, modtime;
280   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
281     {
282       printf("%s not found.\n", aDataDir);
283       return 0;
284     }
285   
286   TChain* chain = new TChain("esdTree");
287   TChain* chaingAlice = 0;
288   
289   if (flags & 2)
290     {
291       TString execDir(gSystem->pwd());
292       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
293       TList* dirList            = baseDir->GetListOfFiles();
294       Int_t nDirs               = dirList->GetEntries();
295       gSystem->cd(execDir);
296       
297       Int_t count = 0;
298       
299       for (Int_t iDir=0; iDir<nDirs; ++iDir)
300         {
301           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
302           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
303             continue;
304           
305           if (offset > 0)
306             {
307               --offset;
308               continue;
309             }
310           
311           if (count++ == aRuns)
312             break;
313           
314           TString presentDirName(aDataDir);
315           presentDirName += "/";
316           presentDirName += presentDir->GetName();        
317           chain->Add(presentDirName + "/AliESDs.root/esdTree");
318           //  cerr<<presentDirName<<endl;
319         }
320       
321     }
322   else
323     {
324       // Open the input stream
325       ifstream in;
326       in.open(aDataDir);
327       
328       Int_t count = 0;
329       
330       // Read the input list of files and add them to the chain
331       TString esdfile;
332       while(in.good()) {
333         in >> esdfile;
334         if (!esdfile.Contains("root")) continue; // protection
335         
336         if (offset > 0)
337           {
338             --offset;
339             continue;
340           }
341         
342         if (count++ == aRuns)
343           break;
344         
345         // add esd file
346         chain->Add(esdfile);
347       }
348       
349       in.close();
350     }
351   
352   return chain;
353 }
354
355
356 // Helper macros for creating chains
357 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
358
359 TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
360 {
361   // creates chain of files in a given directory or file containing a list.
362   // In case of directory the structure is expected as:
363   // <aDataDir>/<dir0>/AliAOD.root
364   // <aDataDir>/<dir1>/AliAOD.root
365   // ...
366   
367   if (!aDataDir)
368     return 0;
369   
370   Long_t id, size, flags, modtime;
371   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
372     {
373       printf("%s not found.\n", aDataDir);
374       return 0;
375     }
376   
377   TChain* chain = new TChain("aodTree");
378   TChain* chaingAlice = 0;
379   
380   if (flags & 2)
381     {
382       TString execDir(gSystem->pwd());
383       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
384       TList* dirList            = baseDir->GetListOfFiles();
385       Int_t nDirs               = dirList->GetEntries();
386       gSystem->cd(execDir);
387       
388       Int_t count = 0;
389       
390       for (Int_t iDir=0; iDir<nDirs; ++iDir)
391         {
392           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
393           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
394             continue;
395           
396           if (offset > 0)
397             {
398               --offset;
399               continue;
400             }
401           
402           if (count++ == aRuns)
403             break;
404           
405           TString presentDirName(aDataDir);
406           presentDirName += "/";
407           presentDirName += presentDir->GetName();        
408           chain->Add(presentDirName + "/AliAOD.root/aodTree");
409           // cerr<<presentDirName<<endl;
410         }
411       
412     }
413   else
414     {
415       // Open the input stream
416       ifstream in;
417       in.open(aDataDir);
418       
419       Int_t count = 0;
420       
421       // Read the input list of files and add them to the chain
422       TString aodfile;
423       while(in.good()) {
424         in >> aodfile;
425         if (!aodfile.Contains("root")) continue; // protection
426         
427         if (offset > 0)
428           {
429             --offset;
430             continue;
431           }
432         
433         if (count++ == aRuns)
434           break;
435         
436         // add aod file
437         chain->Add(aodfile);
438       }
439       
440       in.close();
441     }
442   
443   return chain;
444 }
445