added merging function for different pt hard bins
authorkleinb <kleinb@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 17 Aug 2009 15:06:34 +0000 (15:06 +0000)
committerkleinb <kleinb@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 17 Aug 2009 15:06:34 +0000 (15:06 +0000)
PWG4/JetTasks/AliAnalysisHelperJetTasks.cxx
PWG4/JetTasks/AliAnalysisHelperJetTasks.h

index b3c5fc48dbafa7dca9a5d724b7f2a91225504e7d..20008803c67041067bb00d8b1dfecd43b03f5d4c 100644 (file)
@@ -1,6 +1,10 @@
 
 #include "TROOT.h"
 #include "TList.h"
+#include "TH1F.h"
+#include "TProfile.h"
+#include "THnSparse.h"
+#include "TFile.h"
 #include "AliMCEvent.h"
 #include "AliAODJet.h"
 #include "AliStack.h"
@@ -194,5 +198,97 @@ void AliAnalysisHelperJetTasks::GetClosestJets(AliAODJet *genJets,const Int_t &n
 
 
 
+void  AliAnalysisHelperJetTasks::MergeOutput(char* cFiles, char* cList){
 
+  // This is used to merge the analysis-output from different 
+  // data samples/pt_hard bins
+  // in case the eventweigth was set to xsection/ntrials already, this
+  // is not needed. Both methods only work in case we do not mix different 
+  // pt_hard bins, and do not have overlapping bins
 
+  const Int_t nMaxBins = 12;
+  // LHC08q jetjet100: Mean = 1.42483e-03, RMS = 6.642e-05
+  // LHC08r jetjet50: Mean = 2.44068e-02, RMS = 1.144e-03
+  // LHC08v jetjet15-50: Mean = 2.168291 , RMS = 7.119e-02
+  // const Float_t xsection[nBins] = {2.168291,2.44068e-02};
+
+  Float_t xsection[nMaxBins];
+  Float_t nTrials[nMaxBins];
+  Float_t sf[nMaxBins];
+  TList *lIn[nMaxBins];
+  TFile *fIn[nMaxBins];
+
+  ifstream in1;
+  in1.open(cFiles);
+
+  char cFile[120];
+  Int_t ibTotal = 0;
+  while(in1>>cFile){
+    fIn[ibTotal] = TFile::Open(cFile);
+    lIn[ibTotal] = (TList*)fIn[ibTotal]->Get(cList);
+    if(!lIn[ibTotal]){
+      Printf("%s:%d No list %s found, exiting...",__FILE__,__LINE__,cList);
+      fIn[ibTotal]->ls();
+      return;
+    }
+    TH1* hTrials = (TH1F*)lIn[ibTotal]->FindObject("fh1Trials");
+    if(!hTrials){
+      Printf("%s:%d fh1PtHard_Trials not found in list, exiting...",__FILE__,__LINE__);
+      return;
+    }
+    TProfile* hXsec = (TProfile*)lIn[ibTotal]->FindObject("fh1Xsec");
+    if(!hXsec){
+      Printf("%s:%d fh1Xsec  not found in list, exiting...",__FILE__,__LINE__);
+      return;
+    }
+    xsection[ibTotal] = hXsec->GetBinContent(1);
+    nTrials[ibTotal] = hTrials->Integral();
+    sf[ibTotal] = xsection[ibTotal]/ nTrials[ibTotal];
+    ibTotal++;
+  }
+
+  if(ibTotal==0){
+    Printf("%s:%d No files found for mergin, exiting",__FILE__,__LINE__);
+    return;
+  }
+
+  TFile *fOut = new TFile("allpt.root","RECREATE");
+  TList *lOut = new TList();
+  lOut->SetName(lIn[0]->GetName());
+  // for the start scale all...
+  for(int ie = 0; ie < lIn[0]->GetEntries();++ie){
+    TH1 *h1Add = 0;
+    THnSparse *hnAdd = 0;
+    for(int ib = 0;ib < ibTotal;++ib){
+      // dynamic cast does not work with cint
+      TObject *h = lIn[ib]->At(ie);
+      if(h->InheritsFrom("TH1")){
+       TH1 *h1 = (TH1*)h;
+       if(ib==0){
+         h1Add = (TH1*)h1->Clone(h1->GetName());
+         h1Add->Scale(sf[ib]);
+       }
+       else{
+         h1Add->Add(h1,sf[ib]);
+       }
+      }
+      else if(h->InheritsFrom("THnSparse")){
+       THnSparse *hn = (THnSparse*)h;
+       if(ib==0){
+         hnAdd = (THnSparse*)hn->Clone(hn->GetName());
+         hnAdd->Scale(sf[ib]);
+       }
+       else{
+         hnAdd->Add(hn,sf[ib]);
+       }
+      }
+      
+
+    }// ib
+    if(h1Add)lOut->Add(h1Add);
+    else if(hnAdd)lOut->Add(hnAdd);
+  }
+  fOut->cd();
+  lOut->Write(lOut->GetName(),TObject::kSingleKey);
+  fOut->Close();
+}
index d0a5798d550e84214a4304fe842567e4382ca8aa..e913b39bc060f66da9c571340d96152917eb8d3b 100644 (file)
@@ -23,11 +23,13 @@ class AliAnalysisHelperJetTasks : public TObject {
                             Int_t *iGenIndex,
                             Int_t *iRecIndex,
                             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
   
 
   private:
   
-  ClassDef(AliAnalysisHelperJetTasks, 1) // 
+  ClassDef(AliAnalysisHelperJetTasks, 1) 
 };
 
 #endif // ALIANALYSISHELPERJETTASKS_H