11from __future__
import print_function
18x = ROOT.RooRealVar(
"x",
"x", -10, 10)
21mx = ROOT.RooRealVar(
"mx",
"mx", 0, -10, 10)
22gx = ROOT.RooGaussian(
"gx",
"gx", x, mx, ROOT.RooFit.RooConst(1))
25px = ROOT.RooPolynomial(
"px",
"px", x)
28f = ROOT.RooRealVar(
"f",
"f", 0., 1.)
29model = ROOT.RooAddPdf(
30 "model",
"model", ROOT.RooArgList(gx, px), ROOT.RooArgList(f))
33modelData = model.generate(ROOT.RooArgSet(x), 10000)
39r_full = model.fitTo(modelData, ROOT.RooFit.Save(ROOT.kTRUE))
45x.setRange(
"signal", -3, 3)
48r_sig = model.fitTo(modelData, ROOT.RooFit.Save(
49 ROOT.kTRUE), ROOT.RooFit.Range(
"signal"))
55frame = x.frame(ROOT.RooFit.Title(
"Fitting a sub range"))
56modelData.plotOn(frame)
58 frame, ROOT.RooFit.Range(
"Full"), ROOT.RooFit.LineStyle(
59 ROOT.kDashed), ROOT.RooFit.LineColor(
64print(
"result of fit on all data ")
66print(
"result of fit in in signal region (note increased error on signal fraction)")
70c = ROOT.TCanvas(
"rf203_ranges",
"rf203_ranges", 600, 600)
71ROOT.gPad.SetLeftMargin(0.15)
72frame.GetYaxis().SetTitleOffset(1.4)
75c.SaveAs(
"rf203_ranges.png")