fill trials in the event loop to avoid wrong numbers on proof
authorkleinb <kleinb@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 12 Oct 2009 12:10:24 +0000 (12:10 +0000)
committerkleinb <kleinb@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 12 Oct 2009 12:10:24 +0000 (12:10 +0000)
PWG4/JetTasks/AliAnalysisHelperJetTasks.cxx
PWG4/JetTasks/AliAnalysisHelperJetTasks.h
PWG4/JetTasks/AliAnalysisTaskJFSystematics.cxx
PWG4/JetTasks/AliAnalysisTaskJFSystematics.h
PWG4/JetTasks/AliAnalysisTaskUE.cxx
PWG4/JetTasks/AliAnalysisTaskUE.h

index d7c1a72d5a270477c8433102858dcc11d2b056b5..45acfc21c60a6a2e29de7ba300756b254cbc637a 100644 (file)
@@ -1,10 +1,13 @@
 
 #include "TROOT.h"
+#include "TKey.h"
 #include "TList.h"
+#include "TSystem.h"
 #include "TH1F.h"
 #include "TProfile.h"
 #include "THnSparse.h"
 #include "TFile.h"
+#include "TString.h"
 #include "AliMCEvent.h"
 #include "AliLog.h"
 #include "AliAODJet.h"
@@ -302,3 +305,69 @@ void  AliAnalysisHelperJetTasks::MergeOutput(char* cFiles, char* cList){
   lOut->Write(lOut->GetName(),TObject::kSingleKey);
   fOut->Close();
 }
+
+Bool_t AliAnalysisHelperJetTasks::PythiaInfoFromFile(const char* currFile,Float_t &fXsec,Float_t &fTrials){
+  //
+  // get the cross section and the trails either from pyxsec.root or from pysec_hists.root
+  // This is to called in Notify and should provide the path to the AOD/ESD file
+
+  TString file(currFile);  
+  fXsec = 0;
+  fTrials = 1;
+
+  if(file.Contains("root_archive.zip#")){
+    Ssiz_t pos1 = file.Index("root_archive",12,TString::kExact);
+    Ssiz_t pos = file.Index("#",1,pos1,TString::kExact);
+    file.Replace(pos+1,20,"");
+  }
+  else {
+    // not an archive take the basename....
+    file.ReplaceAll(gSystem->BaseName(file.Data()),"");
+  }
+  Printf("%s",file.Data());
+  
+   
+
+  TFile *fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec.root")); // problem that we cannot really test the existance of a file in a archive so we have to lvie with open error message from root
+  if(!fxsec){
+    // next trial fetch the histgram file
+    fxsec = TFile::Open(Form("%s%s",file.Data(),"pyxsec_hists.root"));
+    if(!fxsec){
+       // not a severe condition but inciate that we have no information
+      return kFALSE;
+    }
+    else{
+      // find the tlist we want to be independtent of the name so use the Tkey
+      TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0); 
+      if(!key){
+       fxsec->Close();
+       return kFALSE;
+      }
+      TList *list = dynamic_cast<TList*>(key->ReadObj());
+      if(!list){
+       fxsec->Close();
+       return kFALSE;
+      }
+      fXsec = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
+      fTrials  = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
+      fxsec->Close();
+    }
+  } // no tree pyxsec.root
+  else {
+    TTree *xtree = (TTree*)fxsec->Get("Xsection");
+    if(!xtree){
+      fxsec->Close();
+      return kFALSE;
+    }
+    UInt_t   ntrials  = 0;
+    Double_t  xsection  = 0;
+    xtree->SetBranchAddress("xsection",&xsection);
+    xtree->SetBranchAddress("ntrials",&ntrials);
+    xtree->GetEntry(0);
+    fTrials = ntrials;
+    fXsec = xsection;
+    fxsec->Close();
+  }
+  return kTRUE;
+}
index c182b74e42970caf88e8f78bde49a31d269eaaed..11324102cdc3b9f986cd6adc18901700333d2791 100644 (file)
@@ -5,6 +5,7 @@
 #include "TObject.h"
 class AliMCEvent;
 class AliAODJet;
+class TString;
 class AliGenPythiaEventHeader;
 
 // Helper Class that contains a lot of usefull static functions (i.e. for Flavor selection.
@@ -25,6 +26,8 @@ class AliAnalysisHelperJetTasks : public TObject {
                             Int_t iDebug, Float_t maxDist = 0.5);
 
   static void MergeOutput(char* cFiles, char* cList = "pwg4spec"); // Merges the files in the input text file  needs the two histograms fh1PtHard_Trials, fh1Xsec and the name of the input list
+  static Bool_t PythiaInfoFromFile(const char* currFile,Float_t &fXsec,Float_t &fTrials);// get the cross section and the trails either from pyxsec.root or from pysec_hists.root
+
   
   enum {kMaxJets = 6}; //  needed for array size not to fragemnt memory on the heap by many new/delete 
   private:
index 570957f415405faec08a83bbfc3a94ba01632737..f408d6386b72bbc6f34e7106ba52c8756d520182 100644 (file)
@@ -79,6 +79,7 @@ AliAnalysisTaskJFSystematics::AliAnalysisTaskJFSystematics(): AliAnalysisTaskSE(
   fAnalysisType(0),
   fExternalWeight(1),    
   fRecEtaWindow(0.5),
+  fAvgTrials(1),
   fh1Xsec(0x0),
   fh1Trials(0x0),
   fh1PtHard(0x0),
@@ -126,6 +127,7 @@ AliAnalysisTaskJFSystematics::AliAnalysisTaskJFSystematics(const char* name):
   fAnalysisType(0),
   fExternalWeight(1),    
   fRecEtaWindow(0.5),
+  fAvgTrials(1),
   fh1Xsec(0x0),
   fh1Trials(0x0),
   fh1PtHard(0x0),
@@ -172,9 +174,8 @@ Bool_t AliAnalysisTaskJFSystematics::Notify()
   // and number of trials from pyxsec.root
   // 
   TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
-  Double_t xsection = 0;
-  UInt_t   ntrials  = 0;
-  Float_t   ftrials  = 0;
+  Float_t xsection = 0;
+  Float_t ftrials  = 1;
   if(tree){
     TFile *curfile = tree->GetCurrentFile();
     if (!curfile) {
@@ -185,59 +186,11 @@ Bool_t AliAnalysisTaskJFSystematics::Notify()
       Printf("%s%d No Histogram fh1Xsec",(char*)__FILE__,__LINE__);
       return kFALSE;
     }
-
-    TString fileName(curfile->GetName());
-    if(fileName.Contains("AliESDs.root")){
-        fileName.ReplaceAll("AliESDs.root", "");
-    }
-    else if(fileName.Contains("AliAOD.root")){
-        fileName.ReplaceAll("AliAOD.root", "");
-    }
-    else if(fileName.Contains("AliAODs.root")){
-        fileName.ReplaceAll("AliAODs.root", "");
-    }
-    else if(fileName.Contains("galice.root")){
-        // for running with galice and kinematics alone...                      
-        fileName.ReplaceAll("galice.root", "");
-    }
-    TFile *fxsec = TFile::Open(Form("%s%s",fileName.Data(),"pyxsec.root"));
-    if(!fxsec){
-      if(fDebug>0)Printf("%s:%d %s not found in the Input",(char*)__FILE__,__LINE__,Form("%s%s",fileName.Data(),"pyxsec.root"));
-      // next trial fetch the histgram file
-      fxsec = TFile::Open(Form("%s%s",fileName.Data(),"pyxsec_hists.root"));
-      if(!fxsec){
-       // not a severe condition
-       if(fDebug>0)Printf("%s:%d %s not found in the Input",(char*)__FILE__,__LINE__,Form("%s%s",fileName.Data(),"pyxsec_hists.root"));        
-       return kTRUE;
-      }
-      else{
-       // find the tlist we want to be independtent of the name so use the Tkey
-       TKey* key = (TKey*)fxsec->GetListOfKeys()->At(0); 
-       if(!key){
-         if(fDebug>0)Printf("%s:%d key not found in the file",(char*)__FILE__,__LINE__);       
-         return kTRUE;
-       }
-       TList *list = dynamic_cast<TList*>(key->ReadObj());
-       if(!list){
-         if(fDebug>0)Printf("%s:%d key is not a tlist",(char*)__FILE__,__LINE__);      
-         return kTRUE;
-       }
-       xsection = ((TProfile*)list->FindObject("h1Xsec"))->GetBinContent(1);
-       ftrials  = ((TH1F*)list->FindObject("h1Trials"))->GetBinContent(1);
-      }
-    }
-    else{
-      TTree *xtree = (TTree*)fxsec->Get("Xsection");
-      if(!xtree){
-       Printf("%s:%d tree not found in the pyxsec.root",(char*)__FILE__,__LINE__);
-      }
-      xtree->SetBranchAddress("xsection",&xsection);
-      xtree->SetBranchAddress("ntrials",&ntrials);
-      ftrials = ntrials;
-      xtree->GetEntry(0);
-    }
+    AliAnalysisHelperJetTasks::PythiaInfoFromFile(curfile->GetName(),xsection,ftrials);
     fh1Xsec->Fill("<#sigma>",xsection);
-    fh1Trials->Fill("#sum{ntrials}",ftrials);
+    // construct a poor man average trials 
+    Float_t nEntries = (Float_t)tree->GetTree()->GetEntries();
+    if(ftrials>=nEntries)fAvgTrials = ftrials/nEntries; 
   }
   return kTRUE;
 }
