]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/runFlowTaskCentralityPIDTrain.C
added pid example macros and QA task for the PMD
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTaskCentralityPIDTrain.C
1 enum anaModes {mLocal,mPROOF,mGrid};
2 //mLocal: Analyze locally files in your computer using aliroot
3 //mPROOF: Analyze CAF files with PROOF
4 //mGrid: Analyze files on Grid via AliEn plug-in and using precompiled FLOW libraries
5
6 // CENTRALITY DEFINITION
7 //Int_t binfirst = 4;  //where do we start numbering bins
8 //Int_t binlast = 6;  //where do we stop numbering bins
9 //const Int_t numberOfCentralityBins = 9;
10 Int_t binfirst = 0;  //where do we start numbering bins
11 Int_t binlast = 8;  //where do we stop numbering bins
12 const Int_t numberOfCentralityBins = 9;
13 Float_t centralityArray[numberOfCentralityBins+1] = {0.,5.,10.,20.,30.,40.,50.,60.,70.,80.}; // in centrality percentile
14 //Int_t centralityArray[numberOfCentralityBins+1] = {41,80,146,245,384,576,835,1203,1471,10000}; // in terms of TPC only reference multiplicity
15
16 TString commonOutputFileName = "outputCentrality"; // e.g.: result for centrality bin 0 will be in the file "outputCentrality0.root", etc
17
18 //void runFlowTaskCentralityPIDTrain(Int_t mode=mLocal, Int_t nEvents = 10,
19 //Bool_t DATA = kFALSE, const Char_t* dataDir="/Users/snelling/alice_data/Therminator_midcentral", Int_t offset = 0)
20
21 void runFlowTaskCentralityPIDTrain( Int_t mode = mGrid,
22                                     Bool_t useFlowParFiles = kTRUE,
23                                     Bool_t DATA = kTRUE,
24                                     //const Char_t* dataDir="/data/alice2/ab/grid/21-16/TEST/data/",
25                                     const Char_t* dataDir="/data/alice2/mikolaj/flowPaper/data/137161/",
26                                     Int_t nEvents = 1e4,
27                                     Int_t offset=0 )
28 {
29   // Time:
30   TStopwatch timer;
31   timer.Start();
32   // Cross-check user settings before starting:
33   //  CrossCheckUserSettings(DATA);
34
35   // Load needed libraries:
36   LoadLibraries(mode,useFlowParFiles);
37
38   // Create analysis manager:
39   AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
40
41   // Chains:
42   if(mode == mLocal)
43   {
44     gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
45     TChain* chain = CreateESDChain(dataDir, nEvents, offset);
46     //TChain* chain = CreateAODChain(dataDir, nEvents, offset);
47   }
48
49   // Connect plug-in to the analysis manager:
50   if(mode == mGrid)
51   {
52     gROOT->LoadMacro("CreateAlienHandler.C");
53     AliAnalysisGrid *alienHandler = CreateAlienHandler(useFlowParFiles);
54     if(!alienHandler) return;
55     mgr->SetGridHandler(alienHandler);
56   }
57
58   // Event handlers:
59   AliVEventHandler* esdH = new AliESDInputHandler;
60   mgr->SetInputEventHandler(esdH);
61   if (!DATA)
62   {
63     AliMCEventHandler *mc = new AliMCEventHandler();
64     mgr->SetMCtruthEventHandler(mc);
65   }
66
67   // Task to check the offline trigger:
68   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
69   AddTaskPhysicsSelection(!DATA);
70
71   //Add the centrality determination task
72   gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
73   AddTaskCentrality();
74
75   //Add the TOF tender
76   gROOT->LoadMacro("$ALICE_ROOT/PWG2/FLOW/macros/AddTaskTenderTOF.C");
77   AddTaskTenderTOF();
78
79   // Setup analysis per centrality bin:
80   gROOT->LoadMacro("AddTaskFlowCentralityPID.C");
81   for (Int_t i=binfirst; i<binlast+1; i++)
82   {
83     Float_t lowCentralityBinEdge = centralityArray[i];
84     Float_t highCentralityBinEdge = centralityArray[i+1];
85     AddTaskFlowCentralityPID( lowCentralityBinEdge,
86                               highCentralityBinEdge,
87                               commonOutputFileName,
88                               AliPID::kPion,
89                               AliFlowTrackCuts::kTOFbetaSimple,
90                               -1,2,kTRUE );
91     AddTaskFlowCentralityPID( lowCentralityBinEdge,
92                               highCentralityBinEdge,
93                               commonOutputFileName,
94                               AliPID::kPion,
95                               AliFlowTrackCuts::kTOFbetaSimple,
96                               1,2,kTRUE );
97     AddTaskFlowCentralityPID( lowCentralityBinEdge,
98                               highCentralityBinEdge,
99                               commonOutputFileName,
100                               AliPID::kKaon,
101                               AliFlowTrackCuts::kTOFbetaSimple,
102                               -1,2,kTRUE );
103     AddTaskFlowCentralityPID( lowCentralityBinEdge,
104                               highCentralityBinEdge,
105                               commonOutputFileName,
106                               AliPID::kKaon,
107                               AliFlowTrackCuts::kTOFbetaSimple,
108                               1,2,kTRUE );
109     AddTaskFlowCentralityPID( lowCentralityBinEdge,
110                               highCentralityBinEdge,
111                               commonOutputFileName,
112                               AliPID::kProton,
113                               AliFlowTrackCuts::kTOFbetaSimple,
114                               -1,2,kTRUE );
115     AddTaskFlowCentralityPID( lowCentralityBinEdge,
116                               highCentralityBinEdge,
117                               commonOutputFileName,
118                               AliPID::kProton,
119                               AliFlowTrackCuts::kTOFbetaSimple,
120                               1,2,kTRUE );
121     AddTaskFlowCentralityPID( lowCentralityBinEdge,
122                               highCentralityBinEdge,
123                               commonOutputFileName,
124                               AliPID::kPion,
125                               AliFlowTrackCuts::kTOFbetaSimple,
126                               -1,3 );
127     AddTaskFlowCentralityPID( lowCentralityBinEdge,
128                               highCentralityBinEdge,
129                               commonOutputFileName,
130                               AliPID::kPion,
131                               AliFlowTrackCuts::kTOFbetaSimple,
132                               1,3 );
133     AddTaskFlowCentralityPID( lowCentralityBinEdge,
134                               highCentralityBinEdge,
135                               commonOutputFileName,
136                               AliPID::kKaon,
137                               AliFlowTrackCuts::kTOFbetaSimple,
138                               -1,3 );
139     AddTaskFlowCentralityPID( lowCentralityBinEdge,
140                               highCentralityBinEdge,
141                               commonOutputFileName,
142                               AliPID::kKaon,
143                               AliFlowTrackCuts::kTOFbetaSimple,
144                               1,3 );
145     AddTaskFlowCentralityPID( lowCentralityBinEdge,
146                               highCentralityBinEdge,
147                               commonOutputFileName,
148                               AliPID::kProton,
149                               AliFlowTrackCuts::kTOFbetaSimple,
150                               -1,3 );
151     AddTaskFlowCentralityPID( lowCentralityBinEdge,
152                               highCentralityBinEdge,
153                               commonOutputFileName,
154                               AliPID::kProton,
155                               AliFlowTrackCuts::kTOFbetaSimple,
156                               1,3 );
157   } // end of for (Int_t i=0; i<numberOfCentralityBins; i++)
158
159   // Enable debug printouts:
160   mgr->SetDebugLevel(2);
161   // Run the analysis:
162   if(!mgr->InitAnalysis()) return;
163   mgr->PrintStatus();
164   if(mode == mLocal)
165   {
166     mgr->StartAnalysis("local",chain);
167   }
168   else if(mode == mPROOF)
169   {
170     mgr->StartAnalysis("proof",dataDir,nEvents,offset);
171   }
172   else if(mode == mGrid)
173   {
174     mgr->StartAnalysis("grid");
175   }
176
177   // Print real and CPU time used for analysis:
178   timer.Stop();
179   timer.Print();
180
181 } // end of void runFlowTaskCentralityPIDTrain(...)
182
183 //===============================================================================================
184 /*
185 void CrossCheckUserSettings(Bool_t bData)
186 {
187  // Check in this method if the user settings make sense.
188  if(LYZ1SUM && LYZ2SUM) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
189  if(LYZ1PROD && LYZ2PROD) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
190  if(LYZ2SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
191  if(LYZ1SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
192 } // end of void CrossCheckUserSettings()
193 */
194 //===============================================================================================
195
196 void LoadLibraries(const anaModes mode, Bool_t useFlowParFiles )
197 {
198   //--------------------------------------
199   // Load the needed libraries most of them already loaded by aliroot
200   //--------------------------------------
201
202   gSystem->Load("libCore");
203   gSystem->Load("libTree");
204   gSystem->Load("libGeom");
205   gSystem->Load("libVMC");
206   gSystem->Load("libXMLIO");
207   gSystem->Load("libPhysics");
208   gSystem->Load("libXMLParser");
209   gSystem->Load("libProof");
210   gSystem->Load("libMinuit");
211
212   if (mode==mLocal || mode==mGrid)
213   {
214     gSystem->Load("libSTEERBase");
215     gSystem->Load("libCDB");
216     gSystem->Load("libRAWDatabase");
217     gSystem->Load("libRAWDatarec");
218     gSystem->Load("libESD");
219     gSystem->Load("libAOD");
220     gSystem->Load("libSTEER");
221     gSystem->Load("libANALYSIS");
222     gSystem->Load("libANALYSISalice");
223     gSystem->Load("libTOFbase");
224     gSystem->Load("libTOFrec");
225     gSystem->Load("libTRDbase");
226     gSystem->Load("libVZERObase");
227     gSystem->Load("libVZEROrec");
228     gSystem->Load("libT0base");
229     gSystem->Load("libT0rec");
230     gSystem->Load("libTENDER");
231     gSystem->Load("libTENDERSupplies");
232
233     if (useFlowParFiles)
234     {
235       AliAnalysisAlien::SetupPar("PWG2flowCommon");
236       AliAnalysisAlien::SetupPar("PWG2flowTasks");
237     }
238     else
239     {
240       gSystem->Load("libPWG2flowCommon");
241       gSystem->Load("libPWG2flowTasks");
242     }
243   }
244   else if (mode==mPROOF)
245   {
246     TList* list = new TList();
247     list->Add(new TNamed("ALIROOT_MODE", "ALIROOT"));
248     if (useFlowParFiles)
249       list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "ANALYSIS:ANALYSISalice:TENDER:TENDERSupplies"));
250     else
251       list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "ANALYSIS:ANALYSISalice:TENDER:TENDERSupplies:PWG2flowCommon:PWG2flowTasks"));
252
253     //list->Add(new TNamed("ALIROOT_EXTRA_INCLUDES","PWG2/FLOW/AliFlowCommon:PWG2/FLOW/AliFlowTasks"));
254
255     // Connect to proof
256     printf("*** Connect to PROOF ***\n");
257     gEnv->SetValue("XSec.GSI.DelegProxy","2");
258     //TProof* proof = TProof::Open("alice-caf.cern.ch");
259     TProof* proof = TProof::Open("skaf.saske.sk");
260
261     // list the data available
262     //gProof->ShowDataSets("/*/*");
263     //gProof->ShowDataSets("/alice/sim/"); //for MC Data
264     //gProof->ShowDataSets("/alice/data/"); //for REAL Data
265
266     proof->ClearPackages();
267     proof->EnablePackage("VO_ALICE@AliRoot::v4-21-14-AN",list);
268
269     if (useFlowParFiles)
270     {
271       gProof->UploadPackage("PWG2flowCommon.par");
272       gProof->UploadPackage("PWG2flowTasks.par");
273     }
274
275     // Show enables Packages
276     gProof->ShowEnabledPackages();
277   }
278 } // end of void LoadLibraries(const anaModes mode)
279
280 //===============================================================================================
281
282 TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
283 {
284   // creates chain of files in a given directory or file containing a list.
285   // In case of directory the structure is expected as:
286   // <aDataDir>/<dir0>/AliAOD.root
287   // <aDataDir>/<dir1>/AliAOD.root
288   // ...
289
290   if (!aDataDir)
291     return 0;
292
293   Long_t id, size, flags, modtime;
294   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
295   {
296     printf("%s not found.\n", aDataDir);
297     return 0;
298   }
299
300   TChain* chain = new TChain("aodTree");
301   TChain* chaingAlice = 0;
302
303   if (flags & 2)
304   {
305     TString execDir(gSystem->pwd());
306     TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
307     TList* dirList            = baseDir->GetListOfFiles();
308     Int_t nDirs               = dirList->GetEntries();
309     gSystem->cd(execDir);
310
311     Int_t count = 0;
312
313     for (Int_t iDir=0; iDir<nDirs; ++iDir)
314     {
315       TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
316       if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
317         continue;
318
319       if (offset > 0)
320       {
321         --offset;
322         continue;
323       }
324
325       if (count++ == aRuns)
326         break;
327
328       TString presentDirName(aDataDir);
329       presentDirName += "/";
330       presentDirName += presentDir->GetName();
331       chain->Add(presentDirName + "/AliAOD.root/aodTree");
332       // cerr<<presentDirName<<endl;
333     }
334
335   }
336   else
337   {
338     // Open the input stream
339     ifstream in;
340     in.open(aDataDir);
341
342     Int_t count = 0;
343
344     // Read the input list of files and add them to the chain
345     TString aodfile;
346     while(in.good())
347     {
348       in >> aodfile;
349       if (!aodfile.Contains("root")) continue; // protection
350
351       if (offset > 0)
352       {
353         --offset;
354         continue;
355       }
356
357       if (count++ == aRuns)
358         break;
359
360       // add aod file
361       chain->Add(aodfile);
362     }
363
364     in.close();
365   }
366
367   return chain;
368
369 } // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
370