]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FLOW/macros/runFlowTaskCentralityPIDTrain.C
Fix for #81567: fix in SetTOFResponse method (AliESDpid)
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTaskCentralityPIDTrain.C
CommitLineData
f8892375 1enum 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;
10Int_t binfirst = 0; //where do we start numbering bins
11Int_t binlast = 8; //where do we stop numbering bins
12const Int_t numberOfCentralityBins = 9;
13Float_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
16TString 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
21void 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/",
f21bdf48 25 const Char_t* dataDir="fileList",
f8892375 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");
f21bdf48 73 AliCentralitySelectionTask* centSelTask = AddTaskCentrality();
74 if (!DATA) centSelTask->SetMCInput();
75
f8892375 76
77 //Add the TOF tender
78 gROOT->LoadMacro("$ALICE_ROOT/PWG2/FLOW/macros/AddTaskTenderTOF.C");
79 AddTaskTenderTOF();
80
81 // Setup analysis per centrality bin:
82 gROOT->LoadMacro("AddTaskFlowCentralityPID.C");
83 for (Int_t i=binfirst; i<binlast+1; i++)
84 {
85 Float_t lowCentralityBinEdge = centralityArray[i];
86 Float_t highCentralityBinEdge = centralityArray[i+1];
87 AddTaskFlowCentralityPID( lowCentralityBinEdge,
88 highCentralityBinEdge,
89 commonOutputFileName,
90 AliPID::kPion,
91 AliFlowTrackCuts::kTOFbetaSimple,
92 -1,2,kTRUE );
93 AddTaskFlowCentralityPID( lowCentralityBinEdge,
94 highCentralityBinEdge,
95 commonOutputFileName,
96 AliPID::kPion,
97 AliFlowTrackCuts::kTOFbetaSimple,
98 1,2,kTRUE );
99 AddTaskFlowCentralityPID( lowCentralityBinEdge,
100 highCentralityBinEdge,
101 commonOutputFileName,
102 AliPID::kKaon,
103 AliFlowTrackCuts::kTOFbetaSimple,
104 -1,2,kTRUE );
105 AddTaskFlowCentralityPID( lowCentralityBinEdge,
106 highCentralityBinEdge,
107 commonOutputFileName,
108 AliPID::kKaon,
109 AliFlowTrackCuts::kTOFbetaSimple,
110 1,2,kTRUE );
111 AddTaskFlowCentralityPID( lowCentralityBinEdge,
112 highCentralityBinEdge,
113 commonOutputFileName,
114 AliPID::kProton,
115 AliFlowTrackCuts::kTOFbetaSimple,
116 -1,2,kTRUE );
117 AddTaskFlowCentralityPID( lowCentralityBinEdge,
118 highCentralityBinEdge,
119 commonOutputFileName,
120 AliPID::kProton,
121 AliFlowTrackCuts::kTOFbetaSimple,
122 1,2,kTRUE );
123 AddTaskFlowCentralityPID( lowCentralityBinEdge,
124 highCentralityBinEdge,
125 commonOutputFileName,
126 AliPID::kPion,
127 AliFlowTrackCuts::kTOFbetaSimple,
128 -1,3 );
129 AddTaskFlowCentralityPID( lowCentralityBinEdge,
130 highCentralityBinEdge,
131 commonOutputFileName,
132 AliPID::kPion,
133 AliFlowTrackCuts::kTOFbetaSimple,
134 1,3 );
135 AddTaskFlowCentralityPID( lowCentralityBinEdge,
136 highCentralityBinEdge,
137 commonOutputFileName,
138 AliPID::kKaon,
139 AliFlowTrackCuts::kTOFbetaSimple,
140 -1,3 );
141 AddTaskFlowCentralityPID( lowCentralityBinEdge,
142 highCentralityBinEdge,
143 commonOutputFileName,
144 AliPID::kKaon,
145 AliFlowTrackCuts::kTOFbetaSimple,
146 1,3 );
147 AddTaskFlowCentralityPID( lowCentralityBinEdge,
148 highCentralityBinEdge,
149 commonOutputFileName,
150 AliPID::kProton,
151 AliFlowTrackCuts::kTOFbetaSimple,
152 -1,3 );
153 AddTaskFlowCentralityPID( lowCentralityBinEdge,
154 highCentralityBinEdge,
155 commonOutputFileName,
156 AliPID::kProton,
157 AliFlowTrackCuts::kTOFbetaSimple,
158 1,3 );
159 } // end of for (Int_t i=0; i<numberOfCentralityBins; i++)
160
161 // Enable debug printouts:
162 mgr->SetDebugLevel(2);
163 // Run the analysis:
164 if(!mgr->InitAnalysis()) return;
165 mgr->PrintStatus();
166 if(mode == mLocal)
167 {
168 mgr->StartAnalysis("local",chain);
169 }
170 else if(mode == mPROOF)
171 {
172 mgr->StartAnalysis("proof",dataDir,nEvents,offset);
173 }
174 else if(mode == mGrid)
175 {
176 mgr->StartAnalysis("grid");
177 }
178
179 // Print real and CPU time used for analysis:
180 timer.Stop();
181 timer.Print();
182
183} // end of void runFlowTaskCentralityPIDTrain(...)
184
185//===============================================================================================
186/*
187void CrossCheckUserSettings(Bool_t bData)
188{
189 // Check in this method if the user settings make sense.
190 if(LYZ1SUM && LYZ2SUM) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
191 if(LYZ1PROD && LYZ2PROD) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
192 if(LYZ2SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
193 if(LYZ1SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
194} // end of void CrossCheckUserSettings()
195*/
196//===============================================================================================
197
198void LoadLibraries(const anaModes mode, Bool_t useFlowParFiles )
199{
200 //--------------------------------------
201 // Load the needed libraries most of them already loaded by aliroot
202 //--------------------------------------
203
204 gSystem->Load("libCore");
205 gSystem->Load("libTree");
206 gSystem->Load("libGeom");
207 gSystem->Load("libVMC");
208 gSystem->Load("libXMLIO");
209 gSystem->Load("libPhysics");
210 gSystem->Load("libXMLParser");
211 gSystem->Load("libProof");
212 gSystem->Load("libMinuit");
213
214 if (mode==mLocal || mode==mGrid)
215 {
216 gSystem->Load("libSTEERBase");
217 gSystem->Load("libCDB");
218 gSystem->Load("libRAWDatabase");
219 gSystem->Load("libRAWDatarec");
220 gSystem->Load("libESD");
221 gSystem->Load("libAOD");
222 gSystem->Load("libSTEER");
223 gSystem->Load("libANALYSIS");
224 gSystem->Load("libANALYSISalice");
cd62a2a8 225 gSystem->Load("libTPCbase");
f8892375 226 gSystem->Load("libTOFbase");
227 gSystem->Load("libTOFrec");
228 gSystem->Load("libTRDbase");
229 gSystem->Load("libVZERObase");
230 gSystem->Load("libVZEROrec");
231 gSystem->Load("libT0base");
232 gSystem->Load("libT0rec");
233 gSystem->Load("libTENDER");
234 gSystem->Load("libTENDERSupplies");
235
236 if (useFlowParFiles)
237 {
238 AliAnalysisAlien::SetupPar("PWG2flowCommon");
239 AliAnalysisAlien::SetupPar("PWG2flowTasks");
240 }
241 else
242 {
243 gSystem->Load("libPWG2flowCommon");
244 gSystem->Load("libPWG2flowTasks");
245 }
246 }
247 else if (mode==mPROOF)
248 {
249 TList* list = new TList();
250 list->Add(new TNamed("ALIROOT_MODE", "ALIROOT"));
251 if (useFlowParFiles)
252 list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "ANALYSIS:ANALYSISalice:TENDER:TENDERSupplies"));
253 else
254 list->Add(new TNamed("ALIROOT_EXTRA_LIBS", "ANALYSIS:ANALYSISalice:TENDER:TENDERSupplies:PWG2flowCommon:PWG2flowTasks"));
255
256 //list->Add(new TNamed("ALIROOT_EXTRA_INCLUDES","PWG2/FLOW/AliFlowCommon:PWG2/FLOW/AliFlowTasks"));
257
258 // Connect to proof
259 printf("*** Connect to PROOF ***\n");
260 gEnv->SetValue("XSec.GSI.DelegProxy","2");
261 //TProof* proof = TProof::Open("alice-caf.cern.ch");
262 TProof* proof = TProof::Open("skaf.saske.sk");
263
264 // list the data available
265 //gProof->ShowDataSets("/*/*");
266 //gProof->ShowDataSets("/alice/sim/"); //for MC Data
267 //gProof->ShowDataSets("/alice/data/"); //for REAL Data
268
269 proof->ClearPackages();
270 proof->EnablePackage("VO_ALICE@AliRoot::v4-21-14-AN",list);
271
272 if (useFlowParFiles)
273 {
274 gProof->UploadPackage("PWG2flowCommon.par");
275 gProof->UploadPackage("PWG2flowTasks.par");
276 }
277
278 // Show enables Packages
279 gProof->ShowEnabledPackages();
280 }
281} // end of void LoadLibraries(const anaModes mode)
282
283//===============================================================================================
284
285TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
286{
287 // creates chain of files in a given directory or file containing a list.
288 // In case of directory the structure is expected as:
289 // <aDataDir>/<dir0>/AliAOD.root
290 // <aDataDir>/<dir1>/AliAOD.root
291 // ...
292
293 if (!aDataDir)
294 return 0;
295
296 Long_t id, size, flags, modtime;
297 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
298 {
299 printf("%s not found.\n", aDataDir);
300 return 0;
301 }
302
303 TChain* chain = new TChain("aodTree");
304 TChain* chaingAlice = 0;
305
306 if (flags & 2)
307 {
308 TString execDir(gSystem->pwd());
309 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
310 TList* dirList = baseDir->GetListOfFiles();
311 Int_t nDirs = dirList->GetEntries();
312 gSystem->cd(execDir);
313
314 Int_t count = 0;
315
316 for (Int_t iDir=0; iDir<nDirs; ++iDir)
317 {
318 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
319 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
320 continue;
321
322 if (offset > 0)
323 {
324 --offset;
325 continue;
326 }
327
328 if (count++ == aRuns)
329 break;
330
331 TString presentDirName(aDataDir);
332 presentDirName += "/";
333 presentDirName += presentDir->GetName();
334 chain->Add(presentDirName + "/AliAOD.root/aodTree");
335 // cerr<<presentDirName<<endl;
336 }
337
338 }
339 else
340 {
341 // Open the input stream
342 ifstream in;
343 in.open(aDataDir);
344
345 Int_t count = 0;
346
347 // Read the input list of files and add them to the chain
348 TString aodfile;
349 while(in.good())
350 {
351 in >> aodfile;
352 if (!aodfile.Contains("root")) continue; // protection
353
354 if (offset > 0)
355 {
356 --offset;
357 continue;
358 }
359
360 if (count++ == aRuns)
361 break;
362
363 // add aod file
364 chain->Add(aodfile);
365 }
366
367 in.close();
368 }
369
370 return chain;
371
372} // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
373