@@ -297,7 +250,7 @@ void AliAnalysisTaskJFSystematics::UserCreateOutputObjects()
   fh1Xsec = new TProfile("fh1Xsec","xsec from pyxsec.root",1,0,1);
   fh1Xsec->GetXaxis()->SetBinLabel(1,"<#sigma>");
 
-  fh1Trials = new TH1F("fh1Trials","trials from pyxsec.root",1,0,1);
+  fh1Trials = new TH1F("fh1Trials","trials event header or pyxsec file",1,0,1);
   fh1Trials->GetXaxis()->SetBinLabel(1,"#sum{ntrials}");
 
   fh1PtHard = new TH1F("fh1PtHard","PYTHIA Pt hard;p_{T,hard}",nBinPt,binLimitsPt);
@@ -434,9 +387,6 @@ void AliAnalysisTaskJFSystematics::UserExec(Option_t */*option*/)
     }
   }
   
-
-
-
   if (fDebug > 1)printf("AliAnalysisTaskJFSystematics::Analysing event # %5d\n", (Int_t) fEntry);
 
   // ========= These pointers need to be valid in any case ======= 
@@ -508,6 +458,9 @@ void AliAnalysisTaskJFSystematics::UserExec(Option_t */*option*/)
     }
   }// if we had the MCEvent
 
+  if(nTrials==1&&fAvgTrials>1) fh1Trials->Fill("#sum{ntrials}",fAvgTrials); 
+  else fh1Trials->Fill("#sum{ntrials}",nTrials); 
+
   fh1PtHard->Fill(ptHard,eventW);
   fh1PtHardNoW->Fill(ptHard,1);
   fh1PtHardTrials->Fill(ptHard,nTrials);
index f092f78cb0d3cb29c2e02dbd56f62d1624425847..6b62676ee9b8bd433dbc12a08dfe9fa96e70310f 100644 (file)
@@ -78,10 +78,10 @@ class AliAnalysisTaskJFSystematics : public AliAnalysisTaskSE
     Bool_t        fUseAODInput;           // use AOD input
     Bool_t        fUseExternalWeightOnly; // use only external weight
     Bool_t        fLimitGenJetEta;        // Limit the eta of the generated jets
-    UInt_t         fAnalysisType;          // Analysis type 
+    UInt_t        fAnalysisType;          // Analysis type 
     Float_t       fExternalWeight;        // external weight
     Float_t       fRecEtaWindow;          // eta window used for corraltion plots between rec and gen 
-
+    Float_t       fAvgTrials;             // average number of trials from pyxsec.root or pysec_hists.root in case trials are not avaiable from the MC Header
     // Event histograms
     TProfile*     fh1Xsec;    // pythia cross section and trials
     TH1F*         fh1Trials;  // trials are added
@@ -114,7 +114,7 @@ class AliAnalysisTaskJFSystematics : public AliAnalysisTaskSE
     TList *fHistList; // Output list
     
 
-    ClassDef(AliAnalysisTaskJFSystematics, 1) // Analysis task for standard jet analysis
+    ClassDef(AliAnalysisTaskJFSystematics, 2) // Analysis task for standard jet analysis
 };
  
 #endif
index b2514d20a4c317be5a569f55ac96ece891473318..22aa16bf7a4895bc7ce27f2036024a21c729723b 100644 (file)
@@ -108,6 +108,7 @@ fJet2RatioPtCut(0.8),
 fJet3PtCut(15.),
 fTrackPtCut(0.),
 fTrackEtaCut(0.9),
+  fAvgTrials(1),
 fhNJets(0x0),
 fhEleadingPt(0x0),
 fhMinRegPtDist(0x0),
@@ -147,10 +148,12 @@ Bool_t AliAnalysisTaskUE::Notify()
   //
   // Implemented Notify() to read the cross sections
   // and number of trials from pyxsec.root
