ROOT logo
#include "TStopwatch.h"
#include "Riostream.h"
#include "TFile.h"


int runFlowOnTheFlyExample(Int_t nEvts=2000, Int_t mult=1000, Float_t v2=0.05, Int_t iseed=7669)
{
  TStopwatch timer;
  timer.Start();
  
  // Load the needed libraries for root (in AliRoot already loaded)
  gSystem->Load("libGeom");
  gSystem->Load("libVMC");
  gSystem->Load("libXMLIO");
  gSystem->Load("libPhysics");
  gSystem->Load("libPWGflowBase");

  fMyTRandom3 = new TRandom3(iseed);   
  gRandom->SetSeed(fMyTRandom3->Integer(65539));

  // Initialize the flow methods for default analysis:
  AliFlowAnalysisWithMCEventPlane *mcep = new AliFlowAnalysisWithMCEventPlane();
  //mcep->SetHarmonic(2); // default is v2
  mcep->Init();

  AliFlowAnalysisWithQCumulants* qc = new AliFlowAnalysisWithQCumulants();
  // qc->SetHarmonic(2); // default is v2
  qc->Init();
  

  // set cuts for the Reference Particles and Particles Of Interest:
  AliFlowTrackSimpleCuts *cutsRP = new AliFlowTrackSimpleCuts();
  //  cutsRP->SetPtMax(ptMaxRP);
  AliFlowTrackSimpleCuts *cutsPOI = new AliFlowTrackSimpleCuts();
  cutsPOI->SetPtMin(0.2);
  cutsPOI->SetPtMax(2.0);

  Printf("starting the main event loop..");
  // create and analyze events 'on the fly':
  for(Int_t i=0; i<nEvts; i++)
    {
      // creating the event with above settings:
      AliFlowEventSimple* event = new AliFlowEventSimple(mult,AliFlowEventSimple::kGenerate);
       event->AddV2(v2);
      //event->TagTracks(cutsRP, cutsPOI);
      event->TagPOI(cutsPOI);
      event->TagRP(cutsRP);
      // event->Print();
      
      // do flow analysis for various methods:
      mcep->Make(event);
      qc->Make(event);
      cout <<"Event: " << i+1 << "\r"; cout.flush();
      delete event;
    } // end of for(Int_t i=0;i<nEvts;i++)
  
 
  // calculate the final results
  mcep->Finish();
  qc->Finish();
 
  // open a new file which will hold the final results of all methods:
  TString outputFileName = "AnalysisResults.root";
  TFile *outputFile = new TFile(outputFileName.Data(),"RECREATE");
  const Int_t nMethods = 2;
  TString method[nMethods] = {"MCEP","QC"};
  TDirectoryFile *dirFileFinal[nMethods] = {NULL};
  TString fileName[nMethods];
  for(Int_t i=0; i<nMethods; i++)
    {
      // form a file name for each method:
      fileName[i]+="output";
      fileName[i]+=method[i].Data();
      fileName[i]+="analysis";
      dirFileFinal[i] = new TDirectoryFile(fileName[i].Data(),fileName[i].Data());
    }
  
  // store the final results
  mcep->WriteHistograms(dirFileFinal[0]);
  qc->WriteHistograms(dirFileFinal[1]);
  
  outputFile->Close();
  
  delete outputFile;
  cout<<endl; cout<<" ---- Fini ---- "<<endl; cout<<endl;
  
  timer.Stop(); timer.Print();
}




 runFlowOnTheFlyExample.C:1
 runFlowOnTheFlyExample.C:2
 runFlowOnTheFlyExample.C:3
 runFlowOnTheFlyExample.C:4
 runFlowOnTheFlyExample.C:5
 runFlowOnTheFlyExample.C:6
 runFlowOnTheFlyExample.C:7
 runFlowOnTheFlyExample.C:8
 runFlowOnTheFlyExample.C:9
 runFlowOnTheFlyExample.C:10
 runFlowOnTheFlyExample.C:11
 runFlowOnTheFlyExample.C:12
 runFlowOnTheFlyExample.C:13
 runFlowOnTheFlyExample.C:14
 runFlowOnTheFlyExample.C:15
 runFlowOnTheFlyExample.C:16
 runFlowOnTheFlyExample.C:17
 runFlowOnTheFlyExample.C:18
 runFlowOnTheFlyExample.C:19
 runFlowOnTheFlyExample.C:20
 runFlowOnTheFlyExample.C:21
 runFlowOnTheFlyExample.C:22
 runFlowOnTheFlyExample.C:23
 runFlowOnTheFlyExample.C:24
 runFlowOnTheFlyExample.C:25
 runFlowOnTheFlyExample.C:26
 runFlowOnTheFlyExample.C:27
 runFlowOnTheFlyExample.C:28
 runFlowOnTheFlyExample.C:29
 runFlowOnTheFlyExample.C:30
 runFlowOnTheFlyExample.C:31
 runFlowOnTheFlyExample.C:32
 runFlowOnTheFlyExample.C:33
 runFlowOnTheFlyExample.C:34
 runFlowOnTheFlyExample.C:35
 runFlowOnTheFlyExample.C:36
 runFlowOnTheFlyExample.C:37
 runFlowOnTheFlyExample.C:38
 runFlowOnTheFlyExample.C:39
 runFlowOnTheFlyExample.C:40
 runFlowOnTheFlyExample.C:41
 runFlowOnTheFlyExample.C:42
 runFlowOnTheFlyExample.C:43
 runFlowOnTheFlyExample.C:44
 runFlowOnTheFlyExample.C:45
 runFlowOnTheFlyExample.C:46
 runFlowOnTheFlyExample.C:47
 runFlowOnTheFlyExample.C:48
 runFlowOnTheFlyExample.C:49
 runFlowOnTheFlyExample.C:50
 runFlowOnTheFlyExample.C:51
 runFlowOnTheFlyExample.C:52
 runFlowOnTheFlyExample.C:53
 runFlowOnTheFlyExample.C:54
 runFlowOnTheFlyExample.C:55
 runFlowOnTheFlyExample.C:56
 runFlowOnTheFlyExample.C:57
 runFlowOnTheFlyExample.C:58
 runFlowOnTheFlyExample.C:59
 runFlowOnTheFlyExample.C:60
 runFlowOnTheFlyExample.C:61
 runFlowOnTheFlyExample.C:62
 runFlowOnTheFlyExample.C:63
 runFlowOnTheFlyExample.C:64
 runFlowOnTheFlyExample.C:65
 runFlowOnTheFlyExample.C:66
 runFlowOnTheFlyExample.C:67
 runFlowOnTheFlyExample.C:68
 runFlowOnTheFlyExample.C:69
 runFlowOnTheFlyExample.C:70
 runFlowOnTheFlyExample.C:71
 runFlowOnTheFlyExample.C:72
 runFlowOnTheFlyExample.C:73
 runFlowOnTheFlyExample.C:74
 runFlowOnTheFlyExample.C:75
 runFlowOnTheFlyExample.C:76
 runFlowOnTheFlyExample.C:77
 runFlowOnTheFlyExample.C:78
 runFlowOnTheFlyExample.C:79
 runFlowOnTheFlyExample.C:80
 runFlowOnTheFlyExample.C:81
 runFlowOnTheFlyExample.C:82
 runFlowOnTheFlyExample.C:83
 runFlowOnTheFlyExample.C:84
 runFlowOnTheFlyExample.C:85
 runFlowOnTheFlyExample.C:86
 runFlowOnTheFlyExample.C:87
 runFlowOnTheFlyExample.C:88
 runFlowOnTheFlyExample.C:89
 runFlowOnTheFlyExample.C:90
 runFlowOnTheFlyExample.C:91
 runFlowOnTheFlyExample.C:92
 runFlowOnTheFlyExample.C:93