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, ROOT.RooFit.RooConst(1))
27px = ROOT.RooPolynomial(
"px",
"px", x)
30f = ROOT.RooRealVar(
"f",
"f", 0., 1.)
31model = ROOT.RooAddPdf(
32 "model",
"model", ROOT.RooArgList(gx, px), ROOT.RooArgList(f))
35modelData = model.generate(ROOT.RooArgSet(x), 10000)
41r_full = model.fitTo(modelData, ROOT.RooFit.Save(ROOT.kTRUE))
47x.setRange(
"signal", -3, 3)
50r_sig = model.fitTo(modelData, ROOT.RooFit.Save(
51 ROOT.kTRUE), ROOT.RooFit.Range(
"signal"))
57frame = x.frame(ROOT.RooFit.Title(
"Fitting a sub range"))
58modelData.plotOn(frame)
59model.plotOn(frame, ROOT.RooFit.Range(
"Full"), ROOT.RooFit.LineStyle(
60 ROOT.kDashed), ROOT.RooFit.LineColor(ROOT.kRed))
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")