12from __future__
import print_function
20x = ROOT.RooRealVar(
"x",
"x", -10, 10)
22m = ROOT.RooRealVar(
"m",
"m", 0, -10, 10)
23s = ROOT.RooRealVar(
"s",
"s", 2, 0.1, 10)
24gauss = ROOT.RooGaussian(
"gauss",
"gauss(x,m,s)", x, m, s)
27poly = ROOT.RooPolynomial(
"poly",
"poly(x)", x)
30f = ROOT.RooRealVar(
"f",
"f", 0.5, 0., 1.)
31model = ROOT.RooAddPdf(
40d = model.generate(ROOT.RooArgSet(x), 50)
47fconstraint = ROOT.RooGaussian(
51 ROOT.RooFit.RooConst(0.8),
52 ROOT.RooFit.RooConst(0.1))
62modelc = ROOT.RooProdPdf(
63 "modelc",
"model with constraint", ROOT.RooArgList(model, fconstraint))
66r1 = model.fitTo(d, ROOT.RooFit.Save())
71 ROOT.RooFit.Constrain(
80fconstext = ROOT.RooGaussian(
"fconstext",
"fconstext", f, ROOT.RooFit.RooConst(
81 0.2), ROOT.RooFit.RooConst(0.1))
84r3 = model.fitTo(d, ROOT.RooFit.ExternalConstraints(
85 ROOT.RooArgSet(fconstext)), ROOT.RooFit.Save())
88print(
"fit result without constraint (data generated at f=0.5)")
90print(
"fit result with internal constraint (data generated at f=0.5, is f=0.8+/-0.2)")
92print(
"fit result with (another) external constraint (data generated at f=0.5, is f=0.2+/-0.1)")