]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/EBYE/macros/runTaskFluctuations.C
Minor updates
[u/mrichter/AliRoot.git] / PWG2 / EBYE / macros / runTaskFluctuations.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 //mGridPAR: Analyze files on Grid via AliEn plug-in and using par files for FLOW package
7
8
9 const TString analysisType = "ESD"; //"MC", "ESD", "AOD"
10 const TString analysisMode = "TPC"; //"TPC", "Global"
11
12 //void runTaskFluctuations(Int_t mode = mPROOF, Int_t nRuns = 600000, 
13 //Bool_t DATA = kTRUE, const Char_t* dataDir="/alice/data/LHC10h_000137161_p1_4plus#esdTree", Int_t offset=0) {
14 //void runTaskFluctuations(Int_t mode = mLocal, Bool_t DATA = kTRUE) {
15 //void runTaskFluctuations(Int_t mode = mGrid, Bool_t DATA = kTRUE) {
16 //void runTaskFluctuations(Int_t mode = mGridPAR, Bool_t DATA = kTRUE) {
17 void runTaskFluctuations(Int_t mode = mLocalPAR, Bool_t DATA = kTRUE) {
18   // Time:
19   TStopwatch timer;
20   timer.Start();
21   
22   // Load needed libraries:
23   LoadLibraries(mode);
24   
25   // Create and configure the AliEn plug-in:
26   if(mode == mGrid || mode == mGridPAR) {
27     gROOT->LoadMacro("CreateAlienHandler.C");
28     AliAnalysisGrid *alienHandler = CreateAlienHandler();  
29     if (!alienHandler) return;
30     //gROOT->LoadMacro("AliEbyEFluctuationAnalysisTask.cxx++");
31   }
32   // Chains:   
33   if(mode==mLocal || mode == mLocalPAR) {
34     //gROOT->LoadMacro("AliEbyEFluctuationAnalysisTask.cxx++");
35     if (analysisType!="AOD") { 
36       TChain* chain = new TChain("esdTree");
37       chain->Add("/home/pchrist/ALICE/HeavyIons/Data/137161/pass1_4plus/Set1/AliESDs.root");
38       chain->Add("/home/pchrist/ALICE/HeavyIons/Data/137161/pass1_4plus/Set2/AliESDs.root");
39       chain->Add("/home/pchrist/ALICE/HeavyIons/Data/137161/pass1_4plus/Set3/AliESDs.root");
40     }
41     else  
42       TChain* chain = CreateAODChain(dataDir, nRuns, offset);
43   }
44   //Proof
45   if(mode == mPROOF) {
46     gROOT->ProcessLine(Form(".include %s/include", gSystem->ExpandPathName("$ALICE_ROOT")));
47     //gProof->Load("AliEbyEFluctuationAnalysisTask.cxx++");
48   }
49
50   // Create analysis manager:
51   AliAnalysisManager *mgr = new AliAnalysisManager("FluctuationsAnalysisManager");
52   // Connect plug-in to the analysis manager:
53   if(mode == mGrid || mode == mGridPAR) { 
54     mgr->SetGridHandler(alienHandler);
55   }
56   // Event handlers:
57   if(analysisType == "ESD") {
58     AliVEventHandler* esdH = new AliESDInputHandler;
59     mgr->SetInputEventHandler(esdH);
60   } // end of if(analysisType == "ESD")  
61   if(analysisType == "AOD") {
62     AliVEventHandler* aodH = new AliAODInputHandler;
63     mgr->SetInputEventHandler(aodH); 
64   } // end of if(analysisType == "AOD")  
65   if(analysisType == "MC") {
66     AliVEventHandler* esdH = new AliESDInputHandler;
67     mgr->SetInputEventHandler(esdH); 
68     AliMCEventHandler *mc = new AliMCEventHandler();
69     mgr->SetMCtruthEventHandler(mc); 
70   } // end of  if(analysisType == "MC")
71   
72   // Load the analysis task:
73   gROOT->LoadMacro("AddTaskFluctuations.C");
74   AliEbyEFluctuationAnalysisTask* taskFA = AddTaskFluctuations(analysisType.Data(),
75                                                                analysisMode.Data());
76   
77   // Task to check the offline trigger:
78   //if(mode == mLocal || mode == mGrid || mode == mGridPAR)
79   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); 
80   AliPhysicsSelectionTask* physicsSelTask = AddTaskPhysicsSelection();
81   if(!DATA){physicsSelTask->GetPhysicsSelection()->SetAnalyzeMC();}
82   // Enable debug printouts:
83   mgr->SetDebugLevel(2);
84   
85   //Add the centrality determination task
86   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
87   AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
88   taskCentrality->SelectCollisionCandidates(AliVEvent::kMB);
89
90   // Run the analysis:
91   if(!mgr->InitAnalysis()){return;}
92   mgr->PrintStatus(); 
93   if(mode == mLocal || mode == mLocalPAR) 
94     //mgr->StartAnalysis("local",chain);
95   else if(mode == mPROOF) 
96     mgr->StartAnalysis("proof",dataDir,nRuns,offset);
97   else if(mode == mGrid || mode == mGridPAR) 
98     //mgr->StartAnalysis("grid");
99
100   // Print real and CPU time used for analysis:  
101   timer.Stop();
102   timer.Print();
103   
104 } // end of void runTaskFluctuations(...)
105
106 //=============================================================//
107 void LoadLibraries(const anaModes mode) {  
108   //--------------------------------------
109   // Load the needed libraries most of them already loaded by aliroot
110   //--------------------------------------
111   gSystem->Load("libTree");
112   gSystem->Load("libGeom");
113   gSystem->Load("libVMC");
114   gSystem->Load("libXMLIO");
115   gSystem->Load("libPhysics");
116   
117   //----------------------------------------------------------
118   // >>>>>>>>>>> Local mode <<<<<<<<<<<<<< 
119   //----------------------------------------------------------
120   if (mode==mLocal || mode==mGrid || mode == mGridPAR) {
121     //--------------------------------------------------------
122     // If you want to use already compiled libraries 
123     // in the aliroot distribution
124     //--------------------------------------------------------
125     gSystem->Load("libSTEERBase");
126     gSystem->Load("libESD");
127     gSystem->Load("libAOD");
128     gSystem->Load("libANALYSIS");
129     gSystem->Load("libANALYSISalice");
130     if(mode==mLocal || mode==mGrid)
131       gSystem->Load("libPWG2ebye");
132     if(mode==mGridPAR)
133       SetupPar("PWG2ebye");
134   }
135   
136   else if (mode == mLocalPAR) {
137     //--------------------------------------------------------
138     //If you want to use root and par files from aliroot
139     //--------------------------------------------------------  
140     gSystem->Load("libSTEERBase");
141     gSystem->Load("libESD");
142     gSystem->Load("libAOD");
143     gSystem->Load("libANALYSIS");
144     gSystem->Load("libANALYSISalice");
145     //SetupPar("STEERBase");
146     //SetupPar("ESD");
147     //SetupPar("AOD");
148     //SetupPar("ANALYSIS");
149     //SetupPar("ANALYSISalice");
150     SetupPar("PWG2ebye");
151 }
152   
153   //---------------------------------------------------------
154   // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
155   //---------------------------------------------------------
156   else if (mode==mPROOF) {
157     // Connect to proof
158     printf("*** Connect to PROOF ***\n");
159     gEnv->SetValue("XSec.GSI.DelegProxy","2");
160     // Put appropriate username here
161     TProof::Open("alice-caf.cern.ch");
162     //TProof::Open("skaf.saske.sk");
163     //TProof::Open("prf000-iep-grid.saske.sk");
164
165     gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-12-AN");
166     gSystem->Load("libSTEERBase");
167     gSystem->Load("libESD");
168     gSystem->Load("libAOD");
169     gSystem->Load("libANALYSIS");
170     gSystem->Load("libANALYSISalice");
171
172     // Clear the Packages    
173     //gProof->ClearPackage("STEERBase.par");
174     //gProof->ClearPackage("ESD.par");
175     //gProof->ClearPackage("AOD.par");
176     //gProof->ClearPackage("ANALYSIS.par");
177     //gProof->ClearPackage("ANALYSISalice.par");    
178     //gProof->ClearPackage("PWG2ebye");
179     
180     // Upload the Packages
181     //gProof->UploadPackage("STEERBase.par");
182     //gProof->UploadPackage("ESD.par");    
183     //gProof->UploadPackage("AOD.par");       
184     //gProof->UploadPackage("ANALYSIS.par"); 
185     //gProof->UploadPackage("ANALYSISalice.par");
186     //gProof->UploadPackage("CORRFW.par");
187     gProof->UploadPackage("PWG2ebye.par");
188
189     // Enable the Packages 
190     //gProof->EnablePackage("STEERBase");
191     //gProof->EnablePackage("ESD");
192     //gProof->EnablePackage("AOD");
193     //gProof->EnablePackage("ANALYSIS");
194     //gProof->EnablePackage("ANALYSISalice");
195     gProof->EnablePackage("PWG2ebye");
196
197     // Show enables Packages
198     //gProof->ShowEnabledPackages();
199   }  
200   
201 } // end of void LoadLibraries(const anaModes mode)
202
203 //===============================================================================================
204
205 void SetupPar(char* pararchivename) {
206   //Load par files, create analysis libraries
207   //For testing, if par file already decompressed and modified
208   //classes then do not decompress.
209   
210   TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; 
211   TString parpar(Form("%s.par", pararchivename)) ; 
212   if ( gSystem->AccessPathName(parpar.Data()) ) {
213     gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
214     TString processline(Form(".! make %s", parpar.Data())) ; 
215     gROOT->ProcessLine(processline.Data()) ;
216     gSystem->ChangeDirectory(cdir) ; 
217     processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
218     gROOT->ProcessLine(processline.Data()) ;
219   } 
220   if ( gSystem->AccessPathName(pararchivename) ) {  
221     TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
222     gROOT->ProcessLine(processline.Data());
223   }
224   
225   TString ocwd = gSystem->WorkingDirectory();
226   gSystem->ChangeDirectory(pararchivename);
227   
228   // check for BUILD.sh and execute
229   if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
230     printf("*******************************\n");
231     printf("*** Building PAR archive    ***\n");
232     cout<<pararchivename<<endl;
233     printf("*******************************\n");
234     if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
235       Error("runProcess","Cannot Build the PAR Archive! - Abort!");
236       return -1;
237     }
238   }
239   // check for SETUP.C and execute
240   if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
241     printf("*******************************\n");
242     printf("*** Setup PAR archive       ***\n");
243     cout<<pararchivename<<endl;
244     printf("*******************************\n");
245     gROOT->Macro("PROOF-INF/SETUP.C");
246   }
247   
248   gSystem->ChangeDirectory(ocwd.Data());
249   printf("Current dir: %s\n", ocwd.Data());
250
251 } // end of void SetupPar(char* pararchivename) 
252
253 //===============================================================================================
254
255 // Helper macros for creating chains
256 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
257
258 TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
259 {
260   // creates chain of files in a given directory or file containing a list.
261   // In case of directory the structure is expected as:
262   // <aDataDir>/<dir0>/AliESDs.root
263   // <aDataDir>/<dir1>/AliESDs.root
264   // ...
265   
266   if (!aDataDir)
267     return 0;
268   
269   Long_t id, size, flags, modtime;
270   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
271     {
272       printf("%s not found.\n", aDataDir);
273       return 0;
274     }
275   
276   TChain* chain = new TChain("esdTree");
277   TChain* chaingAlice = 0;
278   
279   if (flags & 2)
280     {
281       TString execDir(gSystem->pwd());
282       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
283       TList* dirList            = baseDir->GetListOfFiles();
284       Int_t nDirs               = dirList->GetEntries();
285       gSystem->cd(execDir);
286       
287       Int_t count = 0;
288       
289       for (Int_t iDir=0; iDir<nDirs; ++iDir)
290         {
291           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
292           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
293             continue;
294           
295           if (offset > 0)
296             {
297               --offset;
298               continue;
299             }
300           
301           if (count++ == aRuns)
302             break;
303           
304           TString presentDirName(aDataDir);
305           presentDirName += "/";
306           presentDirName += presentDir->GetName();        
307           chain->Add(presentDirName + "/AliESDs.root/esdTree");
308           //  cerr<<presentDirName<<endl;
309         }
310       
311     }
312   else
313     {
314       // Open the input stream
315       ifstream in;
316       in.open(aDataDir);
317       
318       Int_t count = 0;
319       
320       // Read the input list of files and add them to the chain
321       TString esdfile;
322       while(in.good()) {
323         in >> esdfile;
324         if (!esdfile.Contains("root")) continue; // protection
325         
326         if (offset > 0)
327           {
328             --offset;
329             continue;
330           }
331         
332         if (count++ == aRuns)
333           break;
334         
335         // add esd file
336         chain->Add(esdfile);
337       }
338       
339       in.close();
340     }
341   
342   return chain;
343
344 } // end of TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
345
346 //===============================================================================================
347
348 TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
349 {
350   // creates chain of files in a given directory or file containing a list.
351   // In case of directory the structure is expected as:
352   // <aDataDir>/<dir0>/AliAOD.root
353   // <aDataDir>/<dir1>/AliAOD.root
354   // ...
355   
356   if (!aDataDir)
357     return 0;
358   
359   Long_t id, size, flags, modtime;
360   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
361     {
362       printf("%s not found.\n", aDataDir);
363       return 0;
364     }
365   
366   TChain* chain = new TChain("aodTree");
367   TChain* chaingAlice = 0;
368   
369   if (flags & 2)
370     {
371       TString execDir(gSystem->pwd());
372       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
373       TList* dirList            = baseDir->GetListOfFiles();
374       Int_t nDirs               = dirList->GetEntries();
375       gSystem->cd(execDir);
376       
377       Int_t count = 0;
378       
379       for (Int_t iDir=0; iDir<nDirs; ++iDir)
380         {
381           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
382           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
383             continue;
384           
385           if (offset > 0)
386             {
387               --offset;
388               continue;
389             }
390           
391           if (count++ == aRuns)
392             break;
393           
394           TString presentDirName(aDataDir);
395           presentDirName += "/";
396           presentDirName += presentDir->GetName();        
397           chain->Add(presentDirName + "/AliAOD.root/aodTree");
398           // cerr<<presentDirName<<endl;
399         }
400       
401     }
402   else
403     {
404       // Open the input stream
405       ifstream in;
406       in.open(aDataDir);
407       
408       Int_t count = 0;
409       
410       // Read the input list of files and add them to the chain
411       TString aodfile;
412       while(in.good()) {
413         in >> aodfile;
414         if (!aodfile.Contains("root")) continue; // protection
415         
416         if (offset > 0)
417           {
418             --offset;
419             continue;
420           }
421         
422         if (count++ == aRuns)
423           break;
424         
425         // add aod file
426         chain->Add(aodfile);
427       }
428       
429       in.close();
430     }
431   
432   return chain;
433
434 } // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
435