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.0, 1.0)
29model = ROOT.RooAddPdf(
"model",
"model", [gx, px], [f])
32modelData = model.generate({x}, 10000)
38r_full = model.fitTo(modelData, Save=
True)
44x.setRange(
"signal", -3, 3)
47r_sig = model.fitTo(modelData, Save=
True, Range=
"signal")
53frame = x.frame(Title=
"Fitting a sub range")
54modelData.plotOn(frame)
55model.plotOn(frame, Range=
"Full", LineColor=
"r", LineStyle=
"--")
59print(
"result of fit on all data ")
61print(
"result of fit in in signal region (note increased error on signal fraction)")
65c = ROOT.TCanvas(
"rf203_ranges",
"rf203_ranges", 600, 600)
66ROOT.gPad.SetLeftMargin(0.15)
67frame.GetYaxis().SetTitleOffset(1.4)
70c.SaveAs(
"rf203_ranges.png")