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.0, 1.0)
31model = ROOT.RooAddPdf(
"model",
"model", [gauss, poly], [f])
34d = model.generate({x}, 50)
41fconstraint = ROOT.RooGaussian(
"fconstraint",
"fconstraint", f, 0.8, 0.1)
50modelc = ROOT.RooProdPdf(
"modelc",
"model with constraint", [model, fconstraint])
53r1 = model.fitTo(d, Save=
True, PrintLevel=-1)
56r2 = modelc.fitTo(d, Constrain={f}, Save=
True, PrintLevel=-1)
63fconstext = ROOT.RooGaussian(
"fconstext",
"fconstext", f, 0.2, 0.1)
66r3 = model.fitTo(d, ExternalConstraints={fconstext}, Save=
True, PrintLevel=-1)
69print(
"fit result without constraint (data generated at f=0.5)")
71print(
"fit result with internal constraint (data generated at f=0.5, is f=0.8+/-0.2)")
73print(
"fit result with (another) external constraint (data generated at f=0.5, is f=0.2+/-0.1)")