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