A bit more automatisation for generating V0 spectra from David's trees
authorbelikov <belikov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 26 Dec 2012 15:26:45 +0000 (15:26 +0000)
committerbelikov <belikov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 26 Dec 2012 15:26:45 +0000 (15:26 +0000)
PWGLF/STRANGENESS/LambdaK0PbPb/SpectraV0CutVariations.C [new file with mode: 0644]
PWGLF/STRANGENESS/LambdaK0PbPb/runV0CutVariations.C
PWGLF/STRANGENESS/LambdaK0PbPb/runV0CutVariations.sh

diff --git a/PWGLF/STRANGENESS/LambdaK0PbPb/SpectraV0CutVariations.C b/PWGLF/STRANGENESS/LambdaK0PbPb/SpectraV0CutVariations.C
new file mode 100644 (file)
index 0000000..624a7a0
--- /dev/null
@@ -0,0 +1,259 @@
+#if !defined(__CINT__) || defined(__MAKECINT__)
+   #include <TMath.h>
+   #include <TROOT.h>
+   #include <Riostream.h>
+   #include <TCanvas.h>
+
+   #include <TString.h>
+
+   #include <TFile.h>
+   #include <TList.h>
+   #include <TH1F.h>
+   #include <TH1D.h>
+   #include <TF2.h>
+   #include <TFitResult.h>
+   #include <TFitResultPtr.h>
+   #include <TH2F.h>
+   #include <TH3F.h>
+#endif
+
+   Double_t xbins[]={
+   0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,
+   1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0,
+   2.2,2.4,2.6,2.8,3.0,3.2,3.4,3.6,3.8,4.0,
+   4.5,5.0,5.5,6.5,8.0,10.0,12.0
+   };
+   Int_t nb=sizeof(xbins)/sizeof(Double_t);
+   Int_t nb1=nb-1;
+
+TFile *fAss;
+TFile *fGen;
+TFile *fRaw;
+
+void Generated();
+void Efficiencies(Float_t cMin, Float_t cMax, TString centr);
+void RawYields(Float_t cMin, Float_t cMax, TString centr);
+void Spectra(TString centr);
+
+void SpectraV0CutVariations(Float_t cMin, Float_t cMax, TString centr) {
+
+  fRaw=TFile::Open((centr+"/AliV0CutVariations.root").Data());
+  fAss=TFile::Open((centr+"/AliV0CutVariationsMC.root").Data());
+  fGen=TFile::Open("Generated.root");
+  if (!fGen) {
+     Generated();
+     fGen=TFile::Open("Generated.root");
+  }
+
+  Efficiencies(cMin,cMax,centr);
+  RawYields(cMin,cMax,centr);
+  Spectra(centr);
+
+  fAss->Close();
+  fGen->Close();
+  fRaw->Close();
+}
+
+TH1 *GetEfficiency(Float_t, Float_t, const Char_t *, const Char_t *);
+
+void Efficiencies(Float_t cmin, Float_t cmax, TString centr) {
+
+  TString name;
+
+  TH1 *effK0s=
+  GetEfficiency(cmin, cmax, "fK0sAs","f3dHistPrimRawPtVsYVsMultK0Short");
+  name="eff_K0s_";
+  name+=centr;
+  effK0s->SetName(name.Data());
+
+  TH1 *effLambda=
+  GetEfficiency(cmin, cmax, "fLambdaAs","f3dHistPrimRawPtVsYVsMultLambda");
+  name="eff_Lambda_";
+  name+=centr;
+  effLambda->SetName(name.Data());
+
+  TH1 *effLambdaBar=
+  GetEfficiency(cmin,cmax,"fLambdaBarAs","f3dHistPrimRawPtVsYVsMultAntiLambda");
+  name="eff_LambdaBar_";
+  name+=centr;
+  effLambdaBar->SetName(name.Data());
+
+  TFile *f=TFile::Open("SpectraFromTrees.root","update");
+    effK0s->Write();
+    effLambda->Write();
+    effLambdaBar->Write();
+  f->Close();
+}
+
+TH1 *GetEfficiency(Float_t cMin, Float_t cMax, 
+                  const Char_t *chis, const Char_t *znam) {
+  // Numerator
+  fAss->cd();
+  TH2F *f2d=(TH2F*)gDirectory->Get(chis); f2d->Sumw2();
+  TH1D *hAs=f2d->ProjectionX("hAs",0,-1,"e"); 
+
+  // Denominator
+  fGen->cd();
+  TH3F *f3d = (TH3F*)gDirectory->Get(znam);
+  f3d->Sumw2();
+
+  TH1D *fpt = f3d->ProjectionX("fpt",
+                  f3d->GetYaxis()->FindBin(-0.5+1e-2),
+                  f3d->GetYaxis()->FindBin(+0.5-1e-2),
+                  f3d->GetZaxis()->FindBin(cMin),
+                  f3d->GetZaxis()->FindBin(cMax)
+              );
+   TH1 *hMc=fpt->Rebin(nb1,"hMc",xbins);
+  
+  //Efficiency 
+  TH1 *eff = (TH1*)hAs->Clone();
+  eff->Divide(hAs,hMc,1,1,"b");
+
+  return eff;
+}
+
+void RawYields(Float_t cMin, Float_t cMax, TString centr) {
+  TString name;
+  TH2F *f2d=0;
+
+  //+++ Number of events for normalisation
+  TFile *file=TFile::Open("Merged.root");
+    TList *v0list=(TList *)gFile->Get("PWGLFExtractV0_PP/clistV0");
+    TH1F *fMult=(TH1F*)v0list->FindObject("fHistMultiplicity");
+    Int_t i1=fMult->GetXaxis()->FindBin(cMin+1e-2);
+    Int_t i2=fMult->GetXaxis()->FindBin(cMax+1e-2);
+    Float_t nEvents=fMult->Integral(i1,i2);
+  file->Close();
+
+  fRaw->cd();
+
+  name="raw_K0s_";
+  name+=centr;  
+  f2d=(TH2F*)gDirectory->Get("fK0sSi"); f2d->Sumw2();
+  TH1D *rawK0s=f2d->ProjectionX(name,0,-1,"e");
+  rawK0s->Scale(1/nEvents,"width");
+  name="raw_Lambda_";
+  name+=centr;  
+  f2d=(TH2F*)gDirectory->Get("fLambdaSi"); f2d->Sumw2();
+  TH1D *rawLambda=f2d->ProjectionX(name,0,-1,"e");
+  rawLambda->Scale(1/nEvents,"width");
+  name="raw_LambdaBar_";
+  name+=centr;  
+  f2d=(TH2F*)gDirectory->Get("fLambdaBarSi"); f2d->Sumw2();
+  TH1D *rawLambdaBar=f2d->ProjectionX(name,0,-1,"e");
+  rawLambdaBar->Scale(1/nEvents,"width");
+  TFile *f=TFile::Open("SpectraFromTrees.root","update");
+    rawK0s->Write();
+    rawLambda->Write();
+    rawLambdaBar->Write();
+  f->Close();
+}
+
+void Spectra(TString centr) {
+  TString name;
+  TH1 *eff=0;
+  TH1D *raw=0;
+  TH1D *spe=0;
+
+  TFile *f=TFile::Open("SpectraFromTrees.root","update");
+    name="eff_K0s_";
+    name+=centr;
+    eff = (TH1*)gDirectory->Get(name.Data());
+    name="raw_K0s_";
+    name+=centr;
+    raw = (TH1D*)gDirectory->Get(name.Data());
+    spe = new TH1D(*raw);
+    spe->Divide(eff);
+    name="K0s_";
+    name+=centr;
+    spe->SetName(name.Data());
+    spe->Write();  
+
+    name="eff_Lambda_";
+    name+=centr;
+    eff = (TH1*)gDirectory->Get(name.Data());
+    name="raw_Lambda_";
+    name+=centr;
+    raw = (TH1D*)gDirectory->Get(name.Data());
+    spe = new TH1D(*raw);
+    spe->Divide(eff);
+    name="Lambda_";
+    name+=centr;
+    spe->SetName(name.Data());
+    spe->Write();  
+
+    name="eff_LambdaBar_";
+    name+=centr;
+    eff = (TH1*)gDirectory->Get(name.Data());
+    name="raw_LambdaBar_";
+    name+=centr;
+    raw = (TH1D*)gDirectory->Get(name.Data());
+    spe = new TH1D(*raw);
+    spe->Divide(eff);
+    name="LambdaBar_";
+    name+=centr;
+    spe->SetName(name.Data());
+    spe->Write();  
+  f->Close();
+}
+
+void Generated() {
+  TList *v0listMC=0;
+  TH3F *h3=0;
+  //
+  TFile::Open("LHC11a10b_plus/Merged.root");  
+  v0listMC=(TList *)gFile->Get("PWGLFExtractPerformanceV0_PP_MC/clistV0MC");
+
+  TH3F *k0s = 
+    (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultK0Short");
+  TH3F *k0s_nonInj = 
+    (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultNonInjK0Short");
+
+  TH3F *lam = 
+    (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultLambda");
+  TH3F *lam_nonInj = 
+    (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultNonInjLambda");
+
+  TH3F *alam = 
+    (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultAntiLambda");
+  TH3F *alam_nonInj = 
+    (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultNonInjAntiLambda");
+
+
+  //    
+  TFile::Open("LHC11a10b_bis/Merged.root");  
+  v0listMC=(TList *)gFile->Get("PWGLFExtractPerformanceV0_PP_MC/clistV0MC");
+
+  h3 = (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultK0Short");
+  k0s->Add(h3);
+  h3 = (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultNonInjK0Short");
+  k0s_nonInj->Add(h3); 
+
+  h3 = (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultLambda");
+  lam->Add(h3); 
+  h3 = (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultNonInjLambda");
+  lam_nonInj->Add(h3); 
+
+  h3 = (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultAntiLambda");
+  alam->Add(h3); 
+  h3 = (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultNonInjAntiLambda");
+  alam_nonInj->Add(h3); 
+
+  //
+  TFile::Open("LHC11a10a_bis/Merged.root");
+  h3 = (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultK0Short");
+  k0s_nonInj->Add(h3); 
+  h3 = (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultLambda");
+  lam_nonInj->Add(h3); 
+  h3 = (TH3F*)v0listMC->FindObject("f3dHistPrimRawPtVsYVsMultAntiLambda");
+  alam_nonInj->Add(h3); 
+
+  TFile *f=TFile::Open("Generated.root","new");
+  k0s->Write(); k0s_nonInj->Write();
+  lam->Write(); lam_nonInj->Write();
+  alam->Write(); alam_nonInj->Write();
+  f->Close();
+}
index 0d8908f..8e14cdb 100644 (file)
@@ -1,4 +1,7 @@
-void runV0CutVariations(Double_t cmin, Double_t cmax, Bool_t isMC=kFALSE, Bool_t selectNonInjected=kFALSE) {
+void runV0CutVariations(
+Double_t cmin, Double_t cmax, 
+Bool_t isMC=kFALSE, Bool_t selectNonInjected=kFALSE,
+TString fname) {
    TProof::Open("");
 
    TChain *ch=new TChain("chain");
@@ -11,11 +14,13 @@ void runV0CutVariations(Double_t cmin, Double_t cmax, Bool_t isMC=kFALSE, Bool_t
    selector->SetSelectNonInjected(selectNonInjected);
 
    if (isMC) {
-    ch->Add("LHC11a10b_plus/Merged.root/PWGLFExtractPerformanceV0_PP_MC/fTree");
+      fname += "/PWGLFExtractPerformanceV0_PP_MC/fTree";
    } else {
-     ch->Add("LHC10h_pass2/Merged.root/PWGLFExtractV0_PP/fTree");
+      fname += "/PWGLFExtractV0_PP/fTree";
    }
 
-   ch->Process(selector);
+   cout<<"Running over "<<fname.Data()<<endl;
 
+   ch->Add(fname.Data());  
+   ch->Process(selector);
 }
index 9f4b6ab..3ea011d 100755 (executable)
@@ -1,14 +1,50 @@
 #
-prod=LHC11a10b_plus
+centrality="0005 0010 1020 2040 4060 6080 8090"
 
-for dir in 0005 0010 1020 2040 4060 6080 8090
+production="LHC11a10b_bis LHC11a10b_bis"
+
+
+#### Real data
+fn=LHC10h_pass2/Merged.root
+for dir in $centrality
+do
+  s=${dir:0:2}; e=${dir:2:2}
+  echo $dir $s $e
+  root.exe -q runV0CutVariations.C\($s,$e,kFALSE,kFALSE,\"$fn\"\) >& real.log
+  mv AliV0CutVariations.root real.log $dir
+done
+
+echo
+echo
+
+#### Injected MC productions
+for prod in $production
+do
+    echo "Injected MC production $prod"
+    fn=$prod/Merged.root
+    for dir in $centrality
+    do
+        s=${dir:0:2}; e=${dir:2:2}
+        echo $dir $s $e
+        echo "Non-injected"
+      root.exe -q runV0CutVariations.C\($s,$e,kTRUE,kTRUE,\"$fn\"\) >& MC_nonInj.log
+        echo "All"
+      root.exe -q runV0CutVariations.C\($s,$e,kTRUE,kFALSE,\"$fn\"\) >& MC.log
+        mkdir $dir/$prod
+        mv AliV0CutVariationsMC_nonInj.root AliV0CutVariationsMC.root MC_nonInj.log MC.log $dir/$prod
+    done
+done
+
+echo
+echo 
+
+#### Merge efficiency input
+for dir in $centrality
 do
   s=${dir:0:2}; e=${dir:2:2}
   echo $dir $s $e
-  echo "root.exe -q run.C\\($s,$e,kTRUE,kTRUE\\)"  # MC, select non-injected
-     root.exe -q runV0CutVariations.C\($s,$e,kTRUE,kTRUE\) >& MC_nonInj.log
-  echo "root.exe -q run.C\\($s,$e,kTRUE,kFALSE\\)"  # MC
-     root.exe -q runV0CutVariations.C\($s,$e,kTRUE,kFALSE\) >& MC.log
-  mkdir $dir/$prod
-  mv AliV0CutVariationsMC_nonInj.root AliV0CutVariationsMC.root MC_nonInj.log MC.log $dir/$prod
+  cd $dir
+  hadd AliV0CutVariationsMC.root `find . -name "AliV0CutVariationsMC.root"`
+  hadd AliV0CutVariationsMC_nonInj.root `find . -name "AliV0CutVariationsMC_nonInj.root"`
+  cd ..
 done