22x = ROOT.RooRealVar(
"x",
"x", -10, 10)
26p0 = ROOT.RooPolynomial(
"px",
"px", x)
29data = p0.generate(x, 1000)
35wFunc = ROOT.RooFormulaVar(
"w",
"event weight",
"(x*x+10)", [x])
45wdata = ROOT.RooDataSet(data.GetName(), data.GetTitle(), data.get(), Import=data, WeightVar=
"w")
55a0 = ROOT.RooRealVar(
"a0",
"a0", 1)
56a1 = ROOT.RooRealVar(
"a1",
"a1", 0, -1, 1)
57a2 = ROOT.RooRealVar(
"a2",
"a2", 1, 0, 10)
58p2 = ROOT.RooPolynomial(
"p2",
"p2", x, [a0, a1, a2], 0)
67r_ml_wgt = p2.fitTo(wdata, Save=
True, PrintLevel=-1)
82r_ml_wgt_corr = p2.fitTo(wdata, Save=
True, SumW2Error=
True, PrintLevel=-1)
88frame = x.frame(Title=
"Unbinned ML fit, chi^2 fit to weighted data")
91wdata.plotOn(frame, DataError=
"SumW2")
100genPdf = ROOT.RooGenericPdf(
"genPdf",
"x*x+10", [x])
103data2 = genPdf.generate(x, 1000)
106data3 = genPdf.generate(x, 43000)
110r_ml_unw10 = p2.fitTo(data2, Save=
True, PrintLevel=-1)
111r_ml_unw43 = p2.fitTo(data3, Save=
True, PrintLevel=-1)
117binnedData = wdata.binnedClone()
125chi2 = p2.createChi2(binnedData, ROOT.RooFit.DataError(
"SumW2"))
126m = ROOT.RooMinimizer(chi2)
132p2.plotOn(frame, LineStyle=
"--", LineColor=
"r")
141print(
"==> ML Fit results on 1K unweighted events")
143print(
"==> ML Fit results on 43K unweighted events")
145print(
"==> ML Fit results on 1K weighted events with a summed weight of 43K")
147print(
"==> Corrected ML Fit results on 1K weighted events with a summed weight of 43K")
149print(
"==> Chi2 Fit results on 1K weighted events with a summed weight of 43K")
152c = ROOT.TCanvas(
"rf403_weightedevts",
"rf403_weightedevts", 600, 600)
153ROOT.gPad.SetLeftMargin(0.15)
154frame.GetYaxis().SetTitleOffset(1.8)
157c.SaveAs(
"rf403_weightedevts.png")