]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGCF/EBYE/macros/runBalancePsiEfficiencyTaskCentralityTrain.C
Merge branch 'workdir'
[u/mrichter/AliRoot.git] / PWGCF / EBYE / macros / runBalancePsiEfficiencyTaskCentralityTrain.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 = 7;  //where do we stop numbering bins
14 const Int_t numberOfCentralityBins = 8;
15 Double_t centralityArray[numberOfCentralityBins+1] = {0.,10.,20.,30.,40.,50.,60.,70.,80.}; // in centrality percentile
16 Bool_t kUsePID = kFALSE;
17 const TString  centralityEstimator = "V0M";
18 Double_t vertexZ = 10.;
19
20 //output file
21 TString commonOutputFileName = "outputEfficiency";
22
23 //void runEfficiencyTaskCentralityTrain(Int_t mode = mPROOF, 
24 //Int_t nRuns = 600000, 
25 //Bool_t DATA = kFALSE, 
26 //const Char_t* dataDir="/alice/data/LHC10h_000137161_p1_4plus#esdTree", Int_t offset=0) {
27 void runBalancePsiEfficiencyTaskCentralityTrain(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("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set1/AliESDs.root");
49     chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set2/AliESDs.root");
50     chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set3/AliESDs.root");
51     chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set4/AliESDs.root");
52     chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set5/AliESDs.root");
53     chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set6/AliESDs.root");
54     chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set7/AliESDs.root");
55     chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set8/AliESDs.root");
56     chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set9/AliESDs.root");
57     chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/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("bfPsiCorrectionManager");
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/ANALYSIS/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/ANALYSIS/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("$ALICE_ROOT/PWGCF/EBYE/macros/AddTaskBalancePsiEfficiency.C");
101   
102   for (Int_t i=binfirst; i<binlast+1; i++) {
103     //for (Int_t i = 0; i < 9; i++) {
104     Double_t lowCentralityBinEdge = centralityArray[i];
105     Double_t highCentralityBinEdge = centralityArray[i+1];
106     Printf("\nWagon for centrality bin %i: %.0f-%.0f",i,lowCentralityBinEdge,highCentralityBinEdge);
107     AddTaskBalancePsiEfficiency(centralityEstimator.Data(), lowCentralityBinEdge, highCentralityBinEdge, vertexZ, commonOutputFileName.Data());
108   } // end of for (Int_t i=0; i<numberOfCentralityBins; i++)
109
110   // Run the analysis:
111   if(!mgr->InitAnalysis()){return;}
112   mgr->PrintStatus(); 
113   if(mode == mLocal || mode == mLocalPAR) 
114     mgr->StartAnalysis("local",chain);
115   else if(mode == mPROOF) 
116     mgr->StartAnalysis("proof",dataDir,nRuns,offset);
117   else if(mode == mGrid || mode == mGridPAR) 
118     mgr->StartAnalysis("grid");
119
120   // Print real and CPU time used for analysis:  
121   timer.Stop();
122   timer.Print();
123   
124 } // end of void runTaskFluctuations(...)
125
126 //=============================================================//
127 void LoadLibraries(const anaModes mode) {  
128   //--------------------------------------
129   // Load the needed libraries most of them already loaded by aliroot
130   //--------------------------------------
131   gSystem->Load("libTree");
132   gSystem->Load("libGeom");
133   gSystem->Load("libVMC");
134   gSystem->Load("libXMLIO");
135   gSystem->Load("libPhysics");
136   
137   //----------------------------------------------------------
138   // >>>>>>>>>>> Local mode <<<<<<<<<<<<<< 
139   //----------------------------------------------------------
140   if (mode==mLocal || mode==mGrid || mode == mGridPAR) {
141     //--------------------------------------------------------
142     // If you want to use already compiled libraries 
143     // in the aliroot distribution
144     //--------------------------------------------------------
145     gSystem->Load("libSTEERBase");
146     gSystem->Load("libESD");
147     gSystem->Load("libAOD");
148     gSystem->Load("libANALYSIS");
149     gSystem->Load("libANALYSISalice");
150     gSystem->Load("libEventMixing.so");
151     gSystem->Load("libCORRFW.so");
152     gSystem->Load("libPWGTools.so");
153     gSystem->Load("libPWGCFebye.so");
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::v4-21-12-AN");
183  
184     TString extraLibs = "";
185     extraLibs += "CORRFW:PWGTools";
186
187     TList *list = new TList();
188     list->Add(new TNamed("ALIROOT_EXTRA_LIBS",extraLibs.Data()));
189
190     gProof->EnablePackage("VO_ALICE@AliRoot::v5-03-46-AN",list);
191   }  
192   
193 } // end of void LoadLibraries(const anaModes mode)
194
195 //===============================================================================================
196
197 void SetupPar(char* pararchivename) {
198   //Load par files, create analysis libraries
199   //For testing, if par file already decompressed and modified
200   //classes then do not decompress.
201   
202   TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; 
203   TString parpar(Form("%s.par", pararchivename)) ; 
204   if ( gSystem->AccessPathName(parpar.Data()) ) {
205     gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
206     TString processline(Form(".! make %s", parpar.Data())) ; 
207     gROOT->ProcessLine(processline.Data()) ;
208     gSystem->ChangeDirectory(cdir) ; 
209     processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
210     gROOT->ProcessLine(processline.Data()) ;
211   } 
212   if ( gSystem->AccessPathName(pararchivename) ) {  
213     TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
214     gROOT->ProcessLine(processline.Data());
215   }
216   
217   TString ocwd = gSystem->WorkingDirectory();
218   gSystem->ChangeDirectory(pararchivename);
219   
220   // check for BUILD.sh and execute
221   if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
222     printf("*******************************\n");
223     printf("*** Building PAR archive    ***\n");
224     cout<<pararchivename<<endl;
225     printf("*******************************\n");
226     if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
227       Error("runProcess","Cannot Build the PAR Archive! - Abort!");
228       return -1;
229     }
230   }
231   // check for SETUP.C and execute
232   if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
233     printf("*******************************\n");
234     printf("*** Setup PAR archive       ***\n");
235     cout<<pararchivename<<endl;
236     printf("*******************************\n");
237     gROOT->Macro("PROOF-INF/SETUP.C");
238   }
239   
240   gSystem->ChangeDirectory(ocwd.Data());
241   printf("Current dir: %s\n", ocwd.Data());
242
243 } // end of void SetupPar(char* pararchivename) 
244
245 //===============================================================================================
246
247 // Helper macros for creating chains
248 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
249
250 TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
251 {
252   // creates chain of files in a given directory or file containing a list.
253   // In case of directory the structure is expected as:
254   // <aDataDir>/<dir0>/AliESDs.root
255   // <aDataDir>/<dir1>/AliESDs.root
256   // ...
257   
258   if (!aDataDir)
259     return 0;
260   
261   Long_t id, size, flags, modtime;
262   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
263     {
264       printf("%s not found.\n", aDataDir);
265       return 0;
266     }
267   
268   TChain* chain = new TChain("esdTree");
269   TChain* chaingAlice = 0;
270   
271   if (flags & 2)
272     {
273       TString execDir(gSystem->pwd());
274       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
275       TList* dirList            = baseDir->GetListOfFiles();
276       Int_t nDirs               = dirList->GetEntries();
277       gSystem->cd(execDir);
278       
279       Int_t count = 0;
280       
281       for (Int_t iDir=0; iDir<nDirs; ++iDir)
282         {
283           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
284           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
285             continue;
286           
287           if (offset > 0)
288             {
289               --offset;
290               continue;
291             }
292           
293           if (count++ == aRuns)
294             break;
295           
296           TString presentDirName(aDataDir);
297           presentDirName += "/";
298           presentDirName += presentDir->GetName();        
299           chain->Add(presentDirName + "/AliESDs.root/esdTree");
300           //  cerr<<presentDirName<<endl;
301         }
302       
303     }
304   else
305     {
306       // Open the input stream
307       ifstream in;
308       in.open(aDataDir);
309       
310       Int_t count = 0;
311       
312       // Read the input list of files and add them to the chain
313       TString esdfile;
314       while(in.good()) {
315         in >> esdfile;
316         if (!esdfile.Contains("root")) continue; // protection
317         
318         if (offset > 0)
319           {
320             --offset;
321             continue;
322           }
323         
324         if (count++ == aRuns)
325           break;
326         
327         // add esd file
328         chain->Add(esdfile);
329       }
330       
331       in.close();
332     }
333   
334   return chain;
335
336 } // end of TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
337
338 //===============================================================================================
339
340 TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
341 {
342   // creates chain of files in a given directory or file containing a list.
343   // In case of directory the structure is expected as:
344   // <aDataDir>/<dir0>/AliAOD.root
345   // <aDataDir>/<dir1>/AliAOD.root
346   // ...
347   
348   if (!aDataDir)
349     return 0;
350   
351   Long_t id, size, flags, modtime;
352   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
353     {
354       printf("%s not found.\n", aDataDir);
355       return 0;
356     }
357   
358   TChain* chain = new TChain("aodTree");
359   TChain* chaingAlice = 0;
360   
361   if (flags & 2)
362     {
363       TString execDir(gSystem->pwd());
364       TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
365       TList* dirList            = baseDir->GetListOfFiles();
366       Int_t nDirs               = dirList->GetEntries();
367       gSystem->cd(execDir);
368       
369       Int_t count = 0;
370       
371       for (Int_t iDir=0; iDir<nDirs; ++iDir)
372         {
373           TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
374           if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
375             continue;
376           
377           if (offset > 0)
378             {
379               --offset;
380               continue;
381             }
382           
383           if (count++ == aRuns)
384             break;
385           
386           TString presentDirName(aDataDir);
387           presentDirName += "/";
388           presentDirName += presentDir->GetName();        
389           chain->Add(presentDirName + "/AliAOD.root/aodTree");
390           // cerr<<presentDirName<<endl;
391         }
392       
393     }
394   else
395     {
396       // Open the input stream
397       ifstream in;
398       in.open(aDataDir);
399       
400       Int_t count = 0;
401       
402       // Read the input list of files and add them to the chain
403       TString aodfile;
404       while(in.good()) {
405         in >> aodfile;
406         if (!aodfile.Contains("root")) continue; // protection
407         
408         if (offset > 0)
409           {
410             --offset;
411             continue;
412           }
413         
414         if (count++ == aRuns)
415           break;
416         
417         // add aod file
418         chain->Add(aodfile);
419       }
420       
421       in.close();
422     }
423   
424   return chain;
425
426 } // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
427