]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG4/macros/ana.C
cov fixes
[u/mrichter/AliRoot.git] / PWG4 / macros / ana.C
index 8849e1b7c6d7768341286449419d470fda1bcd50..517e700ba16dec07cca52e5ae119ca79603cbd87 100644 (file)
 //  Author : Gustavo Conesa Balbastre (INFN-LNF)
 //
 //-------------------------------------------------
-enum anaModes {mLocal, mLocalCAF,mPROOF,mGRID};
-//mLocal: Analyze locally files in your computer
-//mLocalCAF: Analyze locally CAF files
-//mPROOF: Analyze CAF files with PROOF
+enum anaModes {mLocal=0, mPROOF=1, mPlugin=2, mGRID=3};
+//mLocal    = 0: Analyze locally files in your computer
+//mPROOF    = 1: Analyze files on GRID with Plugin
+//mPlugin   = 2: Analyze files on GRID with Plugin
+//mGRID     = 3: Analyze files on GRID, jobs launched from aliensh
 
 //---------------------------------------------------------------------------
-//Settings to read locally several files, only for "mLocal" mode
-//The different values are default, they can be set with environmental 
-//variables: INDIR, PATTERN, NFILES, respectivelly
+// Settings to read locally several files, only for "mLocal" mode
+// The different values are default, they can be set with environmental 
+// variables: INDIR, PATTERN, NFILES, respectivelly
 
-char * kInDir = "/user/data/files/"; 
+char * kInDir   = "/user/data/files/"; 
 char * kPattern = ""; // Data are in files kInDir/kPattern+i 
-Int_t kFile = 1; // Number of files
+Int_t  kFile    = 1; 
+
 //---------------------------------------------------------------------------
-//Collection file for grid analysis
+// Dataset for proof analysis, mode=mPROOF
+// char * kDataset = "/alice/vernet/PbPb_LHC10h_ESD";
+
+char *  kDatasetPROOF     = "/alice/vernet/LHC11b_149646";
+//char *  kDatasetPROOF     = "/alice/vernet/LHC11b10a_AOD046";//LHC11d_AOD076
+Int_t   kDatasetNMaxFiles = 20;
+TString ccin2p3UserName   = "arbor" ;
+TString alienUserName     = "narbor" ;
+
+//---------------------------------------------------------------------------
+// Collection file for grid analysis
+
 char * kXML = "collection.xml";
+
 //---------------------------------------------------------------------------
 //Scale histograms from file. Change to kTRUE when xsection file exists
 //Put name of file containing xsection 
@@ -36,13 +50,20 @@ const char * kXSFileName = "pyxsec.root";
 
 //---------------------------------------------------------------------------
 
-const Bool_t kMC = kFALSE; //With real data kMC = kFALSE
-const TString kInputData = "ESD"; //ESD, AOD, MC, deltaAOD
-const Bool_t  outAOD = kFALSE; //Some tasks doesnt need it.
-TString kTreeName = "esdTree";
-const Int_t kFilter = kFALSE; //Use ESD filter
+//Set some default values, but used values are set in the code!
+
+Bool_t  kMC        = kFALSE; //With real data kMC = kFALSE
+TString kInputData = "ESD"; //ESD, AOD, MC, deltaAOD
+Int_t   kYear      = 2011;
+TString kCollision = "pp";
+Bool_t  outAOD     = kTRUE; //Some tasks doesnt need it.
+TString kTreeName;
+TString kPass      = "";
+char    kTrigger[1024];
+Int_t   kRun       = 0;
 
