15from __future__
import print_function
23x = ROOT.RooRealVar(
"x",
"x", -10, 10)
27p0 = ROOT.RooPolynomial(
"px",
"px", x)
30data = p0.generate({x}, 1000)
36wFunc = ROOT.RooFormulaVar(
"w",
"event weight",
"(x*x+10)", [x])
39w = data.addColumn(wFunc)
46wdata = ROOT.RooDataSet(data.GetName(), data.GetTitle(), data, data.get(),
"", w.GetName())
56a0 = ROOT.RooRealVar(
"a0",
"a0", 1)
57a1 = ROOT.RooRealVar(
"a1",
"a1", 0, -1, 1)
58a2 = ROOT.RooRealVar(
"a2",
"a2", 1, 0, 10)
59p2 = ROOT.RooPolynomial(
"p2",
"p2", x, [a0, a1, a2], 0)
68r_ml_wgt = p2.fitTo(wdata, Save=
True)
83r_ml_wgt_corr = p2.fitTo(wdata, Save=
True, SumW2Error=
True)
89frame = x.frame(Title=
"Unbinned ML fit, chi^2 fit to weighted data")
92wdata.plotOn(frame, DataError=
"SumW2")
101genPdf = ROOT.RooGenericPdf(
"genPdf",
"x*x+10", [x])
104data2 = genPdf.generate({x}, 1000)
107data3 = genPdf.generate({x}, 43000)
111r_ml_unw10 = p2.fitTo(data2, Save=
True)
112r_ml_unw43 = p2.fitTo(data3, Save=
True)
118binnedData = wdata.binnedClone()
126chi2 = ROOT.RooChi2Var(
"chi2",
"chi2", p2, binnedData, ROOT.RooFit.DataError(
"SumW2"))
127m = ROOT.RooMinimizer(chi2)
133p2.plotOn(frame, LineStyle=
"--", LineColor=
"r")
142print(
"==> ML Fit results on 1K unweighted events")
144print(
"==> ML Fit results on 43K unweighted events")
146print(
"==> ML Fit results on 1K weighted events with a summed weight of 43K")
148print(
"==> Corrected ML Fit results on 1K weighted events with a summed weight of 43K")
150print(
"==> Chi2 Fit results on 1K weighted events with a summed weight of 43K")
153c = ROOT.TCanvas(
"rf403_weightedevts",
"rf403_weightedevts", 600, 600)
154ROOT.gPad.SetLeftMargin(0.15)
155frame.GetYaxis().SetTitleOffset(1.8)
158c.SaveAs(
"rf403_weightedevts.png")