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