# Stack plot with uncertainties

Dear experts,

I am making a stack plot which includes all the Background MC samples. Appropriate snippet of the code:

``````from PlotterToolsDataMC import *
from ROOT import *
#gStyle.SetOptStat(0)
#gROOT.SetBatch(kTRUE)
#first loop over all variables
for v in Vars:
hists = []
hists2 = []
leg = TLegend(0.6, 0.8, 0.89, 0.89)

leg.SetBorderSize(0)
Max = -0.
Max2 = -0.
for fi,f in enumerate(MC):  ## get all MC plots, because they have to stacked!
ch = TChain('H4GSel')
hname = v+'_'+str(fi)
h = TH1F(hname, v, v, v, v)
ch.Draw(v+'>>'+hname,TCut(genCut)) ## add cut based on what you want to plot, blind or unblind or anything else
#total1 = h.Integral
#print total1
h.Scale(float(f),"nosw2")
#h.Scale(1/float(h.Integral()))
h.SetLineColor(f)
h.SetLineWidth(2)
h.SetFillColor(f)
h.Sumw2()
mc_copy = h.Clone("copy")
hists.append([h,ch,f])
if h.GetMaximum() > Max:
Max = h.GetMaximum()
c0 = TCanvas('a','a',800,2000)   ##now starts the drawing part, start by stacking all the MC up + add a ratio plot
SetOwnership(c0,False)
s = THStack("s","")
for fi,hh in enumerate(hists):
hh.SetMaximum(Max*1.5)
hh.SetMinimum(0.0001)
if fi == 0:
hh.Draw('')
if fi > 0:
hh.Draw('same')
if fi == 0:
if fi == 2:
if fi == 5:
#h_err = TH1F(h_err, h_err, 35, 100,180)
s.Draw("hist E2")
s.GetXaxis().SetTitle(v)
s.GetYaxis().SetTitle('Normalized Yields')
s.GetYaxis().SetTitleOffset(1.6)
s.SetMaximum(100000)
``````

While drawing the histograms for the individual samples I store the sum of the weights and on adding them to the stack, draw the stack with the E2 option.
What I expect to see is the total uncertainty due to all the samples, however the plot being created is showing uncertainties on the individual samples.

Screen Shot 2017-10-26 at 11.12.26 AM

I was under the impression that by means of creating a stack, the E2 draw option would display the total uncertainty.
Is there a bug in my code or is there any other way to achieve this?

Thanks,
Tanvi

A stack is just a collection of histogram. It allows to compute a global range at drawing time. The drawing options apply to individual axis. To do what you want you should create a new histogram which is the sum of the individual histograms you put in the stack.

Hi Olivier,

Thanks for the tip! Just for confirmation -

This new histogram (which is the sum of all histograms) should be plotted separately on top of the stack with the E2 option?

Thanks again
Tanvi

Yes with option “E2 SAME”

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.