74void rf611_weightedfits(
int acceptancemodel = 2)
80 gStyle->SetPaintTextFormat(
".1f");
81 gStyle->SetEndErrorSize(6.0);
82 gStyle->SetTitleSize(0.05,
"XY");
83 gStyle->SetLabelSize(0.05,
"XY");
84 gStyle->SetTitleOffset(0.9,
"XY");
86 gStyle->SetPadLeftMargin(0.125);
87 gStyle->SetPadBottomMargin(0.125);
88 gStyle->SetPadTopMargin(0.075);
89 gStyle->SetPadRightMargin(0.075);
90 gStyle->SetMarkerStyle(20);
91 gStyle->SetMarkerSize(1.0);
92 gStyle->SetHistLineWidth(2.0);
93 gStyle->SetHistLineColor(1);
100 TH1 *haccepted =
new TH1D(
"haccepted",
"Generated events;cos(#theta);#events", 40, -1.0, 1.0);
101 TH1 *hweighted =
new TH1D(
"hweighted",
"Generated events;cos(#theta);#events", 40, -1.0, 1.0);
103 std::array<TH1 *, 3> hc0pull;
104 std::array<TH1 *, 3> hc1pull;
105 std::array<TH1 *, 3> hntotpull;
106 std::array<std::string, 3> methodLabels{
"Inverse weighted Hessian matrix [SumW2Error(false)]",
107 "Hessian matrix with squared weights [SumW2Error(true)]",
108 "Asymptotically correct approach [Asymptotic(true)]"};
109 auto makePullXLabel = [](std::string
const &pLabel) {
110 return "Pull (" + pLabel +
"^{fit}-" + pLabel +
"^{gen})/#sigma(" + pLabel +
")";
112 for (std::size_t i = 0; i < 3; ++i) {
113 std::string
const &iLabel = std::to_string(i);
115 std::string hc0XLabel = methodLabels[i] +
";" + makePullXLabel(
"c_{0}") +
";";
116 std::string hc1XLabel = methodLabels[i] +
";" + makePullXLabel(
"c_{1}") +
";";
117 std::string hntotXLabel = methodLabels[i] +
";" + makePullXLabel(
"N_{tot}") +
";";
118 hc0pull[i] =
new TH1D((
"hc0pull" + iLabel).c_str(), hc0XLabel.c_str(), 20, -5.0, 5.0);
120 hc1pull[i] =
new TH1D((
"hc1pull" + iLabel).c_str(), hc1XLabel.c_str(), 20, -5.0, 5.0);
122 hntotpull[i] =
new TH1D((
"hntotpull" + iLabel).c_str(), hntotXLabel.c_str(), 20, -5.0, 5.0);
126 constexpr std::size_t ntoys = 500;
127 constexpr std::size_t nstats = 500;
129 constexpr double c0gen = 0.0;
130 constexpr double c1gen = 0.0;
137 std::cout <<
"Running " << ntoys * 3 <<
" toy fits ..." << std::endl;
141 for (std::size_t i = 0; i < ntoys; i++) {
145 RooRealVar costheta(
"costheta",
"costheta", -1.0, 1.0);
146 RooRealVar weight(
"weight",
"weight", 0.0, 1000.0);
149 RooRealVar c0(
"c0",
"0th-order coefficient", c0gen, -1.0, 1.0);
150 RooRealVar c1(
"c1",
"1st-order coefficient", c1gen, -1.0, 1.0);
156 double ngen = nstats;
157 if (acceptancemodel == 1)
158 ngen *= 2.0 / (23.0 / 15.0);
160 ngen *= 2.0 / (16.0 / 15.0);
161 RooRealVar ntot(
"ntot",
"ntot", ngen, 0.0, 2.0 * ngen);
162 RooExtendPdf extended(
"extended",
"extended pdf", pol, ntot);
163 int npoisson = rnd->
Poisson(nstats);
169 for (std::size_t j = 0; j < npoisson; j++) {
170 bool finished =
false;
173 costheta = 2.0 * rnd->
Rndm() - 1.0;
176 if (acceptancemodel == 1)
177 eff = 1.0 - 0.7 * costheta.getVal() * costheta.getVal();
179 eff = 0.3 + 0.7 * costheta.getVal() * costheta.getVal();
183 if (10.0 * rnd->
Rndm() < eff * pol.getVal())
186 haccepted->
Fill(costheta.getVal());
187 hweighted->
Fill(costheta.getVal(), weight.getVal());
188 data.add({costheta, weight}, weight.getVal());
191 auto fillPulls = [&](std::size_t i) {
192 hc0pull[i]->Fill((c0.getVal() - c0gen) / c0.getError());
193 hc1pull[i]->Fill((
c1.getVal() - c1gen) /
c1.getError());
194 hntotpull[i]->Fill((ntot.getVal() - ngen) / ntot.getError());
213 std::cout <<
"... done." << std::endl;
225 hweighted->
Draw(
"hist");
226 haccepted->
Draw(
"same hist");
228 leg->AddEntry(haccepted,
"Accepted");
229 leg->AddEntry(hweighted,
"Weighted");
237 std::vector<TH1 *> pullHistos{hc0pull[0], hc0pull[1], hc0pull[2], hc1pull[0], hc1pull[1],
238 hc1pull[2], hntotpull[0], hntotpull[1], hntotpull[2]};
243 for (std::size_t i = 0; i < pullHistos.size(); ++i) {
245 pullHistos[i]->Fit(
"gaus");
246 pullHistos[i]->Draw(
"ep");
Container class to hold unbinned data.
RooExtendPdf is a wrapper around an existing PDF that adds a parameteric extended likelihood term to ...
static RooMsgService & instance()
Return reference to singleton instance.
RooPolynomial implements a polynomial p.d.f of the form.
Variable that can be changed from the outside.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
void Update() override
Update canvas pad buffers.
1-D histogram with a double per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
void Draw(Option_t *option="") override
Draw this histogram with options.
virtual void SetMinimum(Double_t minimum=-1111)
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.
Random number generator class based on M.
Double_t Rndm() override
Machine independent random number generator.
void SetSeed(ULong_t seed=0) override
Set the random generator sequence.
virtual ULong64_t Poisson(Double_t mean)
Generates a random integer N according to a Poisson law.
RooCmdArg WeightVar(const char *name="weight", bool reinterpretAsWeight=false)
RooCmdArg AsymptoticError(bool flag)
RooCmdArg SumW2Error(bool flag)
RooCmdArg PrintLevel(Int_t code)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...