]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FLOW/macros/runFlowTaskCentralityTrain.C
enabling centrality "train"
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTaskCentralityTrain.C
CommitLineData
daf66719 1enum anaModes {mLocal,mLocalPAR,mPROOF,mGRID};
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
5
6//CENTRALITY DEFINITION
7const Int_t numberOfCentralityBins = 3;
59dab33a 8Int_t centralityArray[numberOfCentralityBins+1] = {0,4,6,100};
daf66719 9
10// RUN SETTINGS
11
12// Flow analysis method can be:(set to kTRUE or kFALSE)
13Bool_t MCEP = kTRUE; // correlation with Monte Carlo reaction plane
14Bool_t SP = kTRUE; // scalar product method (similar to eventplane method)
15Bool_t GFC = kTRUE; // cumulants based on generating function
16Bool_t QC = kTRUE; // cumulants using Q vectors
17Bool_t FQD = kTRUE; // fit of the distribution of the Q vector (only integrated v)
18Bool_t LYZ1SUM = kTRUE; // Lee Yang Zeroes using sum generating function (integrated v)
19Bool_t LYZ1PROD = kTRUE; // Lee Yang Zeroes using product generating function (integrated v)
20Bool_t LYZ2SUM = kFALSE; // Lee Yang Zeroes using sum generating function (second pass differential v)
21Bool_t LYZ2PROD = kFALSE; // Lee Yang Zeroes using product generating function (second pass differential v)
22Bool_t LYZEP = kFALSE; // Lee Yang Zeroes Event plane using sum generating function (gives eventplane + weight)
23Bool_t MH = kTRUE; // azimuthal correlators in mixed harmonics
24Bool_t NL = kTRUE; // nested loops (for instance distribution of phi1-phi2 for all distinct pairs)
25
26Bool_t METHODS[] = {SP,LYZ1SUM,LYZ1PROD,LYZ2SUM,LYZ2PROD,LYZEP,GFC,QC,FQD,MCEP,MH,NL};
27
28// Analysis type can be ESD, AOD, MC, ESDMCkineESD, ESDMCkineMC
59dab33a 29const TString type = "MK";
daf66719 30
31// Boolean to fill/not fill the QA histograms
32Bool_t QA = kTRUE;
33
34// Boolean to use/not use weights for the Q vector
35Bool_t WEIGHTS[] = {kFALSE,kFALSE,kFALSE}; //Phi, v'(pt), v'(eta)
36
37
59dab33a 38void runFlowTaskCentralityTrain(Int_t mode=mLocal, Int_t nRuns = 1,
39Bool_t DATA = kFALSE, const Char_t* dataDir="LHC10d4", Int_t offset = 0)
daf66719 40// Bool_t DATA = kFALSE, const Char_t* dataDir="/data/alice2/kolk/PP/LHC09d10/104873", Int_t offset = 0)
41
59dab33a 42//void runFlowTaskCentralityTrain(Int_t mode = mPROOF, Int_t nRuns = 50000000,
daf66719 43 //Bool_t DATA = kFALSE, const Char_t* dataDir="/PWG2/akisiel/Therminator_midcentral_ESD", Int_t offset=0)
44 //Bool_t DATA = kFALSE, const Char_t* dataDir="/PWG2/akisiel/LHC10d6_0.9TeV_EPOS_12502X", Int_t offset=0)
45 //Bool_t DATA = kFALSE, const Char_t* dataDir="/alice/sim/LHC10d2_117048", Int_t offset=0) //phojet 7 TeV
46 //Bool_t DATA = kTRUE, const Char_t* dataDir="/alice/data/LHC09d_000104792_p6", Int_t offset=0) //data 0.9 TeV
59dab33a 47 //Bool_t DATA = kFALSE, const Char_t* dataDir="/PWG4/morsch/HIJING_CENT_4EV", Int_t offset=0) //hijing Pb Pb pilot
daf66719 48
59dab33a 49//void runFlowTaskCentralityTrain(Int_t mode = mGRID, Bool_t DATA = kTRUE)
daf66719 50{
51 TStopwatch timer;
52 timer.Start();
53
54 CrossCheckUserSettings(DATA);
55
56 LoadLibraries(mode);
57
58 if (mode == mGRID) {
59 // Create and configure the alien handler plugin
60 gROOT->LoadMacro("CreateAlienHandler.C");
61 AliAnalysisGrid *alienHandler = CreateAlienHandler();
62 if (!alienHandler) return;
63 }
64
65 if (mode==mLocal || mode == mLocalPAR) {
66 if (type!="AOD") { TChain* chain = CreateESDChain(dataDir, nRuns, offset);}
67 else { TChain* chain = CreateAODChain(dataDir, nRuns, offset);}
68 }
69 //____________________________________________//
70 // Make the analysis manager
71 AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
72
73 if (mode == mGRID) {
74 // Connect plug-in to the analysis manager
75 mgr->SetGridHandler(alienHandler);
76 }
daf66719 77 if (type == "ESD"){
78 AliVEventHandler* esdH = new AliESDInputHandler;
79 mgr->SetInputEventHandler(esdH);
80 if (MCEP) {
81 AliMCEventHandler *mc = new AliMCEventHandler();
82 mgr->SetMCtruthEventHandler(mc);
83 }
84 }
59dab33a 85 if (type == "MK"){
86 AliVEventHandler* esdH = new AliESDInputHandler;
87 mgr->SetInputEventHandler(esdH);
88 if (MCEP) {
89 AliMCEventHandler *mc = new AliMCEventHandler();
90 mgr->SetMCtruthEventHandler(mc);
91 }
92 }
93
94
daf66719 95
96 if (type == "AOD"){
97 AliVEventHandler* aodH = new AliAODInputHandler;
98 mgr->SetInputEventHandler(aodH);
99 if (MCEP) {
100 AliMCEventHandler *mc = new AliMCEventHandler();
101 mgr->SetMCtruthEventHandler(mc);
102 }
103 }
104
105 if (type == "MC" || type == "ESDMCkineESD" || type == "ESDMCkineMC"){
106 AliVEventHandler* esdH = new AliESDInputHandler;
107 mgr->SetInputEventHandler(esdH);
108
109 AliMCEventHandler *mc = new AliMCEventHandler();
110 mgr->SetMCtruthEventHandler(mc);
111 }
112
113 //____________________________________________//
114 // Load the analysis task
59dab33a 115 gROOT->LoadMacro("AddTaskFlowCentrality.C");
daf66719 116
117 for (Int_t i=0; i<numberOfCentralityBins; i++)
118 {
119 Int_t lowCentralityBinEdge = centralityArray[i];
120 Int_t highCentralityBinEdge = centralityArray[i+1];
121 TString filename("outputCentrality");
122 filename += i;
123 //TDirectory* dir = new TDirectory(filename.Data(),"");
124 filename += ".root";
125 AddTaskFlowCentrality( type,
126 METHODS,
127 QA,
128 WEIGHTS,
129 lowCentralityBinEdge,
130 highCentralityBinEdge,
131 filename );
132 }
133
134
135 // Task to check the offline trigger
136 if (mode == mLocal || mode == mGRID) {
137 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); }
138 else if (mode == mPROOF || mode == mLocalPAR) {
139 gROOT->LoadMacro("AddTaskPhysicsSelection.C"); }
140 AliPhysicsSelectionTask* physicsSelTask = AddTaskPhysicsSelection();
141 if (!DATA) {physicsSelTask->GetPhysicsSelection()->SetAnalyzeMC();}
142
143
144 // Enable debug printouts
145 mgr->SetDebugLevel(2);
146
147
148 //____________________________________________//
149 // Run the analysis
150 if (!mgr->InitAnalysis()) return;
151 mgr->PrintStatus();
152
153 if (mode == mLocal || mode == mLocalPAR) {
154 mgr->StartAnalysis("local",chain);
155 }
156 else if (mode == mPROOF) {
157 mgr->StartAnalysis("proof",dataDir,nRuns,offset);
158 }
159 else if (mode == mGRID) {
160 mgr->StartAnalysis("grid");
161 }
162
163 timer.Stop();
164 timer.Print();
165
166}
167
168void CrossCheckUserSettings(Bool_t bData)
169{
170 // Check in this method if the user settings make sense.
171
172 if(MCEP==kTRUE && bData==kTRUE)
173 {
174 cout<<endl;
175 cout<<"WARNING: In real datasets there is no Monte Carlo information available !!!!"<<endl;
176 cout<<" Set for real data analysis DATA = kTRUE and MCEP = kFALSE in the macro."<<endl;
177 cout<<endl;
178 exit(0);
179 }
180
181} // end of void CrossCheckUserSettings()
182
183void LoadLibraries(const anaModes mode) {
184
185 //--------------------------------------
186 // Load the needed libraries most of them already loaded by aliroot
187 //--------------------------------------
188 gSystem->Load("libTree");
189 gSystem->Load("libGeom");
190 gSystem->Load("libVMC");
191 gSystem->Load("libXMLIO");
192 gSystem->Load("libPhysics");
193
194 //----------------------------------------------------------
195 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
196 //----------------------------------------------------------
197 if (mode==mLocal || mode==mGRID) {
198 //--------------------------------------------------------
199 // If you want to use already compiled libraries
200 // in the aliroot distribution
201 //--------------------------------------------------------
202 gSystem->Load("libSTEERBase");
203 gSystem->Load("libESD");
204 gSystem->Load("libAOD");
205 gSystem->Load("libANALYSIS");
206 gSystem->Load("libANALYSISalice");
207 gSystem->Load("libCORRFW");
208 gSystem->Load("libPWG2forward");
209 if (mode==mLocal) {
210 gSystem->Load("libPWG2flowCommon");
211 cerr<<"libPWG2flowCommon loaded..."<<endl;
212 gSystem->Load("libPWG2flowTasks");
213 cerr<<"libPWG2flowTasks loaded..."<<endl;
214 }
215 if (mode==mGRID) {
216 SetupPar("PWG2flowCommon");
217 cerr<<"PWG2flowCommon.par loaded..."<<endl;
218 SetupPar("PWG2flowTasks");
219 cerr<<"PWG2flowTasks.par loaded..."<<endl;
220 }
221 }
222
223 else if (mode == mLocalPAR) {
224 //--------------------------------------------------------
225 //If you want to use root and par files from aliroot
226 //--------------------------------------------------------
227 SetupPar("STEERBase");
228 SetupPar("ESD");
229 SetupPar("AOD");
230 SetupPar("ANALYSIS");
231 SetupPar("ANALYSISalice");
232 SetupPar("CORRFW");
233 SetupPar("PWG2flowCommon");
234 cerr<<"PWG2flowCommon.par loaded..."<<endl;
235 SetupPar("PWG2flowTasks");
236 cerr<<"PWG2flowTasks.par loaded..."<<endl;
237 }
238
239 //---------------------------------------------------------
240 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
241 //---------------------------------------------------------
242 else if (mode==mPROOF) {
243 //
244 //gEnv->SetValue("XSec.GSI.DelegProxy","2");
245 // set to debug root versus if needed
246 //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a_dbg");
247 //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a");
248 //TProof::Reset("proof://snelling@alicecaf.cern.ch");
249 // Connect to proof
250 printf("*** Connect to PROOF ***\n");
251 gEnv->SetValue("XSec.GSI.DelegProxy","2");
252 // Put appropriate username here
253 //TProof::Open("abilandz@alicecaf.cern.ch");
254 //TProof::Open("nkolk@alicecaf.cern.ch");
255 //TProof::Open("snelling@localhost");
256 TProof::Open("alice-caf.cern.ch");
257 //TProof::Open("skaf.saske.sk");
258 //TProof::Open("prf000-iep-grid.saske.sk");
259 //Info("runSKAF.C","Loading libs on proof (may take while, around 1 min) ...");
260 // list the data available
261 //gProof->ShowDataSets("/*/*");
262 //gProof->ShowDataSets("/alice/sim/"); //for MC Data
263 //gProof->ShowDataSets("/alice/data/"); //for REAL Data
264
265 // Clear the Packages
266
267 gProof->ClearPackage("STEERBase.par");
268 gProof->ClearPackage("ESD.par");
269 gProof->ClearPackage("AOD.par");
270 gProof->ClearPackage("ANALYSIS.par");
271 gProof->ClearPackage("ANALYSISalice.par");
272 gProof->ClearPackage("CORRFW.par");
273
274 gProof->ClearPackage("PWG2flowCommon");
275 gProof->ClearPackage("PWG2flowTasks");
276
277 // Upload the Packages
278 gProof->UploadPackage("STEERBase.par");
279 gProof->UploadPackage("ESD.par");
280 gProof->UploadPackage("AOD.par");
281
282 gProof->UploadPackage("ANALYSIS.par");
283 gProof->UploadPackage("ANALYSISalice.par");
284 gProof->UploadPackage("CORRFW.par");
285 gProof->UploadPackage("PWG2flowCommon.par");
286 gProof->UploadPackage("PWG2flowTasks.par");
287
288 // Enable the Packages
289 // The global package
290 //gProof->EnablePackage("aliroot_v4-19-05-AN",kTRUE);
291 // Or separate
292
293 gProof->EnablePackage("STEERBase");
294 gProof->EnablePackage("ESD");
295 gProof->EnablePackage("AOD");
296
297 // Always needed
298 gProof->EnablePackage("ANALYSIS");
299 gProof->EnablePackage("ANALYSISalice");
300 gProof->EnablePackage("CORRFW");
301 gProof->EnablePackage("PWG2flowCommon");
302 gProof->EnablePackage("PWG2flowTasks");
303
304 // Show enables Packages
305 gProof->ShowEnabledPackages();
306 }
307
308}
309
310void SetupPar(char* pararchivename) {
311 //Load par files, create analysis libraries
312 //For testing, if par file already decompressed and modified
313 //classes then do not decompress.
314
315 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
316 TString parpar(Form("%s.par", pararchivename)) ;
317 if ( gSystem->AccessPathName(parpar.Data()) ) {
318 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
319 TString processline(Form(".! make %s", parpar.Data())) ;
320 gROOT->ProcessLine(processline.Data()) ;
321 gSystem->ChangeDirectory(cdir) ;
322 processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
323 gROOT->ProcessLine(processline.Data()) ;
324 }
325 if ( gSystem->AccessPathName(pararchivename) ) {
326 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
327 gROOT->ProcessLine(processline.Data());
328 }
329
330 TString ocwd = gSystem->WorkingDirectory();
331 gSystem->ChangeDirectory(pararchivename);
332
333 // check for BUILD.sh and execute
334 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
335 printf("*******************************\n");
336 printf("*** Building PAR archive ***\n");
337 cout<<pararchivename<<endl;
338 printf("*******************************\n");
339 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
340 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
341 return -1;
342 }
343 }
344 // check for SETUP.C and execute
345 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
346 printf("*******************************\n");
347 printf("*** Setup PAR archive ***\n");
348 cout<<pararchivename<<endl;
349 printf("*******************************\n");
350 gROOT->Macro("PROOF-INF/SETUP.C");
351 }
352
353 gSystem->ChangeDirectory(ocwd.Data());
354 printf("Current dir: %s\n", ocwd.Data());
355}
356
357
358// Helper macros for creating chains
359// from: CreateESDChain.C,v 1.10 jgrosseo Exp
360
361TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
362{
363 // creates chain of files in a given directory or file containing a list.
364 // In case of directory the structure is expected as:
365 // <aDataDir>/<dir0>/AliESDs.root
366 // <aDataDir>/<dir1>/AliESDs.root
367 // ...
368
369 if (!aDataDir)
370 return 0;
371
372 Long_t id, size, flags, modtime;
373 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
374 {
375 printf("%s not found.\n", aDataDir);
376 return 0;
377 }
378
379 TChain* chain = new TChain("esdTree");
380 TChain* chaingAlice = 0;
381
382 if (flags & 2)
383 {
384 TString execDir(gSystem->pwd());
385 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
386 TList* dirList = baseDir->GetListOfFiles();
387 Int_t nDirs = dirList->GetEntries();
388 gSystem->cd(execDir);
389
390 Int_t count = 0;
391
392 for (Int_t iDir=0; iDir<nDirs; ++iDir)
393 {
394 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
395 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
396 continue;
397
398 if (offset > 0)
399 {
400 --offset;
401 continue;
402 }
403
404 if (count++ == aRuns)
405 break;
406
407 TString presentDirName(aDataDir);
408 presentDirName += "/";
409 presentDirName += presentDir->GetName();
410 chain->Add(presentDirName + "/AliESDs.root/esdTree");
411 // cerr<<presentDirName<<endl;
412 }
413
414 }
415 else
416 {
417 // Open the input stream
418 ifstream in;
419 in.open(aDataDir);
420
421 Int_t count = 0;
422
423 // Read the input list of files and add them to the chain
424 TString esdfile;
425 while(in.good()) {
426 in >> esdfile;
427 if (!esdfile.Contains("root")) continue; // protection
428
429 if (offset > 0)
430 {
431 --offset;
432 continue;
433 }
434
435 if (count++ == aRuns)
436 break;
437
438 // add esd file
439 chain->Add(esdfile);
440 }
441
442 in.close();
443 }
444
445 return chain;
446}
447
448
449// Helper macros for creating chains
450// from: CreateESDChain.C,v 1.10 jgrosseo Exp
451
452TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
453{
454 // creates chain of files in a given directory or file containing a list.
455 // In case of directory the structure is expected as:
456 // <aDataDir>/<dir0>/AliAOD.root
457 // <aDataDir>/<dir1>/AliAOD.root
458 // ...
459
460 if (!aDataDir)
461 return 0;
462
463 Long_t id, size, flags, modtime;
464 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
465 {
466 printf("%s not found.\n", aDataDir);
467 return 0;
468 }
469
470 TChain* chain = new TChain("aodTree");
471 TChain* chaingAlice = 0;
472
473 if (flags & 2)
474 {
475 TString execDir(gSystem->pwd());
476 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
477 TList* dirList = baseDir->GetListOfFiles();
478 Int_t nDirs = dirList->GetEntries();
479 gSystem->cd(execDir);
480
481 Int_t count = 0;
482
483 for (Int_t iDir=0; iDir<nDirs; ++iDir)
484 {
485 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
486 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
487 continue;
488
489 if (offset > 0)
490 {
491 --offset;
492 continue;
493 }
494
495 if (count++ == aRuns)
496 break;
497
498 TString presentDirName(aDataDir);
499 presentDirName += "/";
500 presentDirName += presentDir->GetName();
501 chain->Add(presentDirName + "/AliAOD.root/aodTree");
502 // cerr<<presentDirName<<endl;
503 }
504
505 }
506 else
507 {
508 // Open the input stream
509 ifstream in;
510 in.open(aDataDir);
511
512 Int_t count = 0;
513
514 // Read the input list of files and add them to the chain
515 TString aodfile;
516 while(in.good()) {
517 in >> aodfile;
518 if (!aodfile.Contains("root")) continue; // protection
519
520 if (offset > 0)
521 {
522 --offset;
523 continue;
524 }
525
526 if (count++ == aRuns)
527 break;
528
529 // add aod file
530 chain->Add(aodfile);
531 }
532
533 in.close();
534 }
535
536 return chain;
537}
538