import ROOT
ROOT.RooMsgService.instance().setGlobalKillBelow(5)
%jsroot on
from matplotlib import pyplot
%matplotlib inline
First we retrieve the workspace created in ExploringData
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.
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.
model = ROOT.RooAddPdf("model","model",ROOT.RooArgList(signal,background))
now we can fit to the data!
model.fitTo(data,ROOT.RooFit.Range(0,200),ROOT.RooFit.PrintLevel(-1))
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()
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")
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))
model.fitTo(data,ROOT.RooFit.Range(0,200),ROOT.RooFit.PrintLevel(-1))
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()
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")
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))
model.fitTo(data,ROOT.RooFit.Range(100,150),ROOT.RooFit.PrintLevel(-1))
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()