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