]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/FLOW/macros/runFlowAnalysisOnTheFly.C
a798c337bb06f13469ec6bc176956d21ca52daca
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowAnalysisOnTheFly.C
1 #include "TStopwatch.h"
2 #include "TObjArray"
3 #include "Riostream.h"
4 #include "TFile.h"
5
6 //--------------------------------------------------------------------------------------
7 // RUN SETTINGS
8 // flow analysis method can be: (set to kTRUE or kFALSE)
9 Bool_t SP    = kFALSE;
10 Bool_t LYZ1  = kFALSE;
11 Bool_t LYZ2  = kFALSE;  
12 Bool_t LYZEP = kFALSE; 
13 Bool_t GFC   = kFALSE;
14 Bool_t QC    = kFALSE;
15 Bool_t FQD   = kFALSE;
16 Bool_t MCEP  = kTRUE; 
17 //--------------------------------------------------------------------------------------
18
19 //.................................................................................  
20
21 // Set the event parameters:
22 Int_t iMultiplicityOfRP = 4400; // multiplicity of RPs
23
24 //.................................................................................
25  
26
27
28 enum anaModes {mLocal,mLocalSource,mLocalPAR,};
29 // mLocal: Analyze data on your computer using aliroot
30 // mLocalPAR: Analyze data on your computer using root + PAR files
31 // mLocalSource: Analyze data on your computer using root + source files
32                                           
33 int runFlowAnalysisOnTheFly(Int_t mode=mLocal, Int_t nEvts=1)
34 {
35  TStopwatch timer;
36  timer.Start();
37  
38  if (LYZ1 && LYZ2)  {cout<<"WARNING: you cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1.  "<<endl; exit(); }
39  if (LYZ2 && LYZEP) {cout<<"WARNING: you cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2."<<endl; exit(); }
40  if (LYZ1 && LYZEP) {cout<<"WARNING: you cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2."<<endl; exit(); }
41  
42  cout<<endl;
43  cout<<endl;
44  cout<<"      ---- ARE YOU READY TO FLY ? ----      "<<endl;
45  cout<<endl;
46  
47  cout<<endl;
48  cout<<" ---- BEGIN FLOW ANALYSIS 'ON THE FLY' ---- "<<endl;
49  cout<<endl;
50  cout<<endl;
51  
52  
53  LoadLibraries(mode);
54
55  //---------------------------------------------------------------------------------------
56  // Initialize the flowevent maker
57  AliFlowEventSimpleMakerOnTheFly* eventMakerOnTheFly = new AliFlowEventSimpleMakerOnTheFly();
58   
59
60  //---------------------------------------------------------------------------------------
61  // Initialize all the flow methods:  
62  AliFlowAnalysisWithQCumulants    *qc    = NULL;
63  AliFlowAnalysisWithCumulants     *gfc   = NULL;
64  AliFittingQDistribution          *fqd   = NULL;
65  AliFlowAnalysisWithLeeYangZeros  *lyz1  = NULL;
66  AliFlowAnalysisWithLeeYangZeros  *lyz2  = NULL;
67  AliFlowAnalysisWithLYZEventPlane *lyzep = NULL;
68  AliFlowAnalysisWithScalarProduct *sp    = NULL;
69  AliFlowAnalysisWithMCEventPlane  *mcep  = NULL;   
70
71  // MCEP = monte carlo event plane
72  if (MCEP) {
73    AliFlowAnalysisWithMCEventPlane *mcep = new AliFlowAnalysisWithMCEventPlane();
74    mcep->Init();
75  }
76
77   // QC = Q-cumulants  
78  if(QC) { 
79    AliFlowAnalysisWithQCumulants* qc = new AliFlowAnalysisWithQCumulants();
80    qc->Init();
81  }
82   
83  // GFC = Generating Function Cumulants 
84  if(GFC) {
85    AliFlowAnalysisWithCumulants* gfc = new AliFlowAnalysisWithCumulants();
86    gfc->Init();
87  }
88  
89  // FQD = Fitting q-distribution 
90  if(FQD) {
91    AliFittingQDistribution* fqd = new AliFittingQDistribution();
92    fqd->Init();
93  }
94  
95  // SP = Scalar Product 
96  if(SP) {
97    AliFlowAnalysisWithScalarProduct* sp = new AliFlowAnalysisWithScalarProduct();
98    sp->Init();
99  }
100
101  // LYZ1 = Lee-Yang Zeroes first run
102  if(LYZ1) {
103    AliFlowAnalysisWithLeeYangZeros* lyz1 = new AliFlowAnalysisWithLeeYangZeros();
104    lyz1->SetFirstRun(kTRUE);
105    lyz1->SetUseSum(kTRUE);
106    lyz1->Init();
107  }
108
109  // LYZ2 = Lee-Yang Zeroes second run
110  if(LYZ2) {
111    AliFlowAnalysisWithLeeYangZeros* lyz2 = new AliFlowAnalysisWithLeeYangZeros();
112    // read the input file from the first run 
113    TString inputFileNameLYZ2 = "outputLYZ1analysis.root" ;
114    TFile* inputFileLYZ2 = new TFile(inputFileNameLYZ2.Data(),"READ");
115    if(!inputFileLYZ2 || inputFileLYZ2->IsZombie()) { 
116      cerr << " ERROR: NO First Run file... " << endl ;
117      break; 
118    }
119    else { 
120      TList* inputListLYZ2 = (TList*)inputFileLYZ2->Get("cobjLYZ1");  
121      if (!inputListLYZ2) {cout<<"Input list is NULL pointer!"<<endl; break;}
122      else {
123        cout<<"LYZ2 input file/list read..."<<endl;
124        lyz2->SetFirstRunList(inputListLYZ2);
125        lyz2->SetFirstRun(kFALSE);
126        lyz2->SetUseSum(kTRUE);
127        lyz2->Init();
128      }
129    }
130  }
131  
132  // LYZEP = Lee-Yang Zeroes event plane
133  if(LYZEP) {
134    AliFlowLYZEventPlane* ep = new AliFlowLYZEventPlane() ;
135    AliFlowAnalysisWithLYZEventPlane* lyzep = new AliFlowAnalysisWithLYZEventPlane();
136    // read the input file from the second lyz run 
137    TString inputFileNameLYZEP = "outputLYZ2analysis.root" ;
138    TFile* inputFileLYZEP = new TFile(inputFileNameLYZEP.Data(),"READ");
139    if(!inputFileLYZEP || inputFileLYZEP->IsZombie()) { 
140      cerr << " ERROR: NO Second Run file... " << endl ; 
141      break;
142    }
143    else { 
144      TList* inputListLYZEP = (TList*)inputFileLYZEP->Get("cobjLYZ2");  
145      if (!inputListLYZEP) {cout<<"Input list is NULL pointer!"<<endl; break;}
146      else {
147        cout<<"LYZEP input file/list read..."<<endl;
148        ep   ->SetSecondRunList(inputListLYZEP);
149        lyzep->SetSecondRunList(inputListLYZEP);
150        ep   ->Init();
151        lyzep->Init();
152      }
153    }
154  }
155  //---------------------------------------------------------------------------------------
156   
157       
158  //---------------------------------------------------------------------------------------  
159  // create and analyze events 'on the fly':
160
161  // set the global event parameters: 
162  eventMakerOnTheFly->SetMultiplicityOfRP(iMultiplicityOfRP);
163
164  for(Int_t i=0;i<nEvts;i++) {   
165    // creating the event with above settings:
166    
167    cout<<endl;
168    cout<<" ---- CREATING EVENT No "<<i+1<<" ---- "<<endl;
169    cout<<endl;   
170    
171    AliFlowEventSimple *event = eventMakerOnTheFly->CreateEventOnTheFly(); 
172    cout<<" .... done .... "<<endl;
173    
174    // analyzing the created event 'on the fly':
175    cout<<endl;
176    cout<<" ---- ANALYZING EVENT No "<<i+1<<" ---- "<<endl;
177    cout<<endl; 
178    
179    // do flow analysis for various methods:
180    if(MCEP) mcep->Make(event);
181    if(QC) qc->Make(event);
182    if(GFC) gfc->Make(event);
183    if(FQD) fqd->Make(event);
184    if(LYZ1) lyz1->Make(event);
185    if(LYZ2) lyz2->Make(event);
186    if(LYZEP) lyzep->Make(event,ep);
187    if(SP) sp->Make(event);
188    
189    cout<<" .... done .... "<<endl;
190    cout<<endl;
191    
192    delete event;
193  } // end of for(Int_t i=0;i<nEvts;i++)
194  //---------------------------------------------------------------------------------------  
195
196
197
198  //---------------------------------------------------------------------------------------  
199  // calculating and storing the final results of flow analysis
200  if(MCEP) {mcep->Finish(); mcep->WriteHistograms("outputMCEPanalysis.root");}
201  if(SP) {sp->Finish(); sp->WriteHistograms("outputSPanalysis.root");}
202  if(QC) {qc->Finish(); qc->WriteHistograms("outputQCanalysis.root");}
203  if(GFC) {gfc->Finish(); gfc->WriteHistograms("outputGFCanalysis.root");}
204  if(FQD) {fqd->Finish(); fqd->WriteHistograms("outputFQDanalysis.root");}
205  if(LYZ1) {lyz1->Finish(); lyz1->WriteHistograms("outputLYZ1analysis.root");}
206  if(LYZ2) {lyz2->Finish(); lyz2->WriteHistograms("outputLYZ2analysis.root");}
207  if(LYZEP) {lyzep->Finish(); lyzep->WriteHistograms("outputLYZEPanalysis.root");}
208  //---------------------------------------------------------------------------------------  
209  
210  
211  
212  cout<<endl;
213  cout<<endl;
214  cout<<" ---- LANDED SUCCESSFULLY ---- "<<endl;
215  cout<<endl; 
216  
217  timer.Stop();
218  cout << endl;
219  timer.Print();
220 }
221
222 void SetupPar(char* pararchivename)
223 {
224   //Load par files, create analysis libraries
225   //For testing, if par file already decompressed and modified
226   //classes then do not decompress.
227  
228   TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; 
229   TString parpar(Form("%s.par", pararchivename)) ; 
230   if ( gSystem->AccessPathName(parpar.Data()) ) {
231     gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
232     TString processline(Form(".! make %s", parpar.Data())) ; 
233     gROOT->ProcessLine(processline.Data()) ;
234     gSystem->ChangeDirectory(cdir) ; 
235     processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
236     gROOT->ProcessLine(processline.Data()) ;
237   } 
238   if ( gSystem->AccessPathName(pararchivename) ) {  
239     TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
240     gROOT->ProcessLine(processline.Data());
241   }
242   
243   TString ocwd = gSystem->WorkingDirectory();
244   gSystem->ChangeDirectory(pararchivename);
245   
246   // check for BUILD.sh and execute
247   if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
248     printf("*******************************\n");
249     printf("*** Building PAR archive    ***\n");
250     cout<<pararchivename<<endl;
251     printf("*******************************\n");
252     
253     if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
254       Error("runProcess","Cannot Build the PAR Archive! - Abort!");
255       return -1;
256     }
257   }
258   // check for SETUP.C and execute
259   if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
260     printf("*******************************\n");
261     printf("*** Setup PAR archive       ***\n");
262     cout<<pararchivename<<endl;
263     printf("*******************************\n");
264     gROOT->Macro("PROOF-INF/SETUP.C");
265   }
266   
267   gSystem->ChangeDirectory(ocwd.Data());
268   printf("Current dir: %s\n", ocwd.Data());
269 }
270
271 void LoadLibraries(const anaModes mode) {
272   
273   //--------------------------------------
274   // Load the needed libraries most of them already loaded by aliroot
275   //--------------------------------------
276   gSystem->Load("libTree.so");
277   gSystem->Load("libGeom.so");
278   gSystem->Load("libVMC.so");
279   gSystem->Load("libXMLIO.so");
280   gSystem->Load("libPhysics.so");
281   
282   //----------------------------------------------------------
283   // >>>>>>>>>>> Local mode <<<<<<<<<<<<<< 
284   //----------------------------------------------------------
285   if (mode==mLocal) {
286     //--------------------------------------------------------
287     // If you want to use already compiled libraries 
288     // in the aliroot distribution
289     //--------------------------------------------------------
290     gSystem->Load("libSTEERBase");
291     gSystem->Load("libESD");
292     gSystem->Load("libAOD");
293     gSystem->Load("libANALYSIS");
294     gSystem->Load("libANALYSISalice");
295     gSystem->Load("libCORRFW.so");
296     cerr<<"libCORRFW.so loaded..."<<endl;
297     gSystem->Load("libPWG2flowCommon.so");
298     cerr<<"libPWG2flowCommon.so loaded..."<<endl;
299     gSystem->Load("libPWG2flowTasks.so");
300     cerr<<"libPWG2flowTasks.so loaded..."<<endl;
301   }
302   
303   else if (mode == mLocalPAR) {
304     //--------------------------------------------------------
305     //If you want to use root and par files from aliroot
306     //--------------------------------------------------------  
307      //If you want to use root and par files from aliroot
308     //--------------------------------------------------------  
309     SetupPar("STEERBase");
310     SetupPar("ESD");
311     SetupPar("AOD");
312     SetupPar("ANALYSIS");
313     SetupPar("ANALYSISalice");
314     SetupPar("PWG2AOD");
315     SetupPar("CORRFW");
316     SetupPar("PWG2flowCommon");
317     cerr<<"PWG2flowCommon.par loaded..."<<endl;
318     SetupPar("PWG2flowTasks");
319     cerr<<"PWG2flowTasks.par loaded..."<<endl;
320   }
321   
322   //---------------------------------------------------------
323   // <<<<<<<<<< Source mode >>>>>>>>>>>>
324   //---------------------------------------------------------
325   else if (mode==mLocalSource) {
326  
327     // In root inline compile
328
329    
330     // Constants  
331     gROOT->LoadMacro("AliFlowCommon/AliFlowCommonConstants.cxx+");
332     gROOT->LoadMacro("AliFlowCommon/AliFlowLYZConstants.cxx+");
333     gROOT->LoadMacro("AliFlowCommon/AliFlowCumuConstants.cxx+");
334     
335     // Flow event
336     gROOT->LoadMacro("AliFlowCommon/AliFlowVector.cxx+"); 
337     gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimple.cxx+");    
338     gROOT->LoadMacro("AliFlowCommon/AliFlowEventSimple.cxx+");
339     
340     // Cuts
341     gROOT->LoadMacro("AliFlowCommon/AliFlowTrackSimpleCuts.cxx+");    
342     
343     // Output histosgrams
344     gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHist.cxx+");
345     gROOT->LoadMacro("AliFlowCommon/AliFlowCommonHistResults.cxx+");
346     gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist1.cxx+");
347     gROOT->LoadMacro("AliFlowCommon/AliFlowLYZHist2.cxx+");
348     
349     // Functions needed for various methods
350     gROOT->LoadMacro("AliFlowCommon/AliCumulantsFunctions.cxx+");
351     gROOT->LoadMacro("AliFlowCommon/AliFittingFunctionsForQDistribution.cxx+");
352     gROOT->LoadMacro("AliFlowCommon/AliFlowLYZEventPlane.cxx+");
353     
354     // Flow Analysis code for various methods
355     gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithMCEventPlane.cxx+"); 
356     gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithScalarProduct.cxx+");
357     gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithLYZEventPlane.cxx+");
358     gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithLeeYangZeros.cxx+");
359     gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithCumulants.cxx+");
360     gROOT->LoadMacro("AliFlowCommon/AliFlowAnalysisWithQCumulants.cxx+"); 
361     gROOT->LoadMacro("AliFlowCommon/AliFittingQDistribution.cxx+");
362     
363     // Class to fill the FlowEvent without aliroot dependence
364     // can be found in the directory FlowEventMakers
365     gROOT->LoadMacro("FlowEventMakers/FlowEventSimpleMaker.cxx+");   
366     
367     cout << "finished loading macros!" << endl;  
368     
369   }  
370   
371 }
372
373