]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG2/FLOW/macros/runFlowTask.C
hooks for PMD flow analysis
[u/mrichter/AliRoot.git] / PWG2 / FLOW / macros / runFlowTask.C
index 2421893d12abdc4e99f73378c9981427175ef8d4..bd55eb69565a59a86123055f13f9f0bbc683febc 100644 (file)
-enum anaModes {mLocal,mLocalPAR,mPROOF,mGRID};
+enum anaModes {mLocal,mLocalPAR,mPROOF,mGrid,mGridPAR};
 //mLocal: Analyze locally files in your computer using aliroot
 //mLocalPAR: Analyze locally files in your computer using root + PAR files
 //mPROOF: Analyze CAF files with PROOF
+//mGrid: Analyze files on Grid via AliEn plug-in and using precompiled FLOW libraries
+//       (Remark: When using this mode set also Bool_t bUseParFiles = kFALSE; in CreateAlienHandler.C)
+//mGridPAR: Analyze files on Grid via AliEn plug-in and using par files for FLOW package
+//          (Remark: when using this mode set also Bool_t bUseParFiles = kTRUE; in CreateAlienHandler.C)
+// CENTRALITY DEFINITION
+Bool_t kUseCentrality = kFALSE;
+Int_t binfirst = -1; //if kUseCentrality then change accordingly
+Int_t binlast = -1;  //if kUseCentrality then change accordingly
+const Int_t numberOfCentralityBins = 9;
+Float_t centralityArray[numberOfCentralityBins+1] = {0.,5.,10.,20.,30.,40.,50.,60.,70.,80.}; // in centrality percentile
+//Int_t centralityArray[numberOfCentralityBins+1] = {41,80,146,245,384,576,835,1203,1471,10000}; // in terms of TPC only reference multiplicity
 
-// RUN SETTINGS
+TString commonOutputFileName = "outputCentrality"; // e.g.: result for centrality bin 0 will be in the file "outputCentrality0.root", etc
 
-// Flow analysis method can be:(set to kTRUE or kFALSE)
-Bool_t SP       = kTRUE;
-Bool_t LYZ1SUM  = kTRUE;
-Bool_t LYZ1PROD = kTRUE;
-Bool_t LYZ2SUM  = kFALSE;
-Bool_t LYZ2PROD = kFALSE;
-Bool_t LYZEP    = kFALSE;
-Bool_t GFC      = kTRUE;
-Bool_t QC       = kTRUE;
-Bool_t FQD      = kFALSE;
-Bool_t MCEP     = kFALSE; //not for pp 
 
-Bool_t METHODS[] = {SP,LYZ1SUM,LYZ1PROD,LYZ2SUM,LYZ2PROD,LYZEP,GFC,QC,FQD,MCEP};
+//void runFlowTask(Int_t mode=mLocal, Int_t nRuns = 10, 
+//Bool_t DATA = kFALSE, const Char_t* dataDir="/Users/snelling/alice_data/Therminator_midcentral", Int_t offset = 0)
 
