29 using namespace RooFit;
31 void rf709_BarlowBeeston()
34 RooRealVar x(
"x",
"x", -20, 20);
37 RooRealVar meanG(
"meanG",
"meanG", 1, -10, 10);
38 RooRealVar sigG(
"sigG",
"sigG", 1.5, -10, 10);
39 RooGaussian g(
"g",
"Gauss", x, meanG, sigG);
40 RooUniform u(
"u",
"Uniform", x);
44 std::unique_ptr<RooDataSet> sigData(g.generate(x, 50));
45 std::unique_ptr<RooDataSet> bkgData(u.generate(x, 1000));
47 RooDataSet sumData(
"sumData",
"Gauss + Uniform", x);
48 sumData.append(*sigData);
49 sumData.append(*bkgData);
56 std::unique_ptr<RooDataHist> dh_sig( g.generateBinned(x, 50) );
57 std::unique_ptr<RooDataHist> dh_bkg( u.generateBinned(x, 10000) );
63 RooHistFunc p_h_sig(
"p_h_sig",
"p_h_sig",x,*dh_sig);
64 RooHistFunc p_h_bkg(
"p_h_bkg",
"p_h_bkg",x,*dh_bkg);
67 RooRealVar Asig0(
"Asig",
"Asig",1,0.01,5000);
68 RooRealVar Abkg0(
"Abkg",
"Abkg",1,0.01,5000);
71 RooRealSumPdf model0(
"model0",
"model0",
72 RooArgList(p_h_sig,p_h_bkg),
73 RooArgList(Asig0,Abkg0),
81 RooParamHistFunc p_ph_sig1(
"p_ph_sig",
"p_ph_sig",*dh_sig);
82 RooParamHistFunc p_ph_bkg1(
"p_ph_bkg",
"p_ph_bkg",*dh_bkg);
84 RooRealVar Asig1(
"Asig",
"Asig",1,0.01,5000);
85 RooRealVar Abkg1(
"Abkg",
"Abkg",1,0.01,5000);
88 RooRealSumPdf model_tmp(
"sp_ph",
"sp_ph",
89 RooArgList(p_ph_sig1,p_ph_bkg1),
90 RooArgList(Asig1,Abkg1),
96 RooHistConstraint hc_sig(
"hc_sig",
"hc_sig",p_ph_sig1);
97 RooHistConstraint hc_bkg(
"hc_bkg",
"hc_bkg",p_ph_bkg1);
100 RooProdPdf model1(
"model1",
"model1",RooArgSet(hc_sig,hc_bkg),Conditional(model_tmp,x));
113 RooParamHistFunc p_ph_sig2(
"p_ph_sig2",
"p_ph_sig2", *dh_sig);
114 RooParamHistFunc p_ph_bkg2(
"p_ph_bkg2",
"p_ph_bkg2", *dh_bkg, p_ph_sig2,
true);
116 RooRealVar Asig2(
"Asig",
"Asig",1,0.01,5000);
117 RooRealVar Abkg2(
"Abkg",
"Abkg",1,0.01,5000);
120 RooRealSumPdf model2_tmp(
"sp_ph",
"sp_ph",
121 RooArgList(p_ph_sig2,p_ph_bkg2),
122 RooArgList(Asig2,Abkg2),
126 RooHistConstraint hc_sigbkg(
"hc_sigbkg",
"hc_sigbkg",RooArgSet(p_ph_sig2,p_ph_bkg2));
129 RooProdPdf model2(
"model2",
"model2",hc_sigbkg, RooFit::Conditional(model2_tmp,x));
135 auto result0 = model0.fitTo(sumData, PrintLevel(0), Save());
136 auto result1 = model1.fitTo(sumData, PrintLevel(0), Save());
137 auto result2 = model2.fitTo(sumData, PrintLevel(0), Save());
140 TCanvas* can =
new TCanvas(
"can",
"", 1500, 600);
143 TPaveText pt(-19.5, 1, -2, 25);
149 auto frame = x.frame(Title(
"No template uncertainties"));
151 sumData.plotOn(frame);
152 model0.plotOn(frame, LineColor(kBlue), VisualizeError(*result0));
154 sumData.plotOn(frame);
156 model0.plotOn(frame, LineColor(kBlue));
157 model0.plotOn(frame, Components(p_h_sig), LineColor(kAzure));
158 model0.plotOn(frame, Components(p_h_bkg), LineColor(kRed));
159 model0.paramOn(frame);
161 sigData->plotOn(frame, MarkerColor(kBlue));
165 "No template uncertainties",
166 "are taken into account.",
167 "This leads to low errors",
168 "for the parameters A, since",
169 "the only source of errors",
170 "are the data statistics."}) {
177 frame = x.frame(Title(
"Barlow Beeston for Sig & Bkg separately"));
178 sumData.plotOn(frame);
179 model1.plotOn(frame, LineColor(kBlue), VisualizeError(*result1));
181 sumData.plotOn(frame);
182 model1.plotOn(frame, LineColor(kBlue));
183 model1.plotOn(frame, Components(p_ph_sig1), LineColor(kAzure));
184 model1.plotOn(frame, Components(p_ph_bkg1), LineColor(kRed));
185 model1.paramOn(frame, Parameters(RooArgSet(Asig1, Abkg1)));
187 sigData->plotOn(frame, MarkerColor(kBlue));
192 "With gamma parameters, the",
193 "signal & background templates",
194 "can adapt to the data.",
195 "Note how the blue signal",
196 "template changes its shape.",
197 "This leads to higher errors",
198 "of the scale parameters A."}) {
204 frame = x.frame(Title(
"Barlow Beeston light for (Sig+Bkg)"));
205 sumData.plotOn(frame);
206 model2.plotOn(frame, LineColor(kBlue), VisualizeError(*result2));
208 sumData.plotOn(frame);
209 model2.plotOn(frame, LineColor(kBlue));
210 model2.plotOn(frame, Components(p_ph_sig2), LineColor(kAzure));
211 model2.plotOn(frame, Components(p_ph_bkg2), LineColor(kRed));
212 model2.paramOn(frame, Parameters(RooArgSet(Asig2, Abkg2)));
214 sigData->plotOn(frame, MarkerColor(kBlue));
219 "When signal and background",
220 "template share one gamma para-",
221 "meter per bin, they adapt less.",
222 "The errors of the A parameters",
223 "also shrink slightly."}) {
229 std::cout <<
"Asig [normal ] = " << Asig0.getVal() <<
" +/- " << Asig0.getError() << std::endl;
230 std::cout <<
"Asig [BB ] = " << Asig1.getVal() <<
" +/- " << Asig1.getError() << std::endl;
231 std::cout <<
"Asig [BBlight] = " << Asig2.getVal() <<
" +/- " << Asig2.getError() << std::endl;