42 for (std::size_t i = 0; i < gammas.
size(); ++i) {
45 auto nomName =
"nom_" + std::string(
gamma->GetName());
46 auto tauName = std::string(
gamma->GetName()) +
"_tau";
47 auto meanName = std::string(
gamma->GetName()) +
"_mean";
48 auto poissonName = std::string(
gamma->GetName()) +
"_constraint";
52 nomVal += func->dataHist().weight(i);
59 gamma->setConstant(
true);
62 gamma->setError(1.0 / std::sqrt(nomVal));
64 auto nominal = std::make_unique<RooRealVar>(nomName.c_str(), nomName.c_str(), nomVal, 0.0,
RooNumber::infinity());
65 nominal->setConstant(
true);
66 globalObservables.
add(*nominal);
68 auto tau = std::make_unique<RooConstVar>(tauName.c_str(), tauName.c_str(), nominal->getVal());
70 auto mean = std::make_unique<RooProduct>(meanName.c_str(), meanName.c_str(), *gamma, *tau);
71 mean->addOwnedComponents(std::move(tau));
73 auto poisson = std::make_unique<RooPoisson>(poissonName.c_str(), poissonName.c_str(), *nominal, *mean);
74 poisson->addOwnedComponents(std::move(nominal));
75 poisson->addOwnedComponents(std::move(mean));
77 constraints.
addOwned(std::move(poisson));
82void rf709_BarlowBeeston()
92 RooRealVar meanG(
"meanG",
"meanG", 1, -10, 10);
98 std::unique_ptr<RooDataSet> sigData(
g.generate(
x, 50));
99 std::unique_ptr<RooDataSet> bkgData(u.generate(
x, 1000));
101 RooDataSet sumData(
"sumData",
"Gauss + Uniform",
x);
102 sumData.append(*sigData);
103 sumData.append(*bkgData);
109 std::unique_ptr<RooDataHist> dh_sig(
g.generateBinned(
x, 50));
110 std::unique_ptr<RooDataHist> dh_bkg(u.generateBinned(
x, 10000));
119 RooRealVar Asig0(
"Asig",
"Asig", 1, 0.01, 5000);
120 RooRealVar Abkg0(
"Abkg",
"Abkg", 1, 0.01, 5000);
123 RooRealSumPdf model0(
"model0",
"model0", {p_h_sig, p_h_bkg}, {Asig0, Abkg0},
true);
131 ParamHistFunc p_phf_sig1{
"p_phf_sig1",
"p_phf_sig1",
x, gammas_sig1};
132 ParamHistFunc p_phf_bkg1{
"p_phf_bkg1",
"p_phf_bkg1",
x, gammas_bkg1};
134 RooProduct p_p_sig1{
"p_p_sig1",
"p_p_sig1", p_h_sig, p_phf_sig1};
135 RooProduct p_p_bkg1{
"p_p_bkg1",
"p_p_bkg1", p_h_bkg, p_phf_bkg1};
137 RooRealVar Asig1(
"Asig",
"Asig", 1, 0.01, 5000);
138 RooRealVar Abkg1(
"Abkg",
"Abkg", 1, 0.01, 5000);
141 RooRealSumPdf model1_tmp(
"sp_ph",
"sp_ph", {p_p_sig1, p_p_bkg1}, {Asig1, Abkg1},
true);
147 RooArgSet constraints_sig1{createConstraints(gammas_sig1, p_h_sig, globs1)};
148 RooArgSet constraints_bkg1{createConstraints(gammas_bkg1, p_h_bkg, globs1)};
151 RooProdPdf model1(
"model1",
"model1", {model1_tmp, constraints_sig1, constraints_bkg1});
163 RooProduct p_p_sig2{
"p_p_sig2",
"p_p_sig2", p_h_sig, p_phf2};
164 RooProduct p_p_bkg2{
"p_p_bkg2",
"p_p_bkg2", p_h_bkg, p_phf2};
166 RooRealVar Asig2(
"Asig",
"Asig", 1, 0.01, 5000);
167 RooRealVar Abkg2(
"Abkg",
"Abkg", 1, 0.01, 5000);
170 RooRealSumPdf model2_tmp(
"sp_ph",
"sp_ph", {p_p_sig2, p_p_bkg2}, {Asig2, Abkg2},
true);
174 RooArgSet constraints2{createConstraints(gammas2, {p_h_sig, p_h_bkg}, globs2)};
177 RooProdPdf model2(
"model2",
"model2", {model2_tmp, constraints2});
193 auto frame =
x.frame(
Title(
"No template uncertainties"));
195 sumData.plotOn(frame);
198 sumData.plotOn(frame);
203 model0.paramOn(frame);
208 for (
auto text : {
"No template uncertainties",
"are taken into account.",
"This leads to low errors",
209 "for the parameters A, since",
"the only source of errors",
"are the data statistics."}) {
215 frame =
x.frame(
Title(
"Barlow Beeston for Sig & Bkg separately"));
216 sumData.plotOn(frame);
219 sumData.plotOn(frame);
223 model1.paramOn(frame,
Parameters({Asig1, Abkg1}));
229 for (
auto text : {
"With gamma parameters, the",
"signal & background templates",
"can adapt to the data.",
230 "Note how the blue signal",
"template changes its shape.",
"This leads to higher errors",
231 "of the scale parameters A."}) {
237 frame =
x.frame(
Title(
"Barlow Beeston light for (Sig+Bkg)"));
238 sumData.plotOn(frame);
241 sumData.plotOn(frame);
245 model2.paramOn(frame,
Parameters({Asig2, Abkg2}));
251 for (
auto text : {
"When signal and background",
"template share one gamma para-",
"meter per bin, they adapt less.",
252 "The errors of the A parameters",
"also shrink slightly."}) {
257 std::cout <<
"Asig [normal ] = " << Asig0.getVal() <<
" +/- " << Asig0.getError() << std::endl;
258 std::cout <<
"Asig [BB ] = " << Asig1.getVal() <<
" +/- " << Asig1.getError() << std::endl;
259 std::cout <<
"Asig [BBlight] = " << Asig2.getVal() <<
" +/- " << Asig2.getError() << std::endl;
ROOT::RRangeCast< T, false, Range_t > static_range_cast(Range_t &&coll)
Option_t Option_t TPoint TPoint const char text
A class which maps the current values of a RooRealVar (or a set of RooRealVars) to one of a number of...
static RooArgList createParamSet(RooWorkspace &w, const std::string &, const RooArgList &Vars)
Create the list of RooRealVar parameters which represent the height of the histogram bins.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Storage_t::size_type size() const
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
RooFit::OwningPtr< RooFitResult > fitTo(RooAbsData &data, CmdArgs_t const &... cmdArgs)
Fit PDF to given dataset.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Container class to hold unbinned data.
A real-valued function sampled from a multidimensional histogram.
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
static constexpr double infinity()
Return internal infinity representation.
Efficient implementation of a product of PDFs of the form.
Represents the product of a given set of RooAbsReal objects.
Implements a PDF constructed from a sum of functions:
Variable that can be changed from the outside.
virtual void SetFillStyle(Style_t fstyle)
Set the fill area style.
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1).
void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0) override
Automatic pad generation by division.
A Pave (see TPave) with text, lines or/and boxes inside.
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
void Clear(Option_t *option="") override
Clear all lines in this pavetext.
virtual void SetBorderSize(Int_t bordersize=4)
Sets the border size of the TPave box and shadow.
void Draw(Option_t *option="") override=0
Default Draw method for all objects.
RooCmdArg Parameters(const RooArgSet ¶ms)
RooCmdArg Save(bool flag=true)
RooCmdArg GlobalObservables(Args_t &&... argsOrArgSet)
RooCmdArg PrintLevel(Int_t code)
RooCmdArg Components(Args_t &&... argsOrArgSet)
RooCmdArg LineColor(TColorNumber color)
RooCmdArg VisualizeError(const RooDataSet ¶mData, double Z=1)
RooCmdArg MarkerColor(TColorNumber color)
double poisson(double x, double par)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
void removeTopic(RooFit::MsgTopic oldTopic)