19x = ROOT.RooRealVar(
"x",
"x", -20, 20)
22meanG = ROOT.RooRealVar(
"meanG",
"meanG", 1, -10, 10)
23sigG = ROOT.RooRealVar(
"sigG",
"sigG", 1.5, -10, 10)
24g = ROOT.RooGaussian(
"g",
"Gauss", x, meanG, sigG)
25u = ROOT.RooUniform(
"u",
"Uniform", x)
29sigData = g.generate(x, 50)
30bkgData = u.generate(x, 1000)
32sumData = ROOT.RooDataSet(
"sumData",
"Gauss + Uniform", x)
33sumData.append(sigData)
34sumData.append(bkgData)
41dh_sig = g.generateBinned(x, 50)
42dh_bkg = u.generateBinned(x, 10000)
48p_h_sig = ROOT.RooHistFunc(
"p_h_sig",
"p_h_sig", x, dh_sig)
49p_h_bkg = ROOT.RooHistFunc(
"p_h_bkg",
"p_h_bkg", x, dh_bkg)
52Asig0 = ROOT.RooRealVar(
"Asig",
"Asig", 1, 0.01, 5000)
53Abkg0 = ROOT.RooRealVar(
"Abkg",
"Abkg", 1, 0.01, 5000)
56model0 = ROOT.RooRealSumPdf(
"model0",
"model0", [p_h_sig, p_h_bkg], [Asig0, Abkg0],
True)
62p_ph_sig1 = ROOT.RooParamHistFunc(
"p_ph_sig",
"p_ph_sig", dh_sig)
63p_ph_bkg1 = ROOT.RooParamHistFunc(
"p_ph_bkg",
"p_ph_bkg", dh_bkg)
65Asig1 = ROOT.RooRealVar(
"Asig",
"Asig", 1, 0.01, 5000)
66Abkg1 = ROOT.RooRealVar(
"Abkg",
"Abkg", 1, 0.01, 5000)
69model_tmp = ROOT.RooRealSumPdf(
"sp_ph",
"sp_ph", [p_ph_sig1, p_ph_bkg1], [Asig1, Abkg1],
True)
74hc_sig = ROOT.RooHistConstraint(
"hc_sig",
"hc_sig", p_ph_sig1)
75hc_bkg = ROOT.RooHistConstraint(
"hc_bkg",
"hc_bkg", p_ph_bkg1)
78model1 = ROOT.RooProdPdf(
"model1",
"model1", {hc_sig, hc_bkg}, Conditional=(model_tmp, x))
90p_ph_sig2 = ROOT.RooParamHistFunc(
"p_ph_sig2",
"p_ph_sig2", dh_sig)
91p_ph_bkg2 = ROOT.RooParamHistFunc(
"p_ph_bkg2",
"p_ph_bkg2", dh_bkg, p_ph_sig2,
True)
93Asig2 = ROOT.RooRealVar(
"Asig",
"Asig", 1, 0.01, 5000)
94Abkg2 = ROOT.RooRealVar(
"Abkg",
"Abkg", 1, 0.01, 5000)
97model2_tmp = ROOT.RooRealSumPdf(
"sp_ph",
"sp_ph", [p_ph_sig2, p_ph_bkg2], [Asig2, Abkg2],
True)
100hc_sigbkg = ROOT.RooHistConstraint(
"hc_sigbkg",
"hc_sigbkg", {p_ph_sig2, p_ph_bkg2})
103model2 = ROOT.RooProdPdf(
"model2",
"model2", hc_sigbkg, Conditional=(model2_tmp, x))
108result0 = model0.fitTo(sumData, PrintLevel=0, Save=
True)
109result1 = model1.fitTo(sumData, PrintLevel=0, Save=
True)
110result2 = model2.fitTo(sumData, PrintLevel=0, Save=
True)
113can = ROOT.TCanvas(
"can",
"", 1500, 600)
116pt = ROOT.TPaveText(-19.5, 1, -2, 25)
122frame = x.frame(Title=
"No template uncertainties")
125model0.plotOn(frame, LineColor=
"b", VisualizeError=result0)
129model0.plotOn(frame, LineColor=
"b")
130p_ph_sig_set = {p_h_sig}
131p_ph_bkg_set = {p_h_bkg}
132model0.plotOn(frame, Components=p_ph_sig_set, LineColor=
"kAzure")
133model0.plotOn(frame, Components=p_ph_bkg_set, LineColor=
"r")
136sigData.plotOn(frame, MarkerColor=
"b")
140 "No template uncertainties",
141 "are taken into account.",
142 "This leads to low errors",
143 "for the parameters A, since",
144 "the only source of errors",
145 "are the data statistics.",
154frame = x.frame(Title=
"Barlow Beeston for Sig & Bkg separately")
156model1.plotOn(frame, LineColor=
"b", VisualizeError=result1)
159model1.plotOn(frame, LineColor=
"b")
160p_ph_sig1_set = {p_ph_sig1}
161p_ph_bkg1_set = {p_ph_bkg1}
162model1.plotOn(frame, Components=p_ph_sig1_set, LineColor=
"kAzure")
163model1.plotOn(frame, Components=p_ph_bkg1_set, LineColor=
"r")
164model1.paramOn(frame, Parameters={Asig1, Abkg1})
166sigData.plotOn(frame, MarkerColor=
"b")
171 "With gamma parameters, the",
172 "signal & background templates",
173 "can adapt to the data.",
174 "Note how the blue signal",
175 "template changes its shape.",
176 "This leads to higher errors",
177 "of the scale parameters A.",
186frame = x.frame(Title=
"Barlow Beeston light for (Sig+Bkg)")
188model2.plotOn(frame, LineColor=
"b", VisualizeError=result2)
191model2.plotOn(frame, LineColor=
"b")
192p_ph_sig2_set = {p_ph_sig2}
193p_ph_bkg2_set = {p_ph_bkg2}
194model2.plotOn(frame, Components=p_ph_sig2_set, LineColor=
"kAzure")
195model2.plotOn(frame, Components=p_ph_bkg2_set, LineColor=
"r")
196model2.paramOn(frame, Parameters={Asig2, Abkg2})
198sigData.plotOn(frame, MarkerColor=
"b")
203 "When signal and background",
204 "template share one gamma para-",
205 "meter per bin, they adapt less.",
206 "The errors of the A parameters",
207 "also shrink slightly.",
214print(
"Asig [normal ] = {} +/- {}".format(Asig0.getVal(), Asig0.getError()))
215print(
"Asig [BB ] = {} +/- {}".format(Asig1.getVal(), Asig1.getError()))
216print(
"Asig [BBlight] = {} +/- {}".format(Asig2.getVal(), Asig2.getError()))
218can.SaveAs(
"rf709_BarlowBeeston.png")