13from __future__
import print_function
20x = ROOT.RooRealVar(
"x",
"x", -10, 10)
23mx = ROOT.RooRealVar(
"mx",
"mx", 0, -10, 10)
24gx = ROOT.RooGaussian(
"gx",
"gx", x, mx, 1.0)
27px = ROOT.RooPolynomial(
"px",
"px", x)
30f = ROOT.RooRealVar(
"f",
"f", 0.0, 1.0)
31model = ROOT.RooAddPdf(
"model",
"model", [gx, px], [f])
34modelData = model.generate({x}, 10000)
40r_full = model.fitTo(modelData, Save=
True, PrintLevel=-1)
46x.setRange(
"signal", -3, 3)
49r_sig = model.fitTo(modelData, Save=
True, Range=
"signal", PrintLevel=-1)
55frame = x.frame(Title=
"Fitting a sub range")
56modelData.plotOn(frame)
57model.plotOn(frame, Range=
"Full", LineColor=
"r", LineStyle=
"--")
61print(
"result of fit on all data ")
63print(
"result of fit in in signal region (note increased error on signal fraction)")
67c = ROOT.TCanvas(
"rf203_ranges",
"rf203_ranges", 600, 600)
68ROOT.gPad.SetLeftMargin(0.15)
69frame.GetYaxis().SetTitleOffset(1.4)
72c.SaveAs(
"rf203_ranges.png")