-  // Copy from AliAnalysisTaskJetSpectrum
+  // Copy from AliAnalysisTaskJFSystematics
+  // 
+
   TTree *tree = AliAnalysisManager::GetAnalysisManager()->GetTree();
-  Double_t xsection = 0;
-  UInt_t   ntrials  = 0;
+  Float_t xsection = 0;
+  Float_t ftrials  = 1;
   if(tree){
     TFile *curfile = tree->GetCurrentFile();
     if (!curfile) {
@@ -161,35 +164,12 @@ Bool_t AliAnalysisTaskUE::Notify()
       Printf("%s%d No Histogram fh1Xsec",(char*)__FILE__,__LINE__);
       return kFALSE;
     }
-    
-    TString fileName(curfile->GetName());
-    if(fileName.Contains("AliESDs.root")){
-      fileName.ReplaceAll("AliESDs.root", "pyxsec.root");
-    }
-    else if(fileName.Contains("AliAOD.root")){
-      fileName.ReplaceAll("AliAOD.root", "pyxsec.root");
-    }
-    else if(fileName.Contains("galice.root")){
-      // for running with galice and kinematics alone...                      
-      fileName.ReplaceAll("galice.root", "pyxsec.root");
-    }
-    TFile *fxsec = TFile::Open(fileName.Data());
-    if(!fxsec){
-      Printf("%s:%d %s not found in the Input",(char*)__FILE__,__LINE__,fileName.Data());
-      // no a severe condition
-      return kTRUE;
-    }
-    TTree *xtree = (TTree*)fxsec->Get("Xsection");
-    if(!xtree){
-      Printf("%s:%d tree not found in the pyxsec.root",(char*)__FILE__,__LINE__);
-    }
-    xtree->SetBranchAddress("xsection",&xsection);
-    xtree->SetBranchAddress("ntrials",&ntrials);
-    xtree->GetEntry(0);
+    AliAnalysisHelperJetTasks::PythiaInfoFromFile(curfile->GetName(),xsection,ftrials);
     fh1Xsec->Fill("<#sigma>",xsection);
-    fh1Trials->Fill("#sum{ntrials}",ntrials);
-  }
-  
+    // construct average trials 
+    Float_t nEntries = (Float_t)tree->GetTree()->GetEntries();
+    if(ftrials>=nEntries)fAvgTrials = ftrials/nEntries; 
+  }  
   return kTRUE;
 }
 
@@ -260,6 +240,24 @@ void  AliAnalysisTaskUE::Exec(Option_t */*option*/)
   // Execute analysis for current event
   //
   if ( fDebug > 3 ) AliInfo( " Processing event..." );
+
+  // fetch the pythia header info and get the trials
+  AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
+  Float_t nTrials = 1;
+  if (mcHandler) {  
+    AliMCEvent* mcEvent = mcHandler->MCEvent();
+    if (mcEvent) {
+      AliGenPythiaEventHeader*  pythiaGenHeader = AliAnalysisHelperJetTasks::GetPythiaEventHeader(mcEvent);
+      if(pythiaGenHeader){
+       nTrials = pythiaGenHeader->Trials();
+      }
+    }
+  }
+
+  if(nTrials==1&&fAvgTrials>1) fh1Trials->Fill("#sum{ntrials}",fAvgTrials); 
+  else fh1Trials->Fill("#sum{ntrials}",nTrials); 
+  
+
   AnalyseUE();
   
   // Post the data
index bdd3a3c897dde65be574eecc9c54e6fd0df41127..64dc8f937495bd4837e7f65b9db416bde6f92934 100644 (file)
@@ -153,6 +153,7 @@ class  AliAnalysisTaskUE : public AliAnalysisTask
     // track cuts
     Double_t   fTrackPtCut;       // Pt cut of tracks in the regions
     Double_t   fTrackEtaCut;      // Eta cut on tracks in the regions (fRegionType=1)
+    Double_t   fAvgTrials;        // average trials used to fill the fh1Triasl histogram in case we do not have trials on a event by event basis
     
     // Histograms    ( are owned by fListOfHistos TList )
     TH1F*  fhNJets;                  //!
@@ -190,7 +191,7 @@ class  AliAnalysisTaskUE : public AliAnalysisTask
     
     
     
-    ClassDef( AliAnalysisTaskUE, 1); // Analysis task for Underlying Event analysis
+    ClassDef( AliAnalysisTaskUE, 2); // Analysis task for Underlying Event analysis
   };
 
 #endif