Hi all,
I met a technical problem in putting several histograms together and combining them. What happens when running my code is that the previous histogram always disappear when a new histogram is drawn. This is because of the scope of the Python language. Thank Danilo Piparo for providing the correct code. The problem is solved. I’m posting this problem and solution here so that people who meet similar problem in the future can reference it.
------------------------original code (not working)--------------------------
from ROOT import *
from glob import glob
gROOT.Reset()
gStyle.SetOptStat(0)
inputDir="NtupleToHist/hist_generated/*.root"
c1 = TCanvas( 'c1', 'Example'',700, 500 )
val = 0
for filename in glob(inputDir):
print filename
f1=TFile(filename, 'R')
hist=f1.Get("hist_1Lep_ttbar_2tag3jet_75_150ptv_WhfSR_BDT_Nominal")
hist.SetName("hist_1Lep_ttbar_2tag3jet_75_150ptv_WhfSR_BDT_Nominal")
hist.Rebin(20)
val = val + 1
hist.SetLineColor(val)
hist.Scale(1/hist.Integral())
hist.Draw("same")
c1.Update()
c1.SaveAs("example.eps")
Best,
Peilong