-// Analysis type can be ESD, AOD, MC, ESDMC0, ESDMC1
-const TString type = "ESD";
-
-// Boolean to fill/not fill the QA histograms
-Bool_t QA = kTRUE;   
-
-// Boolean to use/not use weights for the Q vector
-Bool_t WEIGHTS[] = {kFALSE,kFALSE,kFALSE}; //Phi, v'(pt), v'(eta)
-
-
-void runFlowTask(Int_t mode=mLocal, Int_t nRuns = 40, 
-                //const Char_t* dataDir="/data/alice2/kolk/PP/LHC09a4/81119", Int_t offset = 0)
-                const Char_t* dataDir="/data/alice2/kolk/Therminator_midcentral", Int_t offset = 0)
-//void runFlowTask(Int_t mode=mPROOF, Int_t nRuns = 10000, 
-                //      const Char_t* dataDir="/COMMON/COMMON/LHC09a4_run8158X", Int_t offset = 0)
-                //const Char_t* dataDir="/PWG2/akisiel/Therminator_c2030", Int_t offset=0)
+//void runFlowTask(Int_t mode = mGridPAR, Int_t nRuns = 50000000, 
+//              Bool_t DATA = kTRUE, const Char_t* dataDir="/alice/data/LHC10h_000137161_p1_plusplusplus", Int_t offset=0) 
+void runFlowTask(Int_t mode = mLocal, Int_t nRuns = 50000000, 
+                Bool_t DATA = kTRUE, const Char_t* dataDir="./data/", Int_t offset=0) 
+//void runFlowTask(Int_t mode = mGridPAR, Bool_t DATA = kTRUE)
 {
+  // Time:
   TStopwatch timer;
   timer.Start();
-  
+  // Cross-check user settings before starting:
+  //  CrossCheckUserSettings(DATA);
+  // Load needed libraries:
   LoadLibraries(mode);
-  
-  if (mode==mLocal || mode == mLocalPAR || mode == mGRID) {
-    if (type!="AOD") { TChain* chain = CreateESDChain(dataDir, nRuns, offset);}
-    else { TChain* chain = CreateAODChain(dataDir, nRuns, offset);}
-  }
-  //____________________________________________//
-  // Make the analysis manager
-  AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager");
-  
-  if (type == "ESD"){
-    AliVEventHandler* esdH = new AliESDInputHandler;
-    mgr->SetInputEventHandler(esdH);
+  // Create and configure the AliEn plug-in:
+  if(mode == mGrid || mode == mGridPAR) 
+    {    
+      gROOT->LoadMacro("CreateAlienHandler.C");
+      AliAnalysisGrid *alienHandler = CreateAlienHandler();  
+      if(!alienHandler) return;
+    }
+  // Chains: 
+  if(mode == mLocal || mode == mLocalPAR) {
+    TChain *chain = new TChain("esdTree");
+    chain->Add("/home/pchrist/ALICE/HeavyIons/Data/137161/Set1/AliESDs.root");
+    //TChain* chain = CreateESDChain(dataDir, nRuns, offset);
+    //TChain* chain = CreateAODChain(dataDir, nRuns, offset);
   }
   
-  if (type == "AOD"){
-    AliVEventHandler* aodH = new AliAODInputHandler;
-    mgr->SetInputEventHandler(aodH); 
-  }
+  // Create analysis manager:
+  AliAnalysisManager *mgr = new AliAnalysisManager("FlowAnalysisManager"); 
+  // Connect plug-in to the analysis manager:
+  if(mode == mGrid || mode == mGridPAR) 
+    { 
+      mgr->SetGridHandler(alienHandler);
+    }
   
-  if (type == "MC" || type == "ESDMC0" || type == "ESDMC1"){
-    AliVEventHandler* esdH = new AliESDInputHandler;
-    mgr->SetInputEventHandler(esdH);
-    
+  // Event handlers:
+  AliVEventHandler* esdH = new AliESDInputHandler;
+  mgr->SetInputEventHandler(esdH);
+  if (!DATA) {
     AliMCEventHandler *mc = new AliMCEventHandler();
-    mgr->SetMCtruthEventHandler(mc); }
-  
-  
-  //____________________________________________//
-  // Load the tasks
+    mgr->SetMCtruthEventHandler(mc); 
+  }
+
+  // Task to check the offline trigger:
+  gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); 
+  AddTaskPhysicsSelection(!DATA);
+
+  //Add the centrality determination task
+  if(kUseCentrality) {
+    gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
+    AddTaskCentrality();
+  }
+
+  //Add the TOF tender
+  //gROOT->LoadMacro("$ALICE_ROOT/PWG2/FLOW/macros/AddTaskTenderFlow.C");
+  //AddTaskTenderFlow();
+
+  // Setup analysis and usage of centrality bins
   gROOT->LoadMacro("AddTaskFlow.C");
-  AliAnalysisTaskFlowEvent* taskFE = AddTaskFlow(type,METHODS,QA,WEIGHTS);
-    
-  //____________________________________________//
-  // Run the analysis
-  if (!mgr->InitAnalysis()) return;
+  Float_t kLowCentralityBin = -1.;
+  Float_t kHighCentralityBin = -1;
+  if(kUseCentrality) {
+    kLowCentralityBin = centralityArray[binfirst];
+    kHighCentralityBin = centralityArray[binlast];
+  }
+  AddTaskFlow(kLowCentralityBin,
+             kHighCentralityBin,
+             commonOutputFileName );
+
+  // Enable debug printouts:
+  mgr->SetDebugLevel(2);
+  // Run the analysis:
+  if(!mgr->InitAnalysis()) return;  
   mgr->PrintStatus();
-  
-  if (mode==mLocal || mode == mLocalPAR) {
+  if(mode == mLocal || mode == mLocalPAR) {
     mgr->StartAnalysis("local",chain);
-  }
-  else if (mode==mPROOF) {
+  } else if(mode == mPROOF) {
     mgr->StartAnalysis("proof",dataDir,nRuns,offset);
+  } else if(mode == mGrid || mode == mGridPAR) { 
+    mgr->StartAnalysis("grid");
   }
-  else if (mode==mGRID) { 
-    mgr->StartAnalysis("local",chain);
-  }
-  
+
+  // Print real and CPU time used for analysis:
   timer.Stop();
-  timer.Print();
+  timer.Print();  
   
-}
+} // end of void runFlowTask(...)
 
+//===============================================================================================
+/*
+void CrossCheckUserSettings(Bool_t bData) 
+{
+ // Check in this method if the user settings make sense. 
+ if(LYZ1SUM && LYZ2SUM) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
+ if(LYZ1PROD && LYZ2PROD) {cout<<" WARNING: You cannot run LYZ1 and LYZ2 at the same time! LYZ2 needs the output from LYZ1 !!!!"<<endl; exit(0); }
+ if(LYZ2SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ2 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
+ if(LYZ1SUM && LYZEP) {cout<<" WARNING: You cannot run LYZ1 and LYZEP at the same time! LYZEP needs the output from LYZ2 !!!!"<<endl; exit(0); }
+} // end of void CrossCheckUserSettings()
+*/
+//===============================================================================================
 
-void LoadLibraries(const anaModes mode) {
-  
+void LoadLibraries(const anaModes mode) 
+{
   //--------------------------------------
   // Load the needed libraries most of them already loaded by aliroot
   //--------------------------------------
-  gSystem->Load("libTree.so");
-  gSystem->Load("libGeom.so");
-  gSystem->Load("libVMC.so");
-  gSystem->Load("libXMLIO.so");
-  gSystem->Load("libPhysics.so");
+
+  gSystem->Load("libCore");  
+  gSystem->Load("libTree");
+  gSystem->Load("libGeom");
+  gSystem->Load("libVMC");
+  gSystem->Load("libXMLIO");
+  gSystem->Load("libPhysics");
+  gSystem->Load("libXMLParser");
+  gSystem->Load("libProof");
+  gSystem->Load("libMinuit");
   
-  //----------------------------------------------------------
-  // >>>>>>>>>>> Local mode <<<<<<<<<<<<<< 
-  //----------------------------------------------------------
-  if (mode==mLocal) {
-    //--------------------------------------------------------
-    // If you want to use already compiled libraries 
-    // in the aliroot distribution
-    //--------------------------------------------------------
+  if (mode==mLocal || mode==mGrid || mode == mGridPAR || mode == mLocalPAR )
+  {
     gSystem->Load("libSTEERBase");
+    gSystem->Load("libCDB");
+    gSystem->Load("libRAWDatabase");
+    gSystem->Load("libRAWDatarec");
     gSystem->Load("libESD");
     gSystem->Load("libAOD");
+    gSystem->Load("libSTEER");
     gSystem->Load("libANALYSIS");
-    gSystem->Load("libANALYSISalice");
-    gSystem->Load("libCORRFW.so");
-    cerr<<"libCORRFW.so loaded..."<<endl;
-    gSystem->Load("libPWG2flowCommon.so");
-    cerr<<"libPWG2flowCommon.so loaded..."<<endl;
-    gSystem->Load("libPWG2flowTasks.so");
-    cerr<<"libPWG2flowTasks.so loaded..."<<endl;
-  }
-  
-  else if (mode == mLocalPAR || mode == mGRID) {
-    //--------------------------------------------------------
-    //If you want to use root and par files from aliroot
-    //--------------------------------------------------------  
-    SetupPar("STEERBase");
-    SetupPar("ESD");
-    SetupPar("AOD");
-    SetupPar("ANALYSIS");
-    SetupPar("ANALYSISalice");
-    SetupPar("PWG2AOD");
-    SetupPar("CORRFW");
-    SetupPar("PWG2flowCommon");
-    cerr<<"PWG2flowCommon.par loaded..."<<endl;
-    SetupPar("PWG2flowTasks");
-    cerr<<"PWG2flowTasks.par loaded..."<<endl;
+    gSystem->Load("libANALYSISalice");   
+    gSystem->Load("libTOFbase"); 
+    gSystem->Load("libTOFrec"); 
+    gSystem->Load("libTENDER");
+
+    if (mode == mLocal || mode == mGrid)
+    {
+      gSystem->Load("libTENDERSupplies");
+      gSystem->Load("libPWG2flowCommon"); 
+      gSystem->Load("libPWG2flowTasks"); 
+    }
+    if (mode == mLocalPAR || mode == mGridPAR )
+    {
+      AliAnalysisAlien::SetupPar("TENDERSupplies");
+      AliAnalysisAlien::SetupPar("PWG2flowCommon");
+      AliAnalysisAlien::SetupPar("PWG2flowTasks");
+    }
   }
   
   //---------------------------------------------------------
   // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
   //---------------------------------------------------------
   else if (mode==mPROOF) {
-    //
-    
     //  set to debug root versus if needed
-    //  TProof::Mgr("alicecaf")->SetROOTVersion("v5-21-01-alice_dbg");
-    //  TProof::Mgr("alicecaf")->SetROOTVersion("v5-21-01-alice");
-    
+    //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a_dbg");
+    //TProof::Mgr("alicecaf")->SetROOTVersion("v5-24-00a");
+    //TProof::Reset("proof://snelling@alicecaf.cern.ch");     
     // Connect to proof
-    // Put appropriate username here
-    // TProof::Reset("proof://snelling@alicecaf.cern.ch"); 
     printf("*** Connect to PROOF ***\n");
-    //  TProof::Open("abilandz@alicecaf.cern.ch");
-    //    TProof::Open("nkolk@alicecaf.cern.ch");
-    TProof::Open("snelling@localhost");
+    gEnv->SetValue("XSec.GSI.DelegProxy","2");
+    TProof::Open("mkrzewic@alice-caf.cern.ch");
+    //TProof::Open("mkrzewic@skaf.saske.sk");
+     // list the data available
+    //gProof->ShowDataSets("/*/*"); 
+    //gProof->ShowDataSets("/alice/sim/"); //for MC Data
+    //gProof->ShowDataSets("/alice/data/"); //for REAL Data 
+    // Clear the Packages
+    /*    
+    gProof->ClearPackage("STEERBase.par");
+    gProof->ClearPackage("ESD.par");
+    gProof->ClearPackage("AOD.par");
+    */
+    //gProof->ClearPackage("ANALYSIS.par");
+    //gProof->ClearPackage("ANALYSISalice.par");
+    //gProof->ClearPackage("CORRFW.par");
     
-    // Enable the STEERBase Package
-    //    gProof->ClearPackage("STEERBase.par");
-    gProof->UploadPackage("STEERBase.par");
-    gProof->EnablePackage("STEERBase");
-    // Enable the ESD Package
-    //    gProof->ClearPackage("ESD.par");
-    gProof->UploadPackage("ESD.par");
-    gProof->EnablePackage("ESD");
-    // Enable the AOD Package
-    //    gProof->ClearPackage("AOD.par");
-    gProof->UploadPackage("AOD.par");
-    gProof->EnablePackage("AOD");
-    // Enable the Analysis Package
-    //    gProof->ClearPackage("ANALYSIS.par");
-    gProof->UploadPackage("ANALYSIS.par");
-    gProof->EnablePackage("ANALYSIS");
-    // Enable the Analysis Package alice
-    //    gProof->ClearPackage("ANALYSISalice.par");
-    gProof->UploadPackage("ANALYSISalice.par");
-    gProof->EnablePackage("ANALYSISalice");
-    // Load the PWG2 AOD
-    //    gProof->ClearPackage("PWG2AOD.par");
-    gProof->UploadPackage("PWG2AOD.par");
-    gProof->EnablePackage("PWG2AOD");
-    // Enable the Correction Framework
-    //    gProof->ClearPackage("CORRFW.par");
+    gProof->ClearPackage("PWG2flowCommon");
+    gProof->ClearPackage("PWG2flowTasks");
+    
+    // Upload the Packages
+    //gProof->UploadPackage("STEERBase.par");
+    //gProof->UploadPackage("ESD.par");    
+    //gProof->UploadPackage("AOD.par");
+       
+    //gProof->UploadPackage("ANALYSIS.par"); 
+    //gProof->UploadPackage("ANALYSISalice.par");
     gProof->UploadPackage("CORRFW.par");
-    gProof->EnablePackage("CORRFW");
-    // Enable Flow Analysis
-    //    gProof->ClearPackage("PWG2flowCommon");
     gProof->UploadPackage("PWG2flowCommon.par");
-    gProof->EnablePackage("PWG2flowCommon");
-    //    gProof->ClearPackage("PWG2flowTasks");
     gProof->UploadPackage("PWG2flowTasks.par");
+    gProof->UploadPackage("ALIRECO.par");
+
+    // Enable the Packages 
+    // The global package
+    TList* list = new TList();
+    list->Add(new TNamed("ALIROOT_EXTRA_INCLUDES","RAW:OCDB:STEER:TOF"));
+    gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-07-AN",list);
+    gProof->EnablePackage("ALIRECO");
+    //gProof->EnablePackage("ANALYSIS");
+    //gProof->EnablePackage("ANALYSISalice");
+    //gProof->EnablePackage("CORRFW");
+    gProof->EnablePackage("PWG2flowCommon");
     gProof->EnablePackage("PWG2flowTasks");
-    //
+
+    // Show enables Packages
     gProof->ShowEnabledPackages();
   }  
   
-}
-
-void SetupPar(char* pararchivename) {
-  //Load par files, create analysis libraries
-  //For testing, if par file already decompressed and modified
-  //classes then do not decompress.
-  
-  TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; 
-  TString parpar(Form("%s.par", pararchivename)) ; 
-  if ( gSystem->AccessPathName(parpar.Data()) ) {
-    gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ;
-    TString processline(Form(".! make %s", parpar.Data())) ; 
-    gROOT->ProcessLine(processline.Data()) ;
-    gSystem->ChangeDirectory(cdir) ; 
-    processline = Form(".! mv /tmp/%s .", parpar.Data()) ;
-    gROOT->ProcessLine(processline.Data()) ;
-  } 
-  if ( gSystem->AccessPathName(pararchivename) ) {  
-    TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
-    gROOT->ProcessLine(processline.Data());
-  }
-  
-  TString ocwd = gSystem->WorkingDirectory();
-  gSystem->ChangeDirectory(pararchivename);
-  
-  // check for BUILD.sh and execute
-  if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) {
-    printf("*******************************\n");
-    printf("*** Building PAR archive    ***\n");
-    cout<<pararchivename<<endl;
-    printf("*******************************\n");
-    if (gSystem->Exec("PROOF-INF/BUILD.sh")) {
-      Error("runProcess","Cannot Build the PAR Archive! - Abort!");
-      return -1;
-    }
-  }
-  // check for SETUP.C and execute
-  if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) {
-    printf("*******************************\n");
-    printf("*** Setup PAR archive       ***\n");
-    cout<<pararchivename<<endl;
-    printf("*******************************\n");
-    gROOT->Macro("PROOF-INF/SETUP.C");
-  }
-  
-  gSystem->ChangeDirectory(ocwd.Data());
-  printf("Current dir: %s\n", ocwd.Data());
-}
-
+} // end of void LoadLibraries(const anaModes mode) 
 
 // Helper macros for creating chains
 // from: CreateESDChain.C,v 1.10 jgrosseo Exp
@@ -337,11 +317,10 @@ TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
     }
   
   return chain;
-}
 
+} // end of TChain* CreateESDChain(const char* aDataDir, Int_t aRuns, Int_t offset)
 
-// Helper macros for creating chains
-// from: CreateESDChain.C,v 1.10 jgrosseo Exp
+//===============================================================================================
 
 TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
 {
@@ -428,5 +407,6 @@ TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)
     }
   
   return chain;
-}
+
+} // end of TChain* CreateAODChain(const char* aDataDir, Int_t aRuns, Int_t offset)