]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FLOW/macros/runFlowTaskCentralityTrain.C
typo O instead of 0
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTaskCentralityTrain.C
CommitLineData
5c09ff70 1enum anaModes {mLocal,mLocalPAR,mPROOF,mGrid,mGridPAR};
daf66719 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
6// (Remark: When using this mode set also Bool_t bUseParFiles = kFALSE; in CreateAlienHandler.C)
7//mGridPAR: Analyze files on Grid via AliEn plug-in and using par files for FLOW package
8// (Remark: when using this mode set also Bool_t bUseParFiles = kTRUE; in CreateAlienHandler.C)
9
10// CENTRALITY DEFINITION
27b5ccf2 11const Int_t numberOfCentralityBins = 1;
b785c4e7 12Int_t centralityArray[numberOfCentralityBins+1] = {0,1000000}; // in terms of reference multiplicity
5c09ff70 13TString commonOutputFileName = "outputCentrality"; // e.g.: result for centrality bin 0 will be in the file "outputCentrality0.root", etc
daf66719 14
8544d490 15//void runFlowTaskCentralityTrain(Int_t mode=mLocal, Int_t nRuns = 10,
16//Bool_t DATA = kFALSE, const Char_t* dataDir="/Users/snelling/alice_data/Therminator_midcentral", Int_t offset = 0)
daf66719 17
b785c4e7 18void runFlowTaskCentralityTrain(Int_t mode = mPROOF, Int_t nRuns = 50000000,
19 Bool_t DATA = kTRUE, const Char_t* dataDir="/alice/data/LHC10h_000137045_p1", Int_t offset=0)
daf66719 20
b785c4e7 21//void runFlowTaskCentralityTrain(Int_t mode = mGrid, Bool_t DATA = kTRUE)
daf66719 22{
5c09ff70 23 // Time:
daf66719 24 TStopwatch timer;
25 timer.Start();
5c09ff70 26 // Cross-check user settings before starting:
d178bd1f 27 // CrossCheckUserSettings(DATA);
5c09ff70 28 // Load needed libraries:
daf66719 29 LoadLibraries(mode);
5c09ff70 30 // Create and configure the AliEn plug-in:
31 if(mode == mGrid || mode == mGridPAR)
d178bd1f 32 {
33 gROOT->LoadMacro("CreateAlienHandler.C");
34 AliAnalysisGrid *alienHandler = CreateAlienHandler();
35 if(!alienHandler) return;
36 }
5c09ff70 37 // Chains:
d178bd1f 38 if(mode == mLocal || mode == mLocalPAR) {
39 TChain* chain = CreateESDChain(dataDir, nRuns, offset);
40 //TChain* chain = CreateAODChain(dataDir, nRuns, offset);
59dab33a 41 }
42
5c09ff70 43 // Create analysis manager:
44 AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
45 // Connect plug-in to the analysis manager:
46 if(mode == mGrid || mode == mGridPAR)
d178bd1f 47 {
48 mgr->SetGridHandler(alienHandler);
49 }
50
5c09ff70 51 // Event handlers:
d178bd1f 52 AliVEventHandler* esdH = new AliESDInputHandler;
53 mgr->SetInputEventHandler(esdH);
54 AliMCEventHandler *mc = new AliMCEventHandler();
55 mgr->SetMCtruthEventHandler(mc);
56
5c09ff70 57 // Load the analysis task:
59dab33a 58 gROOT->LoadMacro("AddTaskFlowCentrality.C");
d178bd1f 59
5c09ff70 60 // Setup analysis per centrality bin:
daf66719 61 for (Int_t i=0; i<numberOfCentralityBins; i++)
62 {
63 Int_t lowCentralityBinEdge = centralityArray[i];
64 Int_t highCentralityBinEdge = centralityArray[i+1];
5c09ff70 65 TString filename(commonOutputFileName.Data());
daf66719 66 filename += i;
67 //TDirectory* dir = new TDirectory(filename.Data(),"");
68 filename += ".root";
5c09ff70 69 Printf("\nWagon for centrality bin %i:",i);
d178bd1f 70 AddTaskFlowCentrality( lowCentralityBinEdge,
daf66719 71 highCentralityBinEdge,
72 filename );
5c09ff70 73
74 } // end of for (Int_t i=0; i<numberOfCentralityBins; i++)
d178bd1f 75
5c09ff70 76 // Task to check the offline trigger:
d178bd1f 77 if(mode == mLocal || mode == mGrid || mode == mGridPAR) {
78 gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
79 } else if(mode == mPROOF || mode == mLocalPAR) {
80 gROOT->LoadMacro("AddTaskPhysicsSelection.C");
81 }
82
daf66719 83 AliPhysicsSelectionTask* physicsSelTask = AddTaskPhysicsSelection();
cd6a8858 84 physicsSelTask->GetPhysicsSelection()->AddCollisionTriggerClass("+C0SM1-B-NOPF-ALL");
4171022c 85 physicsSelTask->GetPhysicsSelection()->AddCollisionTriggerClass("+C0VBA-B-NOPF-ALL");
86 physicsSelTask->GetPhysicsSelection()->AddCollisionTriggerClass("+C0VBC-B-NOPF-ALL");
8544d490 87
5c09ff70 88 if(!DATA){physicsSelTask->GetPhysicsSelection()->SetAnalyzeMC();}
89 // Enable debug printouts:
daf66719 90 mgr->SetDebugLevel(2);
5c09ff70 91 // Run the analysis:
92 if(!mgr->InitAnalysis()) return;
daf66719 93 mgr->PrintStatus();
d178bd1f 94 if(mode == mLocal || mode == mLocalPAR) {
95 mgr->StartAnalysis("local",chain);
96 } else if(mode == mPROOF) {
97 mgr->StartAnalysis("proof",dataDir,nRuns,offset);
98 } else if(mode == mGrid || mode == mGridPAR) {
99 mgr->StartAnalysis("grid");
100 }
101
5c09ff70 102 // Print real and CPU time used for analysis:
daf66719 103 timer.Stop();
5c09ff70 104 timer.Print();
daf66719 105
5c09ff70 106} // end of void runFlowTaskCentralityTrain(...)
107
108//===============================================================================================
d178bd1f 109/*
daf66719 110void CrossCheckUserSettings(Bool_t bData)
111{
d178bd1f 112 // Check in this method if the user settings make sense.
5c09ff70 113 if(LYZ1SUM && LYZ2SUM) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
114 if(LYZ1PROD && LYZ2PROD) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
115 if(LYZ2SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
116 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 117} // end of void CrossCheckUserSettings()
d178bd1f 118*/
5c09ff70 119//===============================================================================================
120
121void LoadLibraries(const anaModes mode)
122{
daf66719 123 //--------------------------------------
124 // Load the needed libraries most of them already loaded by aliroot
125 //--------------------------------------
5c09ff70 126 //gSystem->Load("libTree");
daf66719 127 gSystem->Load("libGeom");
128 gSystem->Load("libVMC");
129 gSystem->Load("libXMLIO");
130 gSystem->Load("libPhysics");
131
132 //----------------------------------------------------------
133 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
134 //----------------------------------------------------------
5c09ff70 135 if (mode==mLocal || mode==mGrid || mode == mGridPAR) {
daf66719 136 //--------------------------------------------------------
137 // If you want to use already compiled libraries
138 // in the aliroot distribution
139 //--------------------------------------------------------
140 gSystem->Load("libSTEERBase");
141 gSystem->Load("libESD");
142 gSystem->Load("libAOD");
143 gSystem->Load("libANALYSIS");
144 gSystem->Load("libANALYSISalice");
145 gSystem->Load("libCORRFW");
146 gSystem->Load("libPWG2forward");
5c09ff70 147 if(mode==mLocal || mode==mGrid)
148 {
149 gSystem->Load("libPWG2flowCommon");
150 cerr<<"libPWG2flowCommon loaded..."<<endl;
151 gSystem->Load("libPWG2flowTasks");
152 cerr<<"libPWG2flowTasks loaded..."<<endl;
daf66719 153 }
5c09ff70 154 if(mode==mGridPAR)
155 {
156 SetupPar("PWG2flowCommon");
157 cerr<<"PWG2flowCommon.par loaded..."<<endl;
158 SetupPar("PWG2flowTasks");
159 cerr<<"PWG2flowTasks.par loaded..."<<endl;
daf66719 160 }
161 }
162
163 else if (mode == mLocalPAR) {
164 //--------------------------------------------------------
165 //If you want to use root and par files from aliroot
166 //--------------------------------------------------------
167 SetupPar("STEERBase");
168 SetupPar("ESD");
169 SetupPar("AOD");
170 SetupPar("ANALYSIS");
171 SetupPar("ANALYSISalice");
8544d490 172 SetupPar("CORRFW");
daf66719 173 SetupPar("PWG2flowCommon");
174 cerr<<"PWG2flowCommon.par loaded..."<<endl;
175 SetupPar("PWG2flowTasks");
176 cerr<<"PWG2flowTasks.par loaded..."<<endl;
177 }
178
179 //---------------------------------------------------------
180 // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
181 //---------------------------------------------------------
182 else if (mode==mPROOF) {
daf66719 183 // set to debug root versus if needed
184 //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a_dbg");
185 //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a");
186 //TProof::Reset("proof://snelling@alicecaf.cern.ch");
187 // Connect to proof
188 printf("*** Connect to PROOF ***\n");
189 gEnv->SetValue("XSec.GSI.DelegProxy","2");
daf66719 190 TProof::Open("alice-caf.cern.ch");
191 //TProof::Open("skaf.saske.sk");
8544d490 192 // list the data available
daf66719 193 //gProof->ShowDataSets("/*/*");
194 //gProof->ShowDataSets("/alice/sim/"); //for MC Data
195 //gProof->ShowDataSets("/alice/data/"); //for REAL Data
196
197 // Clear the Packages
8544d490 198 /*
daf66719 199 gProof->ClearPackage("STEERBase.par");
200 gProof->ClearPackage("ESD.par");
201 gProof->ClearPackage("AOD.par");
b785c4e7 202 */
daf66719 203 gProof->ClearPackage("ANALYSIS.par");
204 gProof->ClearPackage("ANALYSISalice.par");
205 gProof->ClearPackage("CORRFW.par");
206
207 gProof->ClearPackage("PWG2flowCommon");
208 gProof->ClearPackage("PWG2flowTasks");
b785c4e7 209
daf66719 210 // Upload the Packages
b785c4e7 211 //gProof->UploadPackage("STEERBase.par");
212 //gProof->UploadPackage("ESD.par");
213 //gProof->UploadPackage("AOD.par");
daf66719 214
215 gProof->UploadPackage("ANALYSIS.par");
216 gProof->UploadPackage("ANALYSISalice.par");
217 gProof->UploadPackage("CORRFW.par");
218 gProof->UploadPackage("PWG2flowCommon.par");
219 gProof->UploadPackage("PWG2flowTasks.par");
220
221 // Enable the Packages
222 // The global package
b785c4e7 223 gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-04-AN");
daf66719 224 //gProof->EnablePackage("aliroot_v4-19-05-AN",kTRUE);
225 // Or separate
226
b785c4e7 227 //gProof->EnablePackage("STEERBase");
228 //gProof->EnablePackage("ESD");
229 //gProof->EnablePackage("AOD");
daf66719 230
231 // Always needed
232 gProof->EnablePackage("ANALYSIS");
233 gProof->EnablePackage("ANALYSISalice");
234 gProof->EnablePackage("CORRFW");
235 gProof->EnablePackage("PWG2flowCommon");
236 gProof->EnablePackage("PWG2flowTasks");
237
238 // Show enables Packages
239 gProof->ShowEnabledPackages();
240 }
241
5c09ff70 242} // end of void LoadLibraries(const anaModes mode)
243
244//===============================================================================================
daf66719 245
5c09ff70 246void SetupPar(char* pararchivename)
247{
daf66719 248 //Load par files, create analysis libraries
249 //For testing, if par file already decompressed and modified
250 //classes then do not decompress.
251
252 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
253 TString parpar(Form("%s.par", pararchivename)) ;
254 if ( gSystem->AccessPathName(parpar.Data()) ) {
255 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
256 TString processline(Form(".! make %s", parpar.Data())) ;
257 gROOT->ProcessLine(processline.Data()) ;
258 gSystem->ChangeDirectory(cdir) ;
259 processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
260 gROOT->ProcessLine(processline.Data()) ;
261 }
262 if ( gSystem->AccessPathName(pararchivename) ) {
263 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
264 gROOT->ProcessLine(processline.Data());
265 }
266
267 TString ocwd = gSystem->WorkingDirectory();
268 gSystem->ChangeDirectory(pararchivename);
269
270 // check for BUILD.sh and execute
271 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
272 printf("*******************************\n");
273 printf("*** Building PAR archive ***\n");
274 cout<<pararchivename<<endl;
275 printf("*******************************\n");
276 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
277 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
278 return -1;
279 }
280 }
281 // check for SETUP.C and execute
282 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
283 printf("*******************************\n");
284 printf("*** Setup PAR archive ***\n");
285 cout<<pararchivename<<endl;
286 printf("*******************************\n");
287 gROOT->Macro("PROOF-INF/SETUP.C");
288 }
289
290 gSystem->ChangeDirectory(ocwd.Data());
291 printf("Current dir: %s\n", ocwd.Data());
daf66719 292
5c09ff70 293} // end of void SetupPar(char* pararchivename)
294
295//===============================================================================================
daf66719 296
297// Helper macros for creating chains
298// from: CreateESDChain.C,v 1.10 jgrosseo Exp
299
300TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
301{
302 // creates chain of files in a given directory or file containing a list.
303 // In case of directory the structure is expected as:
304 // <aDataDir>/<dir0>/AliESDs.root
305 // <aDataDir>/<dir1>/AliESDs.root
306 // ...
307
308 if (!aDataDir)
309 return 0;
310
311 Long_t id, size, flags, modtime;
312 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
313 {
314 printf("%s not found.\n", aDataDir);
315 return 0;
316 }
317
318 TChain* chain = new TChain("esdTree");
319 TChain* chaingAlice = 0;
320
321 if (flags & 2)
322 {
323 TString execDir(gSystem->pwd());
324 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
325 TList* dirList = baseDir->GetListOfFiles();
326 Int_t nDirs = dirList->GetEntries();
327 gSystem->cd(execDir);
328
329 Int_t count = 0;
330
331 for (Int_t iDir=0; iDir<nDirs; ++iDir)
332 {
333 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
334 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
335 continue;
336
337 if (offset > 0)
338 {
339 --offset;
340 continue;
341 }
342
343 if (count++ == aRuns)
344 break;
345
346 TString presentDirName(aDataDir);
347 presentDirName += "/";
348 presentDirName += presentDir->GetName();
349 chain->Add(presentDirName + "/AliESDs.root/esdTree");
350 // cerr<<presentDirName<<endl;
351 }
352
353 }
354 else
355 {
356 // Open the input stream
357 ifstream in;
358 in.open(aDataDir);
359
360 Int_t count = 0;
361
362 // Read the input list of files and add them to the chain
363 TString esdfile;
364 while(in.good()) {
365 in >> esdfile;
366 if (!esdfile.Contains("root")) continue; // protection
367
368 if (offset > 0)
369 {
370 --offset;
371 continue;
372 }
373
374 if (count++ == aRuns)
375 break;
376
377 // add esd file
378 chain->Add(esdfile);
379 }
380
381 in.close();
382 }
383
384 return chain;
daf66719 385
5c09ff70 386} // end of TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
daf66719 387
5c09ff70 388//===============================================================================================
daf66719 389
390TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
391{
392 // creates chain of files in a given directory or file containing a list.
393 // In case of directory the structure is expected as:
394 // <aDataDir>/<dir0>/AliAOD.root
395 // <aDataDir>/<dir1>/AliAOD.root
396 // ...
397
398 if (!aDataDir)
399 return 0;
400
401 Long_t id, size, flags, modtime;
402 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
403 {
404 printf("%s not found.\n", aDataDir);
405 return 0;
406 }
407
408 TChain* chain = new TChain("aodTree");
409 TChain* chaingAlice = 0;
410
411 if (flags & 2)
412 {
413 TString execDir(gSystem->pwd());
414 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
415 TList* dirList = baseDir->GetListOfFiles();
416 Int_t nDirs = dirList->GetEntries();
417 gSystem->cd(execDir);
418
419 Int_t count = 0;
420
421 for (Int_t iDir=0; iDir<nDirs; ++iDir)
422 {
423 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
424 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
425 continue;
426
427 if (offset > 0)
428 {
429 --offset;
430 continue;
431 }
432
433 if (count++ == aRuns)
434 break;
435
436 TString presentDirName(aDataDir);
437 presentDirName += "/";
438 presentDirName += presentDir->GetName();
439 chain->Add(presentDirName + "/AliAOD.root/aodTree");
440 // cerr<<presentDirName<<endl;
441 }
442
443 }
444 else
445 {
446 // Open the input stream
447 ifstream in;
448 in.open(aDataDir);
449
450 Int_t count = 0;
451
452 // Read the input list of files and add them to the chain
453 TString aodfile;
454 while(in.good()) {
455 in >> aodfile;
456 if (!aodfile.Contains("root")) continue; // protection
457
458 if (offset > 0)
459 {
460 --offset;
461 continue;
462 }
463
464 if (count++ == aRuns)
465 break;
466
467 // add aod file
468 chain->Add(aodfile);
469 }
470
471 in.close();
472 }
473
474 return chain;
5c09ff70 475
476} // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
daf66719 477