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