From 519378fbe50e1a2994792c76db35cc7a15699997 Mon Sep 17 00:00:00 2001 From: kleinb Date: Mon, 12 Oct 2009 12:10:24 +0000 Subject: [PATCH] fill trials in the event loop to avoid wrong numbers on proof --- PWG4/JetTasks/AliAnalysisHelperJetTasks.cxx | 69 ++++++++++++++++++ PWG4/JetTasks/AliAnalysisHelperJetTasks.h | 3 + .../JetTasks/AliAnalysisTaskJFSystematics.cxx | 71 ++++--------------- PWG4/JetTasks/AliAnalysisTaskJFSystematics.h | 6 +- PWG4/JetTasks/AliAnalysisTaskUE.cxx | 60 ++++++++-------- PWG4/JetTasks/AliAnalysisTaskUE.h | 3 +- 6 files changed, 118 insertions(+), 94 deletions(-) diff --git a/PWG4/JetTasks/AliAnalysisHelperJetTasks.cxx b/PWG4/JetTasks/AliAnalysisHelperJetTasks.cxx index d7c1a72d5a2..45acfc21c60 100644 --- a/PWG4/JetTasks/AliAnalysisHelperJetTasks.cxx +++ b/PWG4/JetTasks/AliAnalysisHelperJetTasks.cxx @@ -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(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; +} diff --git a/PWG4/JetTasks/AliAnalysisHelperJetTasks.h b/PWG4/JetTasks/AliAnalysisHelperJetTasks.h index c182b74e429..11324102cdc 100644 --- a/PWG4/JetTasks/AliAnalysisHelperJetTasks.h +++ b/PWG4/JetTasks/AliAnalysisHelperJetTasks.h @@ -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: diff --git a/PWG4/JetTasks/AliAnalysisTaskJFSystematics.cxx b/PWG4/JetTasks/AliAnalysisTaskJFSystematics.cxx index 570957f4154..f408d6386b7 100644 --- a/PWG4/JetTasks/AliAnalysisTaskJFSystematics.cxx +++ b/PWG4/JetTasks/AliAnalysisTaskJFSystematics.cxx @@ -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(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); diff --git a/PWG4/JetTasks/AliAnalysisTaskJFSystematics.h b/PWG4/JetTasks/AliAnalysisTaskJFSystematics.h index f092f78cb0d..6b62676ee9b 100644 --- a/PWG4/JetTasks/AliAnalysisTaskJFSystematics.h +++ b/PWG4/JetTasks/AliAnalysisTaskJFSystematics.h @@ -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 diff --git a/PWG4/JetTasks/AliAnalysisTaskUE.cxx b/PWG4/JetTasks/AliAnalysisTaskUE.cxx index b2514d20a4c..22aa16bf7a4 100644 --- a/PWG4/JetTasks/AliAnalysisTaskUE.cxx +++ b/PWG4/JetTasks/AliAnalysisTaskUE.cxx @@ -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 (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 diff --git a/PWG4/JetTasks/AliAnalysisTaskUE.h b/PWG4/JetTasks/AliAnalysisTaskUE.h index bdd3a3c897d..64dc8f93749 100644 --- a/PWG4/JetTasks/AliAnalysisTaskUE.h +++ b/PWG4/JetTasks/AliAnalysisTaskUE.h @@ -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 -- 2.43.0