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