Remove not needed protection in case of 0 tracks in the event to set the matched...
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTask.C
CommitLineData
5c09ff70 1enum anaModes {mLocal,mLocalPAR,mPROOF,mGrid,mGridPAR};
73160af6 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
5c09ff70 5//mGrid: Analyze files on Grid via AliEn plug-in and using precompiled FLOW libraries
cf6d56bc 6// (Remark: When using this mode set also Bool_t bUseParFiles = kFALSE; in CreateAlienHandler.C)
5c09ff70 7//mGridPAR: Analyze files on Grid via AliEn plug-in and using par files for FLOW package
cf6d56bc 8// (Remark: when using this mode set also Bool_t bUseParFiles = kTRUE; in CreateAlienHandler.C)
9
10// CENTRALITY DEFINITION
11Bool_t kUseCentrality = kFALSE;
12Int_t binfirst = -1; //if kUseCentrality then change accordingly
13Int_t binlast = -1; //if kUseCentrality then change accordingly
14const Int_t numberOfCentralityBins = 9;
15Float_t centralityArray[numberOfCentralityBins+1] = {0.,5.,10.,20.,30.,40.,50.,60.,70.,80.}; // in centrality percentile
16//Int_t centralityArray[numberOfCentralityBins+1] = {41,80,146,245,384,576,835,1203,1471,10000}; // in terms of TPC only reference multiplicity
73160af6 17
cf6d56bc 18TString commonOutputFileName = "outputCentrality"; // e.g.: result for centrality bin 0 will be in the file "outputCentrality0.root", etc
73160af6 19
21f8d9b1 20
cf6d56bc 21//void runFlowTask(Int_t mode=mLocal, Int_t nRuns = 10,
22//Bool_t DATA = kFALSE, const Char_t* dataDir="/Users/snelling/alice_data/Therminator_midcentral", Int_t offset = 0)
ff1a880b 23
cf6d56bc 24//void runFlowTask(Int_t mode = mGridPAR, Int_t nRuns = 50000000,
25// Bool_t DATA = kTRUE, const Char_t* dataDir="/alice/data/LHC10h_000137161_p1_plusplusplus", Int_t offset=0)
26void runFlowTask(Int_t mode = mLocal, Int_t nRuns = 50000000,
27 Bool_t DATA = kTRUE, const Char_t* dataDir="./data/", Int_t offset=0)
28//void runFlowTask(Int_t mode = mGridPAR, Bool_t DATA = kTRUE)
73160af6 29{
5c09ff70 30 // Time:
73160af6 31 TStopwatch timer;
32 timer.Start();
5c09ff70 33 // Cross-check user settings before starting:
cf6d56bc 34 // CrossCheckUserSettings(DATA);
5c09ff70 35 // Load needed libraries:
73160af6 36 LoadLibraries(mode);
5c09ff70 37 // Create and configure the AliEn plug-in:
38 if(mode == mGrid || mode == mGridPAR)
cf6d56bc 39 {
40 gROOT->LoadMacro("CreateAlienHandler.C");
41 AliAnalysisGrid *alienHandler = CreateAlienHandler();
42 if(!alienHandler) return;
43 }
44 // Chains:
45 if(mode == mLocal || mode == mLocalPAR) {
46 TChain *chain = new TChain("esdTree");
47 chain->Add("/home/pchrist/ALICE/HeavyIons/Data/137161/Set1/AliESDs.root");
48 //TChain* chain = CreateESDChain(dataDir, nRuns, offset);
49 //TChain* chain = CreateAODChain(dataDir, nRuns, offset);
73160af6 50 }
cf6d56bc 51
5c09ff70 52 // Create analysis manager:
cf6d56bc 53 AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
5c09ff70 54 // Connect plug-in to the analysis manager:
55 if(mode == mGrid || mode == mGridPAR)
cf6d56bc 56 {
57 mgr->SetGridHandler(alienHandler);
58 }
59
5c09ff70 60 // Event handlers:
cf6d56bc 61 AliVEventHandler* esdH = new AliESDInputHandler;
62 mgr->SetInputEventHandler(esdH);
63 if (!DATA) {
73160af6 64 AliMCEventHandler *mc = new AliMCEventHandler();
4a1a86a5 65 mgr->SetMCtruthEventHandler(mc);
cf6d56bc 66 }
67
5c09ff70 68 // Task to check the offline trigger:
cf6d56bc 69 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
70 AddTaskPhysicsSelection(!DATA);
71
72 //Add the centrality determination task
73 if(kUseCentrality) {
74 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
75 AddTaskCentrality();
76 }
77
78 //Add the TOF tender
2b1eaa10 79 //gROOT->LoadMacro("$ALICE_ROOT/PWG2/FLOW/macros/AddTaskTenderFlow.C");
80 //AddTaskTenderFlow();
cf6d56bc 81
82 // Setup analysis and usage of centrality bins
83 gROOT->LoadMacro("AddTaskFlow.C");
84 Float_t kLowCentralityBin = -1.;
85 Float_t kHighCentralityBin = -1;
86 if(kUseCentrality) {
87 kLowCentralityBin = centralityArray[binfirst];
88 kHighCentralityBin = centralityArray[binlast];
89 }
90 AddTaskFlow(kLowCentralityBin,
91 kHighCentralityBin,
92 commonOutputFileName );
93
5c09ff70 94 // Enable debug printouts:
9cc5e012 95 mgr->SetDebugLevel(2);
5c09ff70 96 // Run the analysis:
cf6d56bc 97 if(!mgr->InitAnalysis()) return;
98 mgr->PrintStatus();
99 if(mode == mLocal || mode == mLocalPAR) {
100 mgr->StartAnalysis("local",chain);
101 } else if(mode == mPROOF) {
102 mgr->StartAnalysis("proof",dataDir,nRuns,offset);
103 } else if(mode == mGrid || mode == mGridPAR) {
104 mgr->StartAnalysis("grid");
105 }
106
107 // Print real and CPU time used for analysis:
73160af6 108 timer.Stop();
cf6d56bc 109 timer.Print();
93329510 110
5c09ff70 111} // end of void runFlowTask(...)
112
113//===============================================================================================
cf6d56bc 114/*
61e0c8c0 115void CrossCheckUserSettings(Bool_t bData)
116{
cf6d56bc 117 // Check in this method if the user settings make sense.
5c09ff70 118 if(LYZ1SUM && LYZ2SUM) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
119 if(LYZ1PROD && LYZ2PROD) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
120 if(LYZ2SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
121 if(LYZ1SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
61e0c8c0 122} // end of void CrossCheckUserSettings()
cf6d56bc 123*/
5c09ff70 124//===============================================================================================
125
126void LoadLibraries(const anaModes mode)
cf6d56bc 127{
93329510 128 //--------------------------------------
129 // Load the needed libraries most of them already loaded by aliroot
130 //--------------------------------------
cf6d56bc 131
132 gSystem->Load("libCore");
5d040cf3 133 gSystem->Load("libTree");
134 gSystem->Load("libGeom");
135 gSystem->Load("libVMC");
136 gSystem->Load("libXMLIO");
137 gSystem->Load("libPhysics");
cf6d56bc 138 gSystem->Load("libXMLParser");
139 gSystem->Load("libProof");
140 gSystem->Load("libMinuit");
93329510 141
cf6d56bc 142 if (mode==mLocal || mode==mGrid || mode == mGridPAR || mode == mLocalPAR )
143 {
93329510 144 gSystem->Load("libSTEERBase");
cf6d56bc 145 gSystem->Load("libCDB");
146 gSystem->Load("libRAWDatabase");
147 gSystem->Load("libRAWDatarec");
93329510 148 gSystem->Load("libESD");
149 gSystem->Load("libAOD");
cf6d56bc 150 gSystem->Load("libSTEER");
93329510 151 gSystem->Load("libANALYSIS");
cf6d56bc 152 gSystem->Load("libANALYSISalice");
153 gSystem->Load("libTOFbase");
154 gSystem->Load("libTOFrec");
155 gSystem->Load("libTENDER");
156
157 if (mode == mLocal || mode == mGrid)
5c09ff70 158 {
cf6d56bc 159 gSystem->Load("libTENDERSupplies");
160 gSystem->Load("libPWG2flowCommon");
161 gSystem->Load("libPWG2flowTasks");
f630b0f9 162 }
cf6d56bc 163 if (mode == mLocalPAR || mode == mGridPAR )
5c09ff70 164 {
cf6d56bc 165 AliAnalysisAlien::SetupPar("TENDERSupplies");
166 AliAnalysisAlien::SetupPar("PWG2flowCommon");
167 AliAnalysisAlien::SetupPar("PWG2flowTasks");
f630b0f9 168 }
93329510 169 }
170
93329510 171 //---------------------------------------------------------
172 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
173 //---------------------------------------------------------
174 else if (mode==mPROOF) {
93329510 175 // set to debug root versus if needed
2aa4ebcd 176 //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a_dbg");
edd5904a 177 //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a");
7f7086f7 178 //TProof::Reset("proof://snelling@alicecaf.cern.ch");
93329510 179 // Connect to proof
93329510 180 printf("*** Connect to PROOF ***\n");
238dd515 181 gEnv->SetValue("XSec.GSI.DelegProxy","2");
cf6d56bc 182 TProof::Open("mkrzewic@alice-caf.cern.ch");
183 //TProof::Open("mkrzewic@skaf.saske.sk");
184 // list the data available
238dd515 185 //gProof->ShowDataSets("/*/*");
186 //gProof->ShowDataSets("/alice/sim/"); //for MC Data
187 //gProof->ShowDataSets("/alice/data/"); //for REAL Data
7f7086f7 188
189 // Clear the Packages
cf6d56bc 190 /*
edd5904a 191 gProof->ClearPackage("STEERBase.par");
edd5904a 192 gProof->ClearPackage("ESD.par");
edd5904a 193 gProof->ClearPackage("AOD.par");
cf6d56bc 194 */
195 //gProof->ClearPackage("ANALYSIS.par");
196 //gProof->ClearPackage("ANALYSISalice.par");
197 //gProof->ClearPackage("CORRFW.par");
bec5e178 198
2aa4ebcd 199 gProof->ClearPackage("PWG2flowCommon");
2aa4ebcd 200 gProof->ClearPackage("PWG2flowTasks");
206fe5a1 201
7f7086f7 202 // Upload the Packages
cf6d56bc 203 //gProof->UploadPackage("STEERBase.par");
204 //gProof->UploadPackage("ESD.par");
205 //gProof->UploadPackage("AOD.par");
bec5e178 206
cf6d56bc 207 //gProof->UploadPackage("ANALYSIS.par");
208 //gProof->UploadPackage("ANALYSISalice.par");
7f7086f7 209 gProof->UploadPackage("CORRFW.par");
210 gProof->UploadPackage("PWG2flowCommon.par");
93329510 211 gProof->UploadPackage("PWG2flowTasks.par");
cf6d56bc 212 gProof->UploadPackage("ALIRECO.par");
7f7086f7 213
bec5e178 214 // Enable the Packages
215 // The global package
cf6d56bc 216 TList* list = new TList();
217 list->Add(new TNamed("ALIROOT_EXTRA_INCLUDES","RAW:OCDB:STEER:TOF"));
218 gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-07-AN",list);
219 gProof->EnablePackage("ALIRECO");
220 //gProof->EnablePackage("ANALYSIS");
221 //gProof->EnablePackage("ANALYSISalice");
222 //gProof->EnablePackage("CORRFW");
7f7086f7 223 gProof->EnablePackage("PWG2flowCommon");
93329510 224 gProof->EnablePackage("PWG2flowTasks");
7f7086f7 225
226 // Show enables Packages
93329510 227 gProof->ShowEnabledPackages();
228 }
229
cf6d56bc 230} // end of void LoadLibraries(const anaModes mode)
73160af6 231
232// Helper macros for creating chains
233// from: CreateESDChain.C,v 1.10 jgrosseo Exp
234
235TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
236{
93329510 237 // creates chain of files in a given directory or file containing a list.
238 // In case of directory the structure is expected as:
239 // <aDataDir>/<dir0>/AliESDs.root
240 // <aDataDir>/<dir1>/AliESDs.root
241 // ...
242
243 if (!aDataDir)
244 return 0;
245
246 Long_t id, size, flags, modtime;
247 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
248 {
249 printf("%s not found.\n", aDataDir);
250 return 0;
251 }
252
253 TChain* chain = new TChain("esdTree");
254 TChain* chaingAlice = 0;
255
256 if (flags & 2)
257 {
258 TString execDir(gSystem->pwd());
259 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
260 TList* dirList = baseDir->GetListOfFiles();
261 Int_t nDirs = dirList->GetEntries();
262 gSystem->cd(execDir);
263
264 Int_t count = 0;
265
266 for (Int_t iDir=0; iDir<nDirs; ++iDir)
73160af6 267 {
268 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
269 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
270 continue;
271
272 if (offset > 0)
273 {
274 --offset;
275 continue;
276 }
277
278 if (count++ == aRuns)
279 break;
280
281 TString presentDirName(aDataDir);
282 presentDirName += "/";
283 presentDirName += presentDir->GetName();
284 chain->Add(presentDirName + "/AliESDs.root/esdTree");
285 // cerr<<presentDirName<<endl;
286 }
93329510 287
288 }
289 else
290 {
291 // Open the input stream
292 ifstream in;
293 in.open(aDataDir);
294
295 Int_t count = 0;
296
297 // Read the input list of files and add them to the chain
298 TString esdfile;
299 while(in.good()) {
73160af6 300 in >> esdfile;
301 if (!esdfile.Contains("root")) continue; // protection
302
303 if (offset > 0)
304 {
305 --offset;
306 continue;
307 }
308
309 if (count++ == aRuns)
310 break;
311
93329510 312 // add esd file
73160af6 313 chain->Add(esdfile);
93329510 314 }
315
316 in.close();
317 }
318
319 return chain;
73160af6 320
5c09ff70 321} // end of TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
93329510 322
5c09ff70 323//===============================================================================================
73160af6 324
325TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
326{
93329510 327 // creates chain of files in a given directory or file containing a list.
328 // In case of directory the structure is expected as:
329 // <aDataDir>/<dir0>/AliAOD.root
330 // <aDataDir>/<dir1>/AliAOD.root
331 // ...
332
333 if (!aDataDir)
334 return 0;
335
336 Long_t id, size, flags, modtime;
337 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
338 {
339 printf("%s not found.\n", aDataDir);
340 return 0;
341 }
342
343 TChain* chain = new TChain("aodTree");
344 TChain* chaingAlice = 0;
345
346 if (flags & 2)
347 {
348 TString execDir(gSystem->pwd());
349 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
350 TList* dirList = baseDir->GetListOfFiles();
351 Int_t nDirs = dirList->GetEntries();
352 gSystem->cd(execDir);
353
354 Int_t count = 0;
355
356 for (Int_t iDir=0; iDir<nDirs; ++iDir)
73160af6 357 {
358 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
359 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
360 continue;
361
362 if (offset > 0)
363 {
364 --offset;
365 continue;
366 }
367
368 if (count++ == aRuns)
369 break;
370
371 TString presentDirName(aDataDir);
372 presentDirName += "/";
373 presentDirName += presentDir->GetName();
374 chain->Add(presentDirName + "/AliAOD.root/aodTree");
375 // cerr<<presentDirName<<endl;
376 }
93329510 377
378 }
379 else
380 {
381 // Open the input stream
382 ifstream in;
383 in.open(aDataDir);
384
385 Int_t count = 0;
386
387 // Read the input list of files and add them to the chain
388 TString aodfile;
389 while(in.good()) {
73160af6 390 in >> aodfile;
391 if (!aodfile.Contains("root")) continue; // protection
392
393 if (offset > 0)
394 {
395 --offset;
396 continue;
397 }
398
399 if (count++ == aRuns)
400 break;
401
93329510 402 // add aod file
73160af6 403 chain->Add(aodfile);
93329510 404 }
405
406 in.close();
407 }
408
409 return chain;
5c09ff70 410
411} // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
73160af6 412