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