In [1]:
import ROOT
ROOT.RooMsgService.instance().setGlobalKillBelow(5)
%jsroot on

from matplotlib import pyplot
%matplotlib inline
Welcome to JupyROOT 6.07/07

Preselection Workspace

First we retrieve the workspace created in ExploringData

In [2]:
infile = ROOT.TFile.Open("output/Preselection.root")
w = infile.Get("w")
mc = w.obj("ModelConfig")
data = w.data("data")
x = w.var("x")
mc.LoadSnapshot()

We create a model. The distributions from MC can be used to create our model.

In [3]:
nbkg = w.var("n_bkg")
bkg_t = nbkg.getVal()
nsig = w.var("n_sig")
sig_t = nsig.getVal()
background = ROOT.RooExtendPdf("background","background distribution",w.pdf("bkgpdf"),nbkg) 
signal = ROOT.RooExtendPdf("signal","signal distribution",w.pdf("sigpdf"),nsig)

Now we can define a composite model from these two distributions.

In [4]:
model = ROOT.RooAddPdf("model","model",ROOT.RooArgList(signal,background))

now we can fit to the data!

In [5]:
model.fitTo(data,ROOT.RooFit.Range(0,200),ROOT.RooFit.PrintLevel(-1))
Out[5]:
<ROOT.RooFitResult object at 0x(nil)>
In [6]:
c = ROOT.TCanvas()
plot = x.frame(ROOT.RooFit.Title("Reconstructed Mass"))
plot.SetTitle("")
plot.GetYaxis().SetTitleOffset(1.)
plot.GetYaxis().SetTitleSize(0.05)
plot.GetXaxis().SetTitleSize(0.05)
plot.SetXTitle("MMC mass (GeV)")
data.plotOn(plot,ROOT.RooFit.Name("data"))
#model.plotOn(plot,ROOT.RooFit.Name("ztautau"))
model.plotOn(plot,ROOT.RooFit.Components("background"),ROOT.RooFit.Name("background"), ROOT.RooFit.LineStyle(2), ROOT.RooFit.FillStyle(3001) )
model.plotOn(plot,ROOT.RooFit.Name("signal"), ROOT.RooFit.LineColor(2), ROOT.RooFit.LineStyle(2) )

l = ROOT.TLegend( 0.6, 0.6, 0.9, 0.9)
dataobj = plot.findObject("data")
zobj = plot.findObject("background")
hobj = plot.findObject("signal")

l.AddEntry( dataobj , "Data", "pl" )
l.AddEntry( zobj , "{0:0.0f}% Z#rightarrow#tau#tau events".format(nbkg.getVal()/bkg_t*100), "l"  )
l.AddEntry( hobj , "{0:0.0f}% Higgs events".format(nsig.getVal()/sig_t*100), "l"  )
l.SetTextSizePixels(400)
plot.Draw()
l.Draw()
c.Draw()

VBF workspace

In [7]:
infile = ROOT.TFile.Open("output/VBFselection.root")
w = infile.Get("w")
mc = w.obj("ModelConfig")
data = w.data("data")
mc.LoadSnapshot()
x = w.var("x")
In [8]:
nbkg = w.var("n_bkg")
bkg_t = nbkg.getVal()
nsig = w.var("n_sig")
sig_t = nsig.getVal()
background = ROOT.RooExtendPdf("background","background distribution",w.pdf("bkgpdf"),nbkg) 
signal = ROOT.RooExtendPdf("signal","signal distribution",w.pdf("sigpdf"),nsig)
model = ROOT.RooAddPdf("model","model",ROOT.RooArgList(signal,background))
In [9]:
model.fitTo(data,ROOT.RooFit.Range(0,200),ROOT.RooFit.PrintLevel(-1))
Out[9]:
<ROOT.RooFitResult object at 0x(nil)>
In [10]:
c = ROOT.TCanvas()
plot = x.frame(ROOT.RooFit.Title("Reconstructed Mass"))
plot.SetTitle("")
plot.GetYaxis().SetTitleOffset(1.)
plot.GetYaxis().SetRangeUser(0,1800)
plot.GetYaxis().SetTitleSize(0.05)
plot.GetXaxis().SetTitleSize(0.05)
plot.SetXTitle("MMC mass (GeV)")
data.plotOn(plot,ROOT.RooFit.Name("data"))
model.plotOn(plot,ROOT.RooFit.Components("background"),ROOT.RooFit.Name("background"), ROOT.RooFit.LineStyle(2), ROOT.RooFit.FillStyle(3001) )
model.plotOn(plot,ROOT.RooFit.Name("signal"), ROOT.RooFit.LineColor(2), ROOT.RooFit.LineStyle(2) )