-void ana(Int_t mode=mLocal)
+//________________________
+void ana(Int_t mode=mGRID)
 {
   // Main
   
@@ -51,133 +72,295 @@ void ana(Int_t mode=mLocal)
   // Look at the method below, 
   // change whatever you need for your analysis case
   // ------------------------------------------------------------------
+  
   LoadLibraries(mode) ;
-  // TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!!
-
+  //gSystem->ListLibraries();
+  
   //-------------------------------------------------------------------------------------------------
   //Create chain from ESD and from cross sections files, look below for options.
   //-------------------------------------------------------------------------------------------------
-  if(kInputData == "ESD") kTreeName = "esdTree" ;
-  else if(kInputData.Contains("AOD")) kTreeName = "aodTree" ;
-  else if (kInputData == "MC") kTreeName = "TE" ;
-  else {
-    cout<<"Wrong  data type "<<kInputData<<endl;
-    break;
-  }
   
-  TChain *chain       = new TChain(kTreeName) ;
+  // Set kInputData and kTreeName looking to the kINDIR
+  
+  CheckInputData(mode);
+  
+  // Check global analysis settings  
+  
+  CheckEnvironmentVariables();
+  
+  printf("*********************************************\n");
+  printf("*** Input data < %s >, pass %s, tree < %s >, MC?  < %d > ***\n",kInputData.Data(),kPass.Data(),kTreeName.Data(),kMC);
+  printf("*********************************************\n");
+  
+  TChain * chain   = new TChain(kTreeName) ;
   TChain * chainxs = new TChain("Xsection") ;
-  CreateChain(mode, chain, chainxs);  
-  
-  if(chain){
-    AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
-    
-    //--------------------------------------
-    // Make the analysis manager
-    //-------------------------------------
-    AliAnalysisManager *mgr  = new AliAnalysisManager("Manager", "Manager");
-    //AliAnalysisManager::SetUseProgressBar(kTRUE);
-    //mgr->SetSkipTerminate(kTRUE);
-    //mgr->SetNSysInfo(1);
-    
-    // MC handler
-    if((kMC || kInputData == "MC") && !kInputData.Contains("AOD")){
-      AliMCEventHandler* mcHandler = new AliMCEventHandler();
-      mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file
-      mgr->SetMCtruthEventHandler(mcHandler);
-      if( kInputData == "MC") {
-       cout<<"INPUT EVENT HANDLER"<<endl;
-       mgr->SetInputEventHandler(NULL);
-      }
+  CreateChain(mode, chain, chainxs); 
+  
+  printf("*********************************************\n");
+  printf("number of entries # %lld, skipped %d\n", chain->GetEntries()) ;      
+  printf("*********************************************\n");
+  
+  if(!chain)
+  { 
+    printf("STOP, no chain available\n"); 
+    return;
+  }
+  
+  AliLog::SetGlobalLogLevel(AliLog::kError);//Minimum prints on screen
+  
+  //------------------------------------------
+  //  Alien handler part
+  //------------------------------------------
+  AliAnalysisGrid *alienHandler=0x0;
+  if(mode==mPlugin)
+  {
+    // Create and configure the alien handler plugin
+    gROOT->LoadMacro("CreateAlienHandler.C");
+    alienHandler = CreateAlienHandler();
+    if (!alienHandler) return;
+  }  
+  
+  //--------------------------------------
+  // Make the analysis manager
+  //-------------------------------------
+  AliAnalysisManager *mgr  = new AliAnalysisManager("Manager", "Manager");
+  //AliAnalysisManager::SetUseProgressBar(kTRUE);
+  //mgr->SetSkipTerminate(kTRUE);
+  //mgr->SetNSysInfo(1);
+  
+  if(mode==mPlugin)
+  {
+    // Connect plugin to the analysis manager
+    mgr->SetGridHandler(alienHandler);
+  }
+  
+  // MC handler
+  if((kMC || kInputData == "MC") && !kInputData.Contains("AOD"))
+  {
+    AliMCEventHandler* mcHandler = new AliMCEventHandler();
+    mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file
+    mgr->SetMCtruthEventHandler(mcHandler);
+    if( kInputData == "MC") 
+    {
+      cout<<"MC INPUT EVENT HANDLER"<<endl;
+      mgr->SetInputEventHandler(NULL);
     }
+  }
+  
+  // AOD output handler
+  if(kInputData!="deltaAOD" && outAOD)
+  {
+    cout<<"Init output handler"<<endl;
+    AliAODHandler* aodoutHandler   = new AliAODHandler();
+    aodoutHandler->SetOutputFileName("aod.root");
+    ////aodoutHandler->SetCreateNonStandardAOD();
+    mgr->SetOutputEventHandler(aodoutHandler);
+  }
+  
+  //input
+  
+  if(kInputData == "ESD")
+  {
+    // ESD handler
+    AliESDInputHandler *esdHandler = new AliESDInputHandler();
+    esdHandler->SetReadFriends(kFALSE);
+    mgr->SetInputEventHandler(esdHandler);
+    cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
+  }
+  else if(kInputData.Contains("AOD"))
+  {
+    // AOD handler
+    AliAODInputHandler *aodHandler = new AliAODInputHandler();
+    mgr->SetInputEventHandler(aodHandler);
+    if(kInputData == "deltaAOD") aodHandler->AddFriend("deltaAODPartCorr.root");
+    cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
+  }
+  //mgr->RegisterExternalFile("deltaAODPartCorr.root");
+  //mgr->SetDebugLevel(1); // For debugging, do not uncomment if you want no messages.
+  
+  TString outputFile = AliAnalysisManager::GetCommonFileName(); 
+  
+  //-------------------------------------------------------------------------
+  //Define task, put here any other task that you want to use.
+  //-------------------------------------------------------------------------
+  
+  // Physics selection
+  gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); 
+  AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kMC); 
+  
+  // Centrality
+  if(kCollision=="PbPb")
+  {
+    gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
+    AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
+    taskCentrality->SetPass(2); // remember to set the pass you are processing!!!
+  }
+  
+  // Simple event counting tasks
+  AddTaskCounter("");   // All
+  AddTaskCounter("MB"); // Min Bias
+  if(!kMC)
+  {
+    AddTaskCounter("INT7"); // Min Bias
+    AddTaskCounter("EMC1"); // Trig Th > 1.5 GeV approx
+    AddTaskCounter("EMC7"); // Trig Th > 4-5 GeV 
+    AddTaskCounter("PHOS"); //  
+  }
+  
+  Bool_t kPrint   = kFALSE;
+  Bool_t deltaAOD = kFALSE;
+  
+  gROOT->LoadMacro("AddTaskPartCorr.C");        // $ALICE_ROOT/PWG4/macros
+  gROOT->LoadMacro("AddTaskEMCALClusterize.C"); // $ALICE_ROOT/PWG4/CaloCalib/macros
+  
+  // ------
+  // Tracks
+  // ------  
+  
+  // Track isolation-correlation analysis and EMCAL QA analysis
+  AliAnalysisTaskParticleCorrelation *anamb  = AddTaskPartCorr(kInputData, "EMCAL",   kPrint,kMC, deltaAOD,  outputFile.Data(), 
+                                                               kYear,kRun,kCollision,"INT7","");   // PHOS trigger
+  
+  AliAnalysisTaskParticleCorrelation *anatr  = AddTaskPartCorr(kInputData, "EMCAL",   kPrint,kMC, deltaAOD,  outputFile.Data(), 
+                                                               kYear,kRun,kCollision,"EMC7","");  
+  
+  // -----
+  // EMCAL
+  // -----  
+  
+  Bool_t  bTrackMatch = kTRUE;
+  Int_t   minEcell    = 50;  // 50  MeV (10 MeV used in reconstruction)
+  Int_t   minEseed    = 100; // 100 MeV
+  Int_t   dTime       = 0;   // default, 250 ns
+  Int_t   wTime       = 0;   // default 425 < T < 825 ns
+  TString clTrigger   = "";  // Do not select, do Min Bias and triggered
+  
+  //Analysis with clusterizer V1
+  AliAnalysisTaskEMCALClusterize * clv1 = AddTaskEMCALClusterize(kMC,"V1",clTrigger,kRun,kPass, bTrackMatch,
+                                                                 minEcell,minEseed,dTime,wTime);    
+  
+  TString arrayNameV1(Form("V1_Ecell%d_Eseed%d_DT%d_WT%d",minEcell,minEseed, dTime,wTime));
+  printf("Name of clusterizer array: %s\n",arrayNameV1.Data());
+  
+  if(!kMC)
+  {
     
-    // AOD output handler
-    if(kInputData!="deltaAOD" && outAOD){
-      cout<<"Init output handler"<<endl;
-      AliAODHandler* aodoutHandler   = new AliAODHandler();
-      aodoutHandler->SetOutputFileName("aod.root");
-      ////aodoutHandler->SetCreateNonStandardAOD();
-      mgr->SetOutputEventHandler(aodoutHandler);
-    }
+    AliAnalysisTaskParticleCorrelation *anav1tr  = AddTaskPartCorr(kInputData, "EMCAL",   kPrint,kMC, deltaAOD,  outputFile.Data(), 
+                                                                   kYear,kRun,kCollision,"EMC7",arrayNameV1);
     
-    //input
+    AliAnalysisTaskParticleCorrelation *anav1mb  = AddTaskPartCorr(kInputData, "EMCAL",   kPrint,kMC, deltaAOD,  outputFile.Data(), 
+                                                                   kYear,kRun,kCollision,"INT7",arrayNameV1);
+  }
+  else 
+  {// No trigger (should be MB, but for single particle productions it does not work)
     
-    if(kInputData == "ESD"){
-      // ESD handler
-      AliESDInputHandler *esdHandler = new AliESDInputHandler();
-      esdHandler->SetReadFriends(kFALSE);
-      mgr->SetInputEventHandler(esdHandler);
-      cout<<"ESD handler "<<mgr->GetInputEventHandler()<<endl;
-    }
-    else if(kInputData.Contains("AOD")){
-      // AOD handler
-      AliAODInputHandler *aodHandler = new AliAODInputHandler();
-      mgr->SetInputEventHandler(aodHandler);
-      if(kInputData == "deltaAOD") aodHandler->AddFriend("deltaAODPartCorr.root");
-      cout<<"AOD handler "<<mgr->GetInputEventHandler()<<endl;
-    }
-    //mgr->RegisterExternalFile("deltaAODPartCorr.root");
-    //mgr->SetDebugLevel(-1); // For debugging, do not uncomment if you want no messages.
-    
-    //-------------------------------------------------------------------------
-    //Define task, put here any other task that you want to use.
-    //-------------------------------------------------------------------------
-    AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
-    AliAnalysisDataContainer *coutput1;
-    if(outAOD){
-      
-      coutput1 = mgr->GetCommonOutputContainer();
-      
-      if(kInputData=="ESD"){
-       
-       gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
-       AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection();
-       if(kFilter){
-         gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
-         AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kFALSE);
-       }
-      }
-    }
+    AliAnalysisTaskParticleCorrelation *anav1  = AddTaskPartCorr(kInputData, "EMCAL",   kPrint,kMC, deltaAOD,  outputFile.Data(), 
+                                                                 kYear,kRun,kCollision,"",arrayNameV1);
+  }
+  
+  
+  //Analysis with clusterizer V2
+  AliAnalysisTaskEMCALClusterize * clv2 = AddTaskEMCALClusterize(kMC,"V2",clTrigger,kRun,kPass, bTrackMatch,
+                                                                 minEcell,minEseed,dTime,wTime);    
+  
+  TString arrayNameV2(Form("V2_Ecell%d_Eseed%d_DT%d_WT%d",minEcell,minEseed, dTime,wTime));
+  printf("Name of clusterizer array: %s\n",arrayNameV2.Data());
+  
+  if(!kMC)
+  {
     
-    gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C");
-    TString data = kInputData;
-    if(kFilter && kInputData=="ESD" && outAOD) data = "AOD";
-    //data="MC";
-    AliAnalysisTaskParticleCorrelation *taskEMCAL = AddTaskPartCorr(data,"EMCAL", kFALSE,kFALSE, kFALSE);      
-    //mgr->ProfileTask("PartCorrEMCAL");
-    
-    //AliAnalysisTaskParticleCorrelation *taskPHOS  = AddTaskPartCorr(data,"PHOS", kFALSE,kFALSE,kFALSE);
-    //mgr->ProfileTask("PartCorrPHOS");
-    
-    //gROOT->LoadMacro("AddTaskCalorimeterQA.C");
-    gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/QA/AddTaskCalorimeterQA.C");
-    AliAnalysisTaskParticleCorrelation *taskQA = AddTaskCalorimeterQA(kInputData,kFALSE,kFALSE);
-    //mgr->ProfileTask("CalorimeterPerformance");      
-    
-    //-----------------------
-    // Run the analysis
-    //-----------------------    
-    TString smode = "";
-    if (mode==mLocal || mode == mLocalCAF) 
-      smode = "local";
-    else if (mode==mPROOF) 
-      smode = "proof";
-    else if (mode==mGRID) 
-      smode = "local";
-    mgr->InitAnalysis();
-    mgr->PrintStatus();
-    mgr->StartAnalysis(smode.Data(),chain);
-
-    cout <<" Analysis ended sucessfully "<< endl ;
+    AliAnalysisTaskParticleCorrelation *anav2tr  = AddTaskPartCorr(kInputData, "EMCAL",   kPrint,kMC, deltaAOD,  outputFile.Data(), 
+                                                                   kYear,kRun,kCollision,"EMC7",arrayNameV2);
+    
+    AliAnalysisTaskParticleCorrelation *anav2mb  = AddTaskPartCorr(kInputData, "EMCAL",   kPrint,kMC, deltaAOD,  outputFile.Data(), 
+                                                                   kYear,kRun,kCollision,"INT7",arrayNameV2);
+  }
+  else 
+  {// No trigger (should be MB, but for single particle productions it does not work)
+    AliAnalysisTaskParticleCorrelation *anav2  = AddTaskPartCorr(kInputData, "EMCAL",   kPrint,kMC, deltaAOD,  outputFile.Data(), 
+                                                                 kYear,kRun,kCollision,"",arrayNameV2);    
+  }
+  
+  // -----
+  // PHOS
+  // -----
+  
+  //Add here PHOS tender or whatever is needed
+  
+  if(!kMC)
+  {
+    
+    AliAnalysisTaskParticleCorrelation *anav1tr = AddTaskPartCorr(kInputData, "PHOS", kPrint,kMC, deltaAOD,  outputFile.Data(), 
+                                                                  kYear,kRun,kCollision,"PHOS",""); // PHOS trigger
+    
+    
+    AliAnalysisTaskParticleCorrelation *anav1mb = AddTaskPartCorr(kInputData, "PHOS",   kPrint,kMC, deltaAOD,  outputFile.Data(), 
+                                                                  kYear,kRun,kCollision,"INT7","");
     
   }
-  else cout << "Chain was not produced ! "<<endl;
-  //printf("*** DELETE MANAGER ***\n");
-  // delete mgr;
+  else 
+  {// No trigger
+    
+    AliAnalysisTaskParticleCorrelation *anav1mb = AddTaskPartCorr(kInputData, "PHOS",   kPrint,kMC, deltaAOD,  outputFile.Data(), 
+                                                                  kYear,kRun,kCollision,"","");
+    
+  }
+  
+  //-----------------------
+  // Run the analysis
+  //-----------------------    
+  mgr->InitAnalysis();
+  mgr->PrintStatus();
+  
+  if      (mode == mPlugin) mgr->StartAnalysis("grid");
+  else if (mode == mPROOF ) mgr->StartAnalysis("proof",chain);
+  else                      mgr->StartAnalysis("local",chain);
+  
+  cout <<" Analysis ended sucessfully "<< endl ;
   
 }
 
-void  LoadLibraries(const anaModes mode) {
+//_____________________________
+void  LoadLibraries(Int_t mode)
+{
+  
+  if (mode == mPROOF) {
+    //TProof::Mgr("ccalpmaster")->SetROOTVersion("ALICE_v5-27-06b");
+    gROOT->LoadMacro("/afs/in2p3.fr/group/alice/laf/EnableAliRootForLAF.C");
+    TProof* proof = EnableAliRootForLAF("ccaplmaster",nPROOFWorkers.Data(),ccin2p3UserName.Data(),alienUserName.Data(),"",kFALSE,kTRUE,kTRUE,"OADB:ANALYSIS:ANALYSISalice:AOD:ESD:CORRFW:STEERBase:EMCALUtils:PHOSUtils:PWG4PartCorrBase:PWG4PartCorrDep:PWG4CaloCalib");
+    
+    //  TProof* proof = TProof::Open("ccaplmaster",Form("workers=%s",nPROOFWorkers.Data()));
+    
+    //     //proof->ClearPackages();
+    //     proof->UploadPackage("STEERBase");
+    //     proof->UploadPackage("ESD");
+    //     proof->UploadPackage("AOD");
+    //     proof->UploadPackage("ANALYSIS");
+    //     proof->UploadPackage("OADB");
+    //     proof->UploadPackage("ANALYSISalice");
+    //     proof->UploadPackage("CORRFW");
+    //     //proof->UploadPackage("JETAN");
+    //     proof->UploadPackage("PHOSUtils");
+    //     proof->UploadPackage("EMCALUtils");
+    //     proof->UploadPackage("PWG4PartCorrBase");
+    //     proof->UploadPackage("PWG4PartCorrDep");
+    //     proof->UploadPackage("PWG4CaloCalib");
+    
+    //     proof->EnablePackage("STEERBase");
+    //     proof->EnablePackage("ESD");
+    //     proof->EnablePackage("AOD");
+    //     proof->EnablePackage("ANALYSIS");
+    //     proof->EnablePackage("OADB");
+    //     proof->EnablePackage("ANALYSISalice");
+    //     proof->EnablePackage("CORRFW");
+    //     //proof->EnablePackage("JETAN");
+    //     proof->EnablePackage("PHOSUtils");
+    //     proof->EnablePackage("EMCALUtils");
+    //     proof->EnablePackage("PWG4PartCorrBase");
+    //     proof->EnablePackage("PWG4PartCorrDep");
+    //     proof->EnablePackage("PWG4CaloCalib");
+    return;
+  }  
   
   //--------------------------------------
   // Load the needed libraries most of them already loaded by aliroot
@@ -188,110 +371,67 @@ void  LoadLibraries(const anaModes mode) {
   gSystem->Load("libXMLIO.so");
   gSystem->Load("libMatrix.so");
   gSystem->Load("libPhysics.so");
-  //----------------------------------------------------------
-  // >>>>>>>>>>> Local mode <<<<<<<<<<<<<< 
-  //----------------------------------------------------------
-  if (mode==mLocal || mode == mLocalCAF || mode == mGRID) {
-    //--------------------------------------------------------
-    // If you want to use already compiled libraries 
-    // in the aliroot distribution
-    //--------------------------------------------------------
-    gSystem->Load("libSTEERBase.so");
-    gSystem->Load("libESD.so");
-    gSystem->Load("libAOD.so");
-    gSystem->Load("libANALYSIS.so");
-    gSystem->Load("libANALYSISalice.so");
-    gSystem->Load("libPHOSUtils");
-    gSystem->Load("libEMCALUtils");
-    gSystem->Load("libPWG4PartCorrBase.so");
-    gSystem->Load("libPWG4PartCorrDep.so");
-    if(kFilter){
-      gSystem->Load("libCORRFW.so");
-      gSystem->Load("libPWG3base.so");
-      gSystem->Load("libPWG3muon.so");
-    }
-
-    //--------------------------------------------------------
-    //If you want to use root and par files from aliroot
-    //--------------------------------------------------------  
-    /*
-     SetupPar("STEERBase");
-     SetupPar("ESD");
-     SetupPar("AOD");
-     SetupPar("ANALYSIS");
-     SetupPar("ANALYSISalice");
-     //If your analysis needs PHOS geometry uncomment following lines
-     SetupPar("PHOSUtils");
-     SetupPar("EMCALUtils");
-     //Create Geometry
-     SetupPar("PWG4PartCorrBase");
-     SetupPar("PWG4PartCorrDep");
-     if(kFilter){
-     gSystem->Load("libCORRFW.so");
-     gSystem->Load("libPWG3base.so");
-     gSystem->Load("libPWG3muon.so");
-    }
-    */
-  }
-
-  //---------------------------------------------------------
-  // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
-  //---------------------------------------------------------
-  else if (mode==mPROOF) {
-    //
-    // Connect to proof
-    // Put appropriate username here
-    // TProof::Reset("proof://mgheata@lxb6046.cern.ch"); 
-    TProof::Open("proof://mgheata@lxb6046.cern.ch");
-    
-    //    gProof->ClearPackages();
-    //    gProof->ClearPackage("ESD");
-    //    gProof->ClearPackage("AOD");
-    //    gProof->ClearPackage("ANALYSIS");   
-    //    gProof->ClearPackage("PWG4PartCorrBase");
-    //    gProof->ClearPackage("PWG4PartCorrDep");
-    
-    // Enable the STEERBase Package
-    gProof->UploadPackage("STEERBase.par");
-    gProof->EnablePackage("STEERBase");
-    // Enable the ESD Package
-    gProof->UploadPackage("ESD.par");
-    gProof->EnablePackage("ESD");
-    // Enable the AOD Package
-    gProof->UploadPackage("AOD.par");
-    gProof->EnablePackage("AOD");
-    // Enable the Analysis Package
-    gProof->UploadPackage("ANALYSIS.par");
-    gProof->EnablePackage("ANALYSIS");
-       // Enable the PHOS geometry Package
-    //gProof->UploadPackage("PHOSUtils.par");
-    //gProof->EnablePackage("PHOSUtils");
-    // Enable PartCorr analysis
-    gProof->UploadPackage("PWG4PartCorrBase.par");
-    gProof->EnablePackage("PWG4PartCorrBase");
-    gProof->UploadPackage("PWG4PartCorrDep.par");
-    gProof->EnablePackage("PWG4PartCorrDep");    
-    gProof->ShowEnabledPackages();
-  }  
+  gSystem->Load("libMinuit.so"); // Root + libraries to if reclusterization is done
+  
+  gSystem->Load("libSTEERBase.so");
+  gSystem->Load("libGui.so"); // Root + libraries to if reclusterization is done
+  gSystem->Load("libCDB.so"); // Root + libraries to if reclusterization is done
+  gSystem->Load("libESD.so"); // Root + libraries to if reclusterization is done
+  gSystem->Load("libAOD.so");
+  gSystem->Load("libRAWDatabase.so"); // Root + libraries to if reclusterization is done
+  gSystem->Load("libProof.so"); 
+  gSystem->Load("libANALYSIS.so");
+  gSystem->Load("libSTEER.so"); // Root + libraries to if reclusterization is done
+  
+  gSystem->Load("libRAWDatarec.so"); // Root + libraries to if reclusterization is done
+  gSystem->Load("libRAWDatasim.so"); // Root + libraries to if reclusterization is done
+  gSystem->Load("libVZERObase.so");  // Root + libraries to if reclusterization is done
+  gSystem->Load("libVZEROrec.so");   // Root + libraries to if reclusterization is done
+  
+  gSystem->Load("libEMCALUtils");
+  //SetupPar("EMCALUtils");
+  gSystem->Load("libEMCALraw");  // Root + libraries to if reclusterization is done
+  gSystem->Load("libEMCALbase"); // Root + libraries to if reclusterization is done
+  gSystem->Load("libEMCALsim");  // Root + libraries to if reclusterization is done
+  gSystem->Load("libEMCALrec");  // Root + libraries to if reclusterization is done
+  //SetupPar("EMCALraw");
+  //SetupPar("EMCALbase");
+  //SetupPar("EMCALsim");
+  //SetupPar("EMCALrec");
+  
+  gSystem->Load("libANALYSISalice.so");
+  //gSystem->Load("libTENDER.so"); 
+  //gSystem->Load("libTENDERSupplies.so");
+  
+  gSystem->Load("libPHOSUtils");
+  gSystem->Load("libEMCALUtils");
+  gSystem->Load("libPWG4PartCorrBase");
+  gSystem->Load("libPWG4PartCorrDep");
+  gSystem->Load("libPWG4CaloCalib");
+  //SetupPar("PWG4PartCorrBase");
+  //SetupPar("PWG4PartCorrDep");
+  //SetupPar("PWG4CaloCalib");
+  
+  //gSystem->Load("libJETAN");
+  //gSystem->Load("FASTJETAN");
+  //gSystem->Load("PWG4JetTasks");
+  
+  // needed for plugin?
+  gSystem->AddIncludePath("-I$ALICE_ROOT");
+  gSystem->AddIncludePath("-I./");     
   
 }
 
+//_________________________________
 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 $ALICE_ROOT/%s .", parpar.Data()) ;
-    gROOT->ProcessLine(processline.Data()) ;
-  } 
+  
   if ( gSystem->AccessPathName(pararchivename) ) {  
     TString processline = Form(".! tar xvzf %s",parpar.Data()) ;
     gROOT->ProcessLine(processline.Data());
@@ -325,30 +465,263 @@ void SetupPar(char* pararchivename)
   printf("Current dir: %s\n", ocwd.Data());
 }
 
-
-
-void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs){
-  //Fills chain with data
-  TString ocwd = gSystem->WorkingDirectory();
+//______________________________________
+void CheckInputData(const anaModes mode)
+{
+  //Sets input data and tree
   
-  //-----------------------------------------------------------
-  //Analysis of CAF data locally and with PROOF
-  //-----------------------------------------------------------
-  if(mode ==mPROOF || mode ==mLocalCAF){
-    // Chain from CAF
-    gROOT->LoadMacro("$ALICE_ROOT/PWG0/CreateESDChain.C");
-    // The second parameter is the number of input files in the chain
-    chain = CreateESDChain("ESD12001.txt", 5);  
-  }
+  TString ocwd = gSystem->WorkingDirectory();
   
   //---------------------------------------
   //Local files analysis
   //---------------------------------------
-  else if(mode == mLocal){    
+  if(mode == mLocal){    
     //If you want to add several ESD files sitting in a common directory INDIR
     //Specify as environmental variables the directory (INDIR), the number of files 
     //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
+    
+    if(gSystem->Getenv("INDIR"))  
+      kInDir = gSystem->Getenv("INDIR") ; 
+    else cout<<"INDIR not set, use default: "<<kInDir<<endl;   
+    
+    TString sindir(kInDir);
+    if     (sindir.Contains("pass1")) kPass = "pass1";
+    else if(sindir.Contains("pass2")) kPass = "pass2";
+    else if(sindir.Contains("pass3")) kPass = "pass3";
+    
+    if(gSystem->Getenv("PATTERN"))   
+      kPattern = gSystem->Getenv("PATTERN") ; 
+    else  cout<<"PATTERN not set, use default: "<<kPattern<<endl;
+    
+    cout<<"INDIR   : "<<kInDir<<endl;
+    cout<<"NFILES  : "<<kFile<<endl;
+    
+    char fileE[120] ;   
+    char fileA[120] ;   
+    char fileG[120] ;
+    char fileEm[120] ;   
+    for (Int_t event = 0 ; event < kFile ; event++) {
+      sprintf(fileE,  "%s/%s%d/AliESDs.root",    kInDir,kPattern,event) ; 
+      sprintf(fileA,  "%s/%s%d/AliAOD.root",     kInDir,kPattern,event) ; 
+      sprintf(fileG,  "%s/%s%d/galice.root",     kInDir,kPattern,event) ; 
+      sprintf(fileEm, "%s/%s%d/embededAOD.root", kInDir,kPattern,event) ; 
+      
+      TFile * fESD = TFile::Open(fileE) ; 
+      TFile * fAOD = TFile::Open(fileA) ; 
+      
+      //Check if file exists and add it, if not skip it
+      if (fESD) 
+      {
+        kTreeName  = "esdTree";
+        kInputData = "ESD";
+        TFile * fG = TFile::Open(fileG);
+        if(fG) { kMC = kTRUE; fG->Close();}
+        else     kMC = kFALSE;
+        
+        // Get run number
+        TTree* esdTree = (TTree*)fESD->Get("esdTree");
+        AliESDEvent* esd = new AliESDEvent();
+        esd->ReadFromTree(esdTree);
+        esdTree->GetEvent(0);
+        kRun = esd->GetRunNumber();
+        
+        return;
+      }
+      else if(fAOD)
+      {
+        kTreeName  = "aodTree";
+        kInputData = "AOD";
+        if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
+        else kMC = kFALSE;
+        
+        // Get run number
+        TTree* aodTree = (TTree*)fAOD->Get("aodTree");
+        AliAODEvent* aod = new AliAODEvent();
+        aod->ReadFromTree(aodTree);
+        aodTree->GetEvent(0);
+        kRun = aod->GetRunNumber();
+        return;
+      }
+      else if(TFile::Open(fileEm))
+      {
+        kTreeName  = "aodTree";
+        kInputData = "AOD";
+        kMC        = kTRUE;
+        
+        return;
+      }
+      else if(TFile::Open(fileG))
+      {
+        kTreeName  = "TE";
+        kInputData = "MC";
+        kMC        = kTRUE;
+        return;
+      }
+    }
+    
+    if(fESD) fESD->Close();
+    if(fAOD) fAOD->Close();
+    
+  }// local files analysis
+  
+  //------------------------------
+  //GRID xml files
+  //-----------------------------
+  else if(mode == mGRID){
+    //Get colection file. It is specified by the environmental
+    //variable XML
+    
+    if(gSystem->Getenv("XML") )
+      kXML = gSystem->Getenv("XML");
+    else
+      sprintf(kXML, "collection.xml") ; 
+    
+    if (!TFile::Open(kXML)) {
+      printf("No collection file with name -- %s -- was found\n",kXML);
+      return ;
+    }
+    else cout<<"XML file "<<kXML<<endl;
+    
+    //Load necessary libraries and connect to the GRID
+    gSystem->Load("libNetx.so") ; 
+    gSystem->Load("libRAliEn.so"); 
+    TGrid::Connect("alien://") ;
+    
+    //Feed Grid with collection file
+    TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
+    if (! collection) {
+      AliError(Form("%s not found", kXML)) ; 
+      return kFALSE ; 
+    }
+    TGridResult* result = collection->GetGridResult("",0 ,0);
+    
+    for (Int_t index = 0; index < result->GetEntries(); index++) {
+      TString alienURL = result->GetKey(index, "turl") ; 
+      cout << "================== " << alienURL << endl ; 
+      
+      if     (alienURL.Contains("pass1")) kPass = "pass1";
+      else if(alienURL.Contains("pass2")) kPass = "pass2";
+      else if(alienURL.Contains("pass3")) kPass = "pass3";
+      
+      kRun = AliAnalysisManager::GetRunFromAlienPath(alienURL.Data());
+      printf("Run number from alien path = %d\n",kRun);
+      
+      TFile * fAOD = 0 ; 
+      //Check if file exists and add it, if not skip it
+      if (alienURL.Contains("AliESDs.root"))  
+      {
+        kTreeName  = "esdTree";
+        kInputData = "ESD";
+        alienURL.ReplaceAll("AliESDs.root","galice.root");
+        if(TFile::Open(alienURL)) kMC=kTRUE;
+        else kMC = kFALSE;
+        return;
+      }
+      else if(alienURL.Contains("AliAOD.root"))
+      {
+        kTreeName  = "aodTree";
+        kInputData = "AOD";
+        fAOD = TFile::Open(alienURL);
+        if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
+        else kMC = kFALSE;
+        return;
+      }
+      else if(alienURL.Contains("embededAOD.root"))
+      {
+        kTreeName  = "aodTree";
+        kInputData = "AOD";
+        kMC=kTRUE;
+        return;
+      }
+      else if(alienURL.Contains("galice.root"))
+      {
+        kTreeName  = "TE";
+        kInputData = "MC";
+        kMC=kTRUE;
+        return;
+      } 
+    }
+  }// xml analysis
+  //------------------------------
+  //PROOF files
+  //-----------------------------
+  else if(mode == mPROOF){
+    
+    TFileCollection* coll  = gProof->GetDataSet(kDatasetPROOF)->GetStagedSubset();
+    
+    TIter iter(coll->GetList());
+    
+    TFileInfo* fileInfo = 0;
+    while ((fileInfo = dynamic_cast<TFileInfo*> (iter())))
+    {
+      if (fileInfo->GetFirstUrl()) {
+        TString ProofURL = fileInfo->GetFirstUrl()->GetUrl();
+        cout << "================== " << ProofURL << endl ; 
+        
+        if     (ProofURL.Contains("pass1")) kPass = "pass1";
+        else if(ProofURL.Contains("pass2")) kPass = "pass2";
+        else if(ProofURL.Contains("pass3")) kPass = "pass3";
+        
+        kRun = AliAnalysisManager::GetRunFromAlienPath(ProofURL.Data());
+        printf("Run number from alien path = %d\n",kRun);
+        
+        TFile * fAOD = 0 ; 
+        //Check if file exists and add it, if not skip it
+        if (ProofURL.Contains("AliESDs.root"))  
+        {
+          kTreeName  = "esdTree";
+          kInputData = "ESD";
+          alienURL.ReplaceAll("AliESDs.root","galice.root");
+          if(TFile::Open(ProofURL)) kMC=kTRUE;
+          else kMC = kFALSE;
+          
+          return;
+        }
+        else if(ProofURL.Contains("AliAOD.root"))
+        {
+          kTreeName  = "aodTree";
+          kInputData = "AOD";
+          fAOD = TFile::Open(ProofURL);
+          if(((TTree*) fAOD->Get("aodTree"))->GetBranch("mcparticles")) kMC=kTRUE;
+          else kMC = kFALSE;
+          return;
+        }
+        else if(ProofURL.Contains("embededAOD.root"))
+        {
+          kTreeName  = "aodTree";
+          kInputData = "AOD";
+          kMC=kTRUE;
+          return;
+        }
+        else if(ProofURL.Contains("galice.root"))
+        {
+          kTreeName  = "TE";
+          kInputData = "MC";
+          kMC=kTRUE;
+          return;
+        } 
+      }
+    }
+  }// proof analysis
+  
+  gSystem->ChangeDirectory(ocwd.Data());
+  
+}
 
+//_____________________________________________________________________
+void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs)
+{
+  //Fills chain with data
+  TString ocwd = gSystem->WorkingDirectory();
+  
+  //---------------------------------------
+  // Local files analysis
+  //---------------------------------------
+  if(mode == mLocal){    
+    //If you want to add several ESD files sitting in a common directory INDIR
+    //Specify as environmental variables the directory (INDIR), the number of files 
+    //to analyze (NFILES) and the pattern name of the directories with files (PATTERN)
+    
     if(gSystem->Getenv("INDIR"))  
       kInDir = gSystem->Getenv("INDIR") ; 
     else cout<<"INDIR not set, use default: "<<kInDir<<endl;   
@@ -365,56 +738,55 @@ void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs){
     if ( kInDir  && kFile) {
       printf("Get %d files from directory %s\n",kFile,kInDir);
       if ( ! gSystem->cd(kInDir) ) {//check if ESDs directory exist
-       printf("%s does not exist\n", kInDir) ;
-       return ;
+        printf("%s does not exist\n", kInDir) ;
+        return ;
       }
-
+      
       //if(gSystem->Getenv("XSFILE"))  
       //kXSFileName = gSystem->Getenv("XSFILE") ; 
       //else cout<<" XS file name not set, use default: "<<kXSFileName<<endl;  
       char * kGener = gSystem->Getenv("GENER");
       if(kGener) {
-       cout<<"GENER "<<kGener<<endl;
-       if(!strcmp(kGener,"PYTHIA")) kXSFileName = "pyxsec.root";
-       else if(!strcmp(kGener,"HERWIG")) kXSFileName = "hexsec.root";
-       else cout<<" UNKNOWN GENER, use default: "<<kXSFileName<<endl;
+        cout<<"GENER "<<kGener<<endl;
+        if     (!strcmp(kGener,"PYTHIA")) kXSFileName = "pyxsec.root";
+        else if(!strcmp(kGener,"HERWIG")) kXSFileName = "hexsec.root";
+        else cout<<" UNKNOWN GENER, use default: "<<kXSFileName<<endl;
       }
       else cout<<" GENER not set, use default xs file name: "<<kXSFileName<<endl;
-
-      cout<<"INDIR   : "<<kInDir<<endl;
-      cout<<"NFILES  : "<<kFile<<endl;
-      cout<<"PATTERN : " <<kPattern<<endl;
+      
+      cout<<"INDIR   : "<<kInDir     <<endl;
+      cout<<"NFILES  : "<<kFile      <<endl;
+      cout<<"PATTERN : "<<kPattern   <<endl;
       cout<<"XSFILE  : "<<kXSFileName<<endl;
-
+      
       TString datafile="";
-      if(kInputData == "ESD") datafile = "AliESDs.root" ;
-      else if(kInputData.Contains("AOD")) datafile = "AliAOD.root" ;
-      else if(kInputData == "MC")  datafile = "galice.root" ;
+      if     (kInputData == "ESD")        datafile = "AliESDs.root" ;
+      else if(kInputData.Contains("AOD")) datafile = "AliAOD.root"  ;
+      else if(kInputData == "MC")         datafile = "galice.root"  ;
       
-      //Loop on ESD files, add them to chain
+      //Loop on ESD/AOD/MC files, add them to chain
       Int_t event =0;
       Int_t skipped=0 ; 
       char file[120] ;
       char filexs[120] ;
       
       for (event = 0 ; event < kFile ; event++) {
-       sprintf(file, "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ; 
-       sprintf(filexs, "%s/%s%d/%s", kInDir,kPattern,event,kXSFileName) ; 
-       TFile * fESD = 0 ; 
-       //Check if file exists and add it, if not skip it
-       if ( fESD = TFile::Open(file)) {
-         if ( fESD->Get(kTreeName) ) { 
-           printf("++++ Adding %s\n", file) ;
-           chain->AddFile(file);
-           chainxs->Add(filexs) ; 
-         }
-       }
-       else { 
-         printf("---- Skipping %s\n", file) ;
-         skipped++ ;
-       }
+        sprintf(file,   "%s/%s%d/%s", kInDir,kPattern,event,datafile.Data()) ; 
+        sprintf(filexs, "%s/%s%d/%s", kInDir,kPattern,event,kXSFileName) ; 
+        TFile * fData = 0 ; 
+        //Check if file exists and add it, if not skip it
+        if ( fData = TFile::Open(file)) {
+          if ( fData->Get(kTreeName) ) { 
+            printf("++++ Adding %s\n", file) ;
+            chain->AddFile(file);
+            chainxs->Add(filexs) ; 
+          }
+        }
+        else { 
+          printf("---- Skipping %s\n", file) ;
+          skipped++ ;
+        }
       }
-      printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ;     
     }
     else {
       TString input = "AliESDs.root" ;
@@ -425,37 +797,21 @@ void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs){
   }// local files analysis
   
   //------------------------------
-  //GRID xml files
-  //-----------------------------
+  // GRID xml files
+  //------------------------------
   else if(mode == mGRID){
     //Get colection file. It is specified by the environmental
     //variable XML
-
-    if(gSystem->Getenv("XML") )
-      kXML = gSystem->Getenv("XML");
-    else
-      sprintf(kXML, "collection.xml") ; 
     
-    if (!TFile::Open(kXML)) {
-      printf("No collection file with name -- %s -- was found\n",kXML);
-      return ;
-    }
-    else cout<<"XML file "<<kXML<<endl;
-
-    //Load necessary libraries and connect to the GRID
-    gSystem->Load("libNetx.so") ; 
-    gSystem->Load("libRAliEn.so"); 
-    TGrid::Connect("alien://") ;
-
     //Feed Grid with collection file
-    //TGridCollection * collection =  (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML));
     TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML);
     if (! collection) {
       AliError(Form("%s not found", kXML)) ; 
       return kFALSE ; 
     }
+    
     TGridResult* result = collection->GetGridResult("",0 ,0);
-   
+    
     // Makes the ESD chain 
     printf("*** Getting the Chain       ***\n");
     for (Int_t index = 0; index < result->GetEntries(); index++) {
@@ -467,10 +823,23 @@ void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs){
     }
   }// xml analysis
   
+  //------------------------------
+  // PROOF
+  //------------------------------
+  else if (mode == mPROOF) {
+    
+    TFileCollection* ds= gProof->GetDataSet(kDatasetPROOF)->GetStagedSubset();
+    
+    gROOT->LoadMacro("/afs/in2p3.fr/group/alice/laf/dataset_management/CreateChainFromDataSet.C");
+    chain = CreateChainFromDataSet(ds, kTreeName , kDatasetNMaxFiles);
+    printf("chain has %d entries\n",chain->GetEntries());
+  }
+  
   gSystem->ChangeDirectory(ocwd.Data());
+  
 }
 
-//________________________________________________
+//_________________________________________________________________
 void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr)
 {
   // Read the PYTHIA statistics from the file pyxsec.root created by
@@ -491,7 +860,8 @@ void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr)
   ntr = 0;
   
   Int_t nfiles =  tree->GetEntries()  ;
-  if (tree && nfiles > 0) {
+  if (tree && nfiles > 0) 
+  {
     tree->SetBranchAddress("xsection",&xsection);
     tree->SetBranchAddress("ntrials",&ntrials);
     for(Int_t i = 0; i < nfiles; i++){
@@ -511,5 +881,118 @@ void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr)
   
 }
 
+//______________________________
+void CheckEnvironmentVariables()
+{
+  
+  sprintf(kTrigger,"");
+  
+  Bool_t bRecalibrate = kFALSE;
+  Bool_t bBadChannel = kFALSE;
+  
+  for (int i=0; i< gApplication->Argc();i++){
+    
+#ifdef VERBOSEARGS
+    
+    printf("Arg  %d:  %s\n",i,gApplication->Argv(i));
+    
+#endif
+    
+    TString sRun = "";
+    
+    if (!(strcmp(gApplication->Argv(i),"--trigger")))
+      sprintf(trigger,gApplication->Argv(i+1));
+    
+    if (!(strcmp(gApplication->Argv(i),"--recalibrate")))
+      bRecalibrate = atoi(gApplication->Argv(i+1));
+    
+    if (!(strcmp(gApplication->Argv(i),"--badchannel")))
+      bBadChannel = atoi(gApplication->Argv(i+1));
+    
+    if (!(strcmp(gApplication->Argv(i),"--run"))){
+      sRun = gApplication->Argv(i+1);
+      if(sRun.Contains("LHC10")) {
+        kYear = 2010;
+      }
+      else {
+        if(kRun <=0){
+          kRun = atoi(gApplication->Argv(i+1));
+        }
+        else printf("** Run number already set  to %d, do not set to %d\n",kRun,atoi(gApplication->Argv(i+1)));
+      }//numeric run
+    }//--run available
+    
+  }// args loop
+  
+  if(!sRun.Contains("LHC10")){
+    if ( kRun < 140000) {
+      kYear = 2010;
+      if( kRun >= 136851 ) kCollision = "PbPb";
+    }
+    else{
+      kYear = 2011;
+    }
+  }
+  
+  if(kMC) sprintf(kTrigger,"");
+  
+  printf("*********************************************\n");
+  //printf("*** Settings trigger %s, recalibrate %d, remove bad channels %d, year %d, collision %s, run %d ***\n",
+  //       kTrigger,bRecalibrate,bBadChannel, kYear,kCollision.Data(), kRun);
+  printf("*** Settings year %d, collision %s, run %d ***\n",kYear,kCollision.Data(), kRun);
+  printf("*********************************************\n");
+  
+}
+
+//_______________________________________________
+void AddTaskCounter(const TString trigger = "MB")
+{
+  
+  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+  
+  AliAnalysisTaskCounter * counter =  new AliAnalysisTaskCounter(Form("Counter%s",trigger.Data()));
+  if(kRun > 140000 && kRun < 146900) counter ->RejectFastCluster();
+  if     (kCollision=="pp"  )   counter->SetZVertexCut(50.);  //Open cut
+  else if(kCollision=="PbPb")   counter->SetZVertexCut(10.);  //Centrality defined in this range.
+  
+  if(trigger=="EMC7")
+  {
+    printf("counter trigger EMC7\n");
+    counter->SelectCollisionCandidates(AliVEvent::kEMC7);
+  }
+  else if (trigger=="INT7")
+  {
+    printf("counter trigger INT7\n");
+    counter->SelectCollisionCandidates(AliVEvent::kINT7);
+  }
+  if(trigger=="EMC1")
+  {
+    printf("counter trigger EMC1\n");
+    counter->SelectCollisionCandidates(AliVEvent::kEMC1);
+  }
+  else if(trigger=="MB")
+  {
+    printf("counter trigger MB\n");
+    counter->SelectCollisionCandidates(AliVEvent::kMB);
+  }
+  else if(trigger=="PHOS")
+  {
+    printf("counter trigger PHOS\n");
+    counter->SelectCollisionCandidates(AliVEvent::kPHI7);
+  }
+  
+  TString outputFile = AliAnalysisManager::GetCommonFileName(); 
+  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
+  
+  AliAnalysisDataContainer *coutput = 
+  mgr->CreateContainer(Form("Counter%s",trigger.Data()), TList::Class(), AliAnalysisManager::kOutputContainer,  outputFile.Data());
+  mgr->AddTask(counter);
+  mgr->ConnectInput  (counter, 0, cinput1);
+  mgr->ConnectOutput (counter, 1, coutput);
+  
+}
+
+
+