19x = ROOT.RooRealVar(
"x",
"x", -10, 10)
21m = ROOT.RooRealVar(
"m",
"m", 0, -10, 10)
22s = ROOT.RooRealVar(
"s",
"s", 2, 0.1, 10)
23gauss = ROOT.RooGaussian(
"gauss",
"gauss(x,m,s)", x, m, s)
26poly = ROOT.RooPolynomial(
"poly",
"poly(x)", x)
29f = ROOT.RooRealVar(
"f",
"f", 0.5, 0.0, 1.0)
30model = ROOT.RooAddPdf(
"model",
"model", [gauss, poly], [f])
33d = model.generate({x}, 50)
40fconstraint = ROOT.RooGaussian(
"fconstraint",
"fconstraint", f, 0.8, 0.1)
49modelc = ROOT.RooProdPdf(
"modelc",
"model with constraint", [model, fconstraint])
52r1 = model.fitTo(d, Save=
True, PrintLevel=-1)
55r2 = modelc.fitTo(d, Constrain={f}, Save=
True, PrintLevel=-1)
62fconstext = ROOT.RooGaussian(
"fconstext",
"fconstext", f, 0.2, 0.1)
65r3 = model.fitTo(d, ExternalConstraints={fconstext}, Save=
True, PrintLevel=-1)
68print(
"fit result without constraint (data generated at f=0.5)")
70print(
"fit result with internal constraint (data generated at f=0.5, is f=0.8+/-0.2)")
72print(
"fit result with (another) external constraint (data generated at f=0.5, is f=0.2+/-0.1)")