22 using namespace RooFit;
25 int rf611_weightedfits(
int acceptancemodel=2) {
67 gStyle->SetPaintTextFormat(
".1f");
68 gStyle->SetEndErrorSize(6.0);
69 gStyle->SetTitleSize(0.05,
"XY");
70 gStyle->SetLabelSize(0.05,
"XY");
71 gStyle->SetTitleOffset(0.9,
"XY");
72 gStyle->SetTextSize(0.05);
73 gStyle->SetPadLeftMargin(0.125);
74 gStyle->SetPadBottomMargin(0.125);
75 gStyle->SetPadTopMargin(0.075);
76 gStyle->SetPadRightMargin(0.075);
77 gStyle->SetMarkerStyle(20);
78 gStyle->SetMarkerSize(1.0);
79 gStyle->SetHistLineWidth(2.0);
80 gStyle->SetHistLineColor(1);
83 TRandom3* rnd =
new TRandom3();
84 rnd->SetSeed(191101303);
87 TH1D* haccepted =
new TH1D(
"haccepted",
"Generated events;cos(#theta);#events", 40, -1.0, 1.0);
88 TH1D* hweighted =
new TH1D(
"hweighted",
"Generated events;cos(#theta);#events", 40, -1.0, 1.0);
91 TH1D* hc0pull1 =
new TH1D(
"hc0pull1",
"Inverse weighted Hessian matrix [SumW2Error(false)];Pull (c_{0}^{fit}-c_{0}^{gen})/#sigma(c_{0});", 20, -5.0, 5.0);
92 TH1D* hc1pull1 =
new TH1D(
"hc1pull1",
"Inverse weighted Hessian matrix [SumW2Error(false)];Pull (c_{1}^{fit}-c_{1}^{gen})/#sigma(c_{1});", 20, -5.0, 5.0);
94 TH1D* hc0pull2 =
new TH1D(
"hc0pull2",
"Hessian matrix with squared weights [SumW2Error(true)];Pull (c_{0}^{fit}-c_{0}^{gen})/#sigma(c_{0});", 20, -5.0, 5.0);
95 TH1D* hc1pull2 =
new TH1D(
"hc1pull2",
"Hessian matrix with squared weights [SumW2Error(true)];Pull (c_{1}^{fit}-c_{1}^{gen})/#sigma(c_{1});", 20, -5.0, 5.0);
97 TH1D* hc0pull3 =
new TH1D(
"hc0pull3",
"Asymptotically correct approach [Asymptotic(true)];Pull (c_{0}^{fit}-c_{0}^{gen})/#sigma(c_{0});", 20, -5.0, 5.0);
98 TH1D* hc1pull3 =
new TH1D(
"hc1pull3",
"Asymptotically correct approach [Asymptotic(true)];Pull (c_{1}^{fit}-c_{1}^{gen})/#sigma(c_{1});", 20, -5.0, 5.0);
101 unsigned int ntoys = 500;
102 unsigned int nstats = 5000;
109 for (
unsigned int i=0; i<ntoys; i++)
114 RooRealVar costheta(
"costheta",
"costheta", -1.0, 1.0);
115 RooRealVar weight(
"weight",
"weight", 0.0, 1000.0);
118 RooRealVar c0(
"c0",
"c0", c0gen, -1.0, 1.0);
119 RooRealVar c1(
"c1",
"c1", c1gen, -1.0, 1.0);
123 RooPolynomial pol(
"pol",
"pol", costheta, RooArgList(c0, c1), 1);
127 RooDataSet data(
"data",
"data",RooArgSet(costheta, weight), WeightVar(
"weight"));
129 for (
unsigned int j=0; j<nstats; j++)
131 bool finished =
false;
135 costheta = 2.0*rnd->Rndm()-1.0;
138 if (acceptancemodel == 1)
139 eff = 1.0 - 0.7 * costheta.getValV()*costheta.getValV();
141 eff = 0.3 + 0.7 * costheta.getValV()*costheta.getValV();
145 if (10.0*rnd->Rndm() < eff*pol.getValV())
148 haccepted->Fill(costheta.getValV());
149 hweighted->Fill(costheta.getValV(), weight.getValV());
150 data.add(RooArgSet(costheta, weight), weight.getValV());
155 RooFitResult* result = pol.fitTo(data, Save(
true), SumW2Error(
false));
156 hc0pull1->Fill((c0.getValV()-c0gen)/c0.getError());
157 hc1pull1->Fill((c1.getValV()-c1gen)/c1.getError());
159 result = pol.fitTo(data, Save(
true), SumW2Error(
true));
160 hc0pull2->Fill((c0.getValV()-c0gen)/c0.getError());
161 hc1pull2->Fill((c1.getValV()-c1gen)/c1.getError());
163 result = pol.fitTo(data, Save(
true), AsymptoticError(
true));
164 hc0pull3->Fill((c0.getValV()-c0gen)/c0.getError());
165 hc1pull3->Fill((c1.getValV()-c1gen)/c1.getError());
172 gStyle->SetOptStat(0);
173 gStyle->SetOptFit(0);
174 TCanvas* cevents =
new TCanvas(
"cevents",
"cevents", 800, 600);
176 hweighted->SetMinimum(0.0);
177 hweighted->SetLineColor(2);
178 hweighted->Draw(
"hist");
179 haccepted->Draw(
"same hist");
180 TLegend* leg =
new TLegend(0.6, 0.8, 0.9, 0.9);
181 leg->AddEntry(haccepted,
"Accepted");
182 leg->AddEntry(hweighted,
"Weighted");
187 TCanvas* cpull =
new TCanvas(
"cpull",
"cpull", 1200, 800);
190 gStyle->SetOptStat(1100);
191 gStyle->SetOptFit(11);
192 hc0pull1->Fit(
"gaus");
193 hc0pull1->Draw(
"ep");
195 hc0pull2->Fit(
"gaus");
196 hc0pull2->Draw(
"ep");
198 hc0pull3->Fit(
"gaus");
199 hc0pull3->Draw(
"ep");
201 hc1pull1->Fit(
"gaus");
202 hc1pull1->Draw(
"ep");
204 hc1pull2->Fit(
"gaus");
205 hc1pull2->Draw(
"ep");
207 hc1pull3->Fit(
"gaus");
208 hc1pull3->Draw(
"ep");