l = ROOT.TLegend( 0.1, 0.6, 0.45, 0.9)
dataobj = plot.findObject("data")
zobj = plot.findObject("background")
hobj = plot.findObject("signal")
l.AddEntry( dataobj , "VBF Data", "pl" )
l.AddEntry( zobj , "{0:0.0f}% of true Z#rightarrow#tau#tau events".format(nbkg.getVal()/bkg_t*100), "l"  )
l.AddEntry( hobj , "{0:0.0f}% of true Higgs(x50) events".format(nsig.getVal()/sig_t*100), "l"  )
l.SetTextSizePixels(400)
plot.Draw()
l.Draw()
c.Draw()

Higgs SR

In [11]:
infile = ROOT.TFile.Open("output/SRselection.root")
w = infile.Get("w")
mc = w.obj("ModelConfig")
data = w.data("data")
mc.LoadSnapshot()
x = w.var("x")
In [12]:
nbkg = w.var("n_bkg")
print bkg_t
bkg_t = nbkg.getVal()
nsig = w.var("n_sig")
sig_t = nsig.getVal()
print sig_t
background = ROOT.RooExtendPdf("background","background distribution",w.pdf("bkgpdf"),nbkg) 
signal = ROOT.RooExtendPdf("signal","signal distribution",w.pdf("sigpdf"),nsig)
model = ROOT.RooAddPdf("model","model",ROOT.RooArgList(signal,background))
7794.33337887
421.876963784
In [13]:
model.fitTo(data,ROOT.RooFit.Range(100,150),ROOT.RooFit.PrintLevel(-1))
Out[13]:
<ROOT.RooFitResult object at 0x(nil)>
In [14]:
c = ROOT.TCanvas()
plot = x.frame(ROOT.RooFit.Title("Reconstructed Mass"))
plot.SetTitle("")
plot.GetYaxis().SetTitleOffset(1.)
plot.GetYaxis().SetRangeUser(0,800)
plot.GetYaxis().SetTitleSize(0.05)
plot.GetXaxis().SetTitleSize(0.05)
plot.SetXTitle("MMC mass (GeV)")
data.plotOn(plot,ROOT.RooFit.Name("data"))
model.plotOn(plot,ROOT.RooFit.Components("background"),ROOT.RooFit.Name("background"), ROOT.RooFit.LineStyle(2), ROOT.RooFit.FillStyle(3001) )
model.plotOn(plot,ROOT.RooFit.Name("signal"), ROOT.RooFit.LineColor(2), ROOT.RooFit.LineStyle(2) )

l = ROOT.TLegend( 0.5, 0.6, 0.9, 0.9)
dataobj = plot.findObject("data")
zobj = plot.findObject("background")
hobj = plot.findObject("signal")
l.AddEntry( dataobj , "VBF Data", "pl" )
l.AddEntry( zobj , "{0:0.0f}% of true Z#rightarrow#tau#tau events".format(nbkg.getVal()/bkg_t*100), "l"  )
l.AddEntry( hobj , "{0:0.0f}% of true Higgs(x10) events".format(nsig.getVal()/sig_t*100), "l"  )
l.SetTextSizePixels(400)
plot.Draw()
l.Draw()
c.Draw()
In [ ]: