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