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