1 #include "TStopwatch.h"
6 //--------------------------------------------------------------------------------------
8 //flow analysis method can be: (set to kTRUE or kFALSE)
12 Bool_t LYZEP = kFALSE;
16 Bool_t MCEP = kFALSE; //does not work yet 24/12/08
17 //--------------------------------------------------------------------------------------
20 // Use weights for Q vector
21 Bool_t usePhiWeights = kFALSE; //Phi (correction for non-uniform azimuthal acceptance)
22 Bool_t usePtWeights = kFALSE; //v'(pt) (differential flow in pt)
23 Bool_t useEtaWeights = kFALSE; //v'(eta) (differential flow in eta)
25 //--------------------------------------------------------------------------------------
27 //integrated selection
28 Double_t ptMaxInt = 10.;
29 Double_t ptMinInt = 0.;
30 Double_t etaMaxInt = 1.;
31 Double_t etaMinInt = -1.;
32 Double_t phiMaxInt = 7.5;
33 Double_t phiMinInt = 0.;
36 //differential selection
37 Double_t ptMaxDiff = 10.;
38 Double_t ptMinDiff = 0.;
39 Double_t etaMaxDiff = 1.;
40 Double_t etaMinDiff = -1.;
41 Double_t phiMaxDiff = 7.5;
42 Double_t phiMinDiff = 0.;
44 //--------------------------------------------------------------------------------------
46 enum anaModes {mLocal,mLocalSource,mLocalPAR,};
47 //mLocal: Analyze data on your computer using aliroot
48 //mLocalPAR: Analyze data on your computer using root + PAR files
49 //mLocalSource: Analyze data on your computer using root + source files
55 int runFlowAnalysis(Int_t mode=mLocal, Int_t aRuns = 100, const char*
56 // dir="/data/alice1/kolk/KineOnly3/")
57 dir="/Users/snelling/alice_data/KineOnly3/")
62 if (LYZ1 && LYZ2) {cout<<"WARNING: you cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1."<<endl; exit(); }
63 if (LYZ2 && LYZEP) {cout<<"WARNING: you cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2."<<endl; exit(); }
64 if (LYZ1 && LYZEP) {cout<<"WARNING: you cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2."<<endl; exit(); }
68 cout<<" ---- BEGIN ANALYSIS ---- "<<endl;
73 if (mode == mLocal || mode == mLocalPAR) {
74 // AliFlow event in aliroot or with pars
75 AliFlowEventSimpleMaker* fEventMaker = new AliFlowEventSimpleMaker();
77 else if (mode == mLocalSource) {
78 // flow event in source mode
79 FlowEventSimpleMaker* fEventMaker = new FlowEventSimpleMaker();
82 cout << "No supported running mode selected!" << endl;
87 //------------------------------------------------------------------------
89 AliFlowTrackSimpleCuts* cutsInt = new AliFlowTrackSimpleCuts();
90 cutsInt->SetPtMax(ptMaxInt);
91 cutsInt->SetPtMin(ptMinInt);
92 cutsInt->SetEtaMax(etaMaxInt);
93 cutsInt->SetEtaMin(etaMinInt);
94 cutsInt->SetPhiMax(phiMaxInt);
95 cutsInt->SetPhiMin(phiMinInt);
96 cutsInt->SetPID(PIDInt);
98 AliFlowTrackSimpleCuts* cutsDiff = new AliFlowTrackSimpleCuts();
99 cutsDiff->SetPtMax(ptMaxDiff);
100 cutsDiff->SetPtMin(ptMinDiff);
101 cutsDiff->SetEtaMax(etaMaxDiff);
102 cutsDiff->SetEtaMin(etaMinDiff);
103 cutsDiff->SetPhiMax(phiMaxDiff);
104 cutsDiff->SetPhiMin(phiMinDiff);
105 cutsDiff->SetPID(PIDDiff);
107 //if the weights are used:
108 TFile *fileWithWeights = NULL;
109 TList *listWithWeights = NULL;
111 if(usePhiWeights||usePtWeights||useEtaWeights) {
112 fileWithWeights = TFile::Open("weights.root","READ");
113 if(fileWithWeights) {
114 listWithWeights = (TList*)fileWithWeights->Get("weights");
117 {cout << " WARNING: the file <weights.root> with weights from the previous run was not found."<<endl;
123 AliFlowAnalysisWithQCumulants *qc = NULL;
124 AliFlowAnalysisWithCumulants *gfc = NULL;
125 AliFittingQDistribution *fqd = NULL;
126 AliFlowAnalysisWithLeeYangZeros *lyz1 = NULL;
127 AliFlowAnalysisWithLeeYangZeros *lyz2 = NULL;
128 AliFlowAnalysisWithLYZEventPlane *lyzep = NULL;
129 AliFlowAnalysisWithScalarProduct *sp = NULL;
130 AliFlowAnalysisWithMCEventPlane *mcep = NULL;
132 //MCEP = monte carlo event plane
134 AliFlowAnalysisWithMCEventPlane *mcep = new AliFlowAnalysisWithMCEventPlane();
140 AliFlowAnalysisWithQCumulants* qc = new AliFlowAnalysisWithQCumulants();
142 if(listWithWeights) qc->SetWeightsList(listWithWeights);
143 if(usePhiWeights) qc->SetUsePhiWeights(usePhiWeights);
144 if(usePtWeights) qc->SetUsePtWeights(usePtWeights);
145 if(useEtaWeights) qc->SetUseEtaWeights(useEtaWeights);
148 //GFC = Generating Function Cumulants
150 AliFlowAnalysisWithCumulants* gfc = new AliFlowAnalysisWithCumulants();
152 if(listWithWeights) gfc->SetWeightsList(listWithWeights);
153 if(usePhiWeights) gfc->SetUsePhiWeights(usePhiWeights);
154 if(usePtWeights) gfc->SetUsePtWeights(usePtWeights);
155 if(useEtaWeights) gfc->SetUseEtaWeights(useEtaWeights);
158 //FQD = Fitting q-distribution
160 AliFittingQDistribution* fqd = new AliFittingQDistribution();
162 if(listWithWeights) fqd->SetWeightsList(listWithWeights);
163 if(usePhiWeights) fqd->SetUsePhiWeights(usePhiWeights);
166 //SP = Scalar Product
168 AliFlowAnalysisWithScalarProduct* sp = new AliFlowAnalysisWithScalarProduct();
172 //LYZ1 = Lee-Yang Zeroes first run
174 AliFlowAnalysisWithLeeYangZeros* lyz1 = new AliFlowAnalysisWithLeeYangZeros();
175 lyz1->SetFirstRun(kTRUE);
176 lyz1->SetUseSum(kTRUE);
180 //LYZ2 = Lee-Yang Zeroes second run
182 AliFlowAnalysisWithLeeYangZeros* lyz2 = new AliFlowAnalysisWithLeeYangZeros();
183 // read the input file from the first run
184 TString inputFileNameLYZ2 = "outputLYZ1analysis.root" ;
185 TFile* inputFileLYZ2 = new TFile(inputFileNameLYZ2.Data(),"READ");
186 if(!inputFileLYZ2 || inputFileLYZ2->IsZombie()) {
187 cerr << " ERROR: NO First Run file... " << endl ;
191 TList* inputListLYZ2 = (TList*)inputFileLYZ2->Get("cobjLYZ1");
192 if (!inputListLYZ2) {cout<<"Input list is NULL pointer!"<<endl; break;}
194 cout<<"LYZ2 input file/list read..."<<endl;
195 lyz2->SetFirstRunList(inputListLYZ2);
196 lyz2->SetFirstRun(kFALSE);
197 lyz2->SetUseSum(kTRUE);
203 //LYZEP = Lee-Yang Zeroes event plane
205 AliFlowLYZEventPlane* ep = new AliFlowLYZEventPlane() ;
206 AliFlowAnalysisWithLYZEventPlane* lyzep = new AliFlowAnalysisWithLYZEventPlane();
207 // read the input file from the second lyz run
208 TString inputFileNameLYZEP = "outputLYZ2analysis.root" ;
209 TFile* inputFileLYZEP = new TFile(inputFileNameLYZEP.Data(),"READ");
210 if(!inputFileLYZEP || inputFileLYZEP->IsZombie()) {
211 cerr << " ERROR: NO Second Run file... " << endl ;
215 TList* inputListLYZEP = (TList*)inputFileLYZEP->Get("cobjLYZ2");
216 if (!inputListLYZEP) {cout<<"Input list is NULL pointer!"<<endl; break;}
218 cout<<"LYZEP input file/list read..."<<endl;
219 ep ->SetSecondRunList(inputListLYZEP);
220 lyzep->SetSecondRunList(inputListLYZEP);
226 //------------------------------------------------------------------------
231 TString execDir(gSystem->pwd());
232 TString targetDir(dir);
233 TSystemDirectory* baseDir = new TSystemDirectory(".", dir);
234 TList* dirList = baseDir->GetListOfFiles();
236 cout << endl << "No input files in: " << targetDir.Data() << endl;
239 Int_t nDirs = dirList->GetEntries();
241 cout<<"Int_t nDirs = "<<nDirs<<endl;
242 gSystem->cd(execDir);
244 for(Int_t iDir=0;iDir<nDirs;++iDir)
246 TSystemFile* presentDir = (TSystemFile*)dirList->At(iDir);
247 if(!presentDir || !presentDir->IsDirectory() ||
248 strcmp(presentDir->GetName(), ".") == 0 ||
249 strcmp(presentDir->GetName(), "..") == 0)
252 cout << "Directory (" << iDir << "): " << presentDir->GetName() <<
253 " - Skipping ... " << endl;
257 if(offset > 0) { --offset ; continue ; }
258 if((aRuns > 0) && (fCount >= aRuns)) { break ; }
260 TString presentDirName(dir); // aDataDir
261 presentDirName += presentDir->GetName();
262 presentDirName += "/";
263 //cerr<<" presentDirName = "<<presentDirName<<endl;
265 TString fileName = presentDirName;
266 fileName += "galice.root";
267 Long_t *id, *size, *flags, *modtime;
268 if(gSystem->GetPathInfo(fileName.Data(),id,size,flags,modtime))
270 cout << " File : " << fileName << " does NOT exist ! - Skipping ... "
274 // cout << endl ; cout << "Directory (" << iDir << "): " << presentDirName << " ... " << endl;
276 //loop (simulations in the present dir)
277 TSystemDirectory* evtsDir = new TSystemDirectory(".",
278 presentDirName.Data());
279 TList* fileList = evtsDir->GetListOfFiles();
280 Int_t nFiles = fileList->GetEntries();
281 //cout<<" Int_t nFiles = "<<nFiles<<endl;
282 gSystem->cd(execDir);
283 for(Int_t iFiles=0; iFiles<nFiles; ++iFiles)
285 TSystemFile* presentFile = (TSystemFile*) fileList->At(iFiles);
286 TString presentFileName(presentDirName);
287 presentFileName += presentFile->GetName();
289 if(!(presentFileName.Contains("Kinematics") &&
290 presentFileName.Contains("root"))) { continue ; }
292 //cout << " found: " << presentFileName.Data() << endl;
294 TFile* kineFile = new TFile(presentFileName.Data(), "READ");
296 Int_t nEvts = kineFile->GetNkeys() ;
297 //cout << " . found: " << nEvts << " KineTree(s) in " << presentFileName.Data() << endl;
298 TList* kineEventsList = (TList*)kineFile->GetListOfKeys();
300 TIter next(kineEventsList);
303 //loop over the events
304 while( key=(TKey *)next() )
306 TDirectory* tDir = (TDirectory*)key->ReadObj();
309 TString evtDir(tDir->GetName());
310 //cout << " . . found: " << tDir->GetName() << endl;
312 kTree = (TTree *)tDir->Get("TreeK");
315 Int_t nPart = kTree->GetEntries();
316 //cout << " . . . kTree " << fCount << " has " << nPart << " particles " << endl;
318 //-----------------------------------------------------------
319 //fill and save the flow event
320 AliFlowEventSimple *fEvent = fEventMaker->FillTracks(kTree, cutsInt, cutsDiff);
322 if(MCEP) mcep->Make(fEvent);
323 if(QC) qc->Make(fEvent);
324 if(GFC) gfc->Make(fEvent);
325 if(FQD) fqd->Make(fEvent);
326 if(LYZ1) lyz1->Make(fEvent);
327 if(LYZ2) lyz2->Make(fEvent);
328 if(LYZEP) lyzep->Make(fEvent,ep);
329 if(SP) sp->Make(fEvent);
330 //-----------------------------------------------------------
332 //cout << "# " << fCount << " events processed" << endl;
341 //--------------------------------------------------------------
342 //calculating and storing the final results of flow analysis
343 if(MCEP) {mcep->Finish(); mcep->WriteHistograms("outputMCEPanalysis.root");}
344 if(SP) {sp->Finish(); sp->WriteHistograms("outputSPanalysis.root");}
345 if(QC) {qc->Finish(); qc->WriteHistograms("outputQCanalysis.root");}
346 if(GFC) {gfc->Finish(); gfc->WriteHistograms("outputGFCanalysis.root");}
347 if(FQD) {fqd->Finish(); fqd->WriteHistograms("outputFQDanalysis.root");}
348 if(LYZ1) {lyz1->Finish(); lyz1->WriteHistograms("outputLYZ1analysis.root");}
349 if(LYZ2) {lyz2->Finish(); lyz2->WriteHistograms("outputLYZ2analysis.root");}
350 if(LYZEP) {lyzep->Finish(); lyzep->WriteHistograms("outputLYZEPanalysis.root");}
352 //--------------------------------------------------------------
355 cout << " Fini ... " << endl;
363 void SetupPar(char* pararchivename)
365 //Load par files, create analysis libraries
366 //For testing, if par file already decompressed and modified
367 //classes then do not decompress.
369 TString cdir(Form("%s", gSystem->WorkingDirectory() )) ;
370 TString parpar(Form("%s.par", pararchivename)) ;
371 if ( gSystem->AccessPathName(parpar.Data()) ) {
372 gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
373 TString processline(Form(".! make %s", parpar.Data())) ;
374 gROOT->ProcessLine(processline.Data()) ;
375 gSystem->ChangeDirectory(cdir) ;
376 processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
377 gROOT->ProcessLine(processline.Data()) ;
379 if ( gSystem->AccessPathName(pararchivename) ) {
380 TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
381 gROOT->ProcessLine(processline.Data());
384 TString ocwd = gSystem->WorkingDirectory();
385 gSystem->ChangeDirectory(pararchivename);
387 // check for BUILD.sh and execute
388 if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
389 printf("*******************************\n");
390 printf("*** Building PAR archive ***\n");
391 cout<<pararchivename<<endl;
392 printf("*******************************\n");
394 if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
395 Error("runProcess","Cannot Build the PAR Archive! - Abort!");
399 // check for SETUP.C and execute
400 if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
401 printf("*******************************\n");
402 printf("*** Setup PAR archive ***\n");
403 cout<<pararchivename<<endl;
404 printf("*******************************\n");
405 gROOT->Macro("PROOF-INF/SETUP.C");
408 gSystem->ChangeDirectory(ocwd.Data());
409 printf("Current dir: %s\n", ocwd.Data());
412 void LoadLibraries(const anaModes mode) {
414 //--------------------------------------
415 // Load the needed libraries most of them already loaded by aliroot
416 //--------------------------------------
417 gSystem->Load("libTree.so");
418 gSystem->Load("libGeom.so");
419 gSystem->Load("libVMC.so");
420 gSystem->Load("libXMLIO.so");
421 gSystem->Load("libPhysics.so");
423 //----------------------------------------------------------
424 // >>>>>>>>>>> Local mode <<<<<<<<<<<<<<
425 //----------------------------------------------------------
427 //--------------------------------------------------------
428 // If you want to use already compiled libraries
429 // in the aliroot distribution
430 //--------------------------------------------------------
431 gSystem->Load("libSTEERBase");
432 gSystem->Load("libESD");
433 gSystem->Load("libAOD");
434 gSystem->Load("libANALYSIS");
435 gSystem->Load("libANALYSISalice");
436 gSystem->Load("libCORRFW.so");
437 cerr<<"libCORRFW.so loaded..."<<endl;
438 gSystem->Load("libPWG2flowCommon.so");
439 cerr<<"libPWG2flowCommon.so loaded..."<<endl;
440 gSystem->Load("libPWG2flowTasks.so");
441 cerr<<"libPWG2flowTasks.so loaded..."<<endl;
444 else if (mode == mLocalPAR) {
445 //--------------------------------------------------------
446 //If you want to use root and par files from aliroot
447 //--------------------------------------------------------
448 //If you want to use root and par files from aliroot
449 //--------------------------------------------------------
450 SetupPar("STEERBase");
453 SetupPar("ANALYSIS");
454 SetupPar("ANALYSISalice");
457 SetupPar("PWG2flowCommon");
458 cerr<<"PWG2flowCommon.par loaded..."<<endl;
459 SetupPar("PWG2flowTasks");
460 cerr<<"PWG2flowTasks.par loaded..."<<endl;
463 //---------------------------------------------------------
464 // <<<<<<<<<< Source mode >>>>>>>>>>>>
465 //---------------------------------------------------------
466 else if (mode==mLocalSource) {
468 // In root inline compile
472 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonConstants.cxx+");
473 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZConstants.cxx+");
474 gROOT->LoadMacro("AliFlowCommon/AliFlowCumuConstants.cxx+");
477 gROOT->LoadMacro("AliFlowCommon/AliFlowVector.cxx+");
478 gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimple.cxx+");
479 gROOT->LoadMacro("AliFlowCommon/AliFlowEventSimple.cxx+");
482 gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimpleCuts.cxx+");
484 // Output histosgrams
485 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHist.cxx+");
486 gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHistResults.cxx+");
487 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist1.cxx+");
488 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist2.cxx+");
490 // Functions needed for various methods
491 gROOT->LoadMacro("AliFlowCommon/AliCumulantsFunctions.cxx+");
492 gROOT->LoadMacro("AliFlowCommon/AliFittingFunctionsForQDistribution.cxx+");
493 gROOT->LoadMacro("AliFlowCommon/AliFlowLYZEventPlane.cxx+");
495 // Flow Analysis code for various methods
496 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithMCEventPlane.cxx+");
497 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithScalarProduct.cxx+");
498 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithLYZEventPlane.cxx+");
499 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithLeeYangZeros.cxx+");
500 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithCumulants.cxx+");
501 gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithQCumulants.cxx+");
502 gROOT->LoadMacro("AliFlowCommon/AliFittingQDistribution.cxx+");
504 // Class to fill the FlowEvent without aliroot dependence
505 // can be found in the directory FlowEventMakers
506 gROOT->LoadMacro("FlowEventMakers/FlowEventSimpleMaker.cxx+");
508 cout << "finished loading macros!" << endl;