1 void myText(Double_t
x,Double_t
y,Color_t
color,
const char *
text, Double_t tsize = 0.05,
double angle = -1);
6 const char *
text, Double_t tsize,
double angle) {
11 l.SetTextColor(color);
12 if (angle > 0) l.SetTextAngle(angle);
13 l.DrawLatex(x,y,text);
21 Double_t xMin = p->GetUxmin();
22 Double_t xMax = p->GetUxmax();
26 xMin = std::pow(10, xMin);
27 xMax = std::pow(10, xMax);
30 TLine *
line =
new TLine(xMin, y, xMax, y);
31 line->SetLineStyle(2);
32 line->SetLineWidth(1);
33 line->SetLineColor(1);
39 FitResolution(
const TH2F *
h2,
const bool normalize_mean =
true,
const int param = 2)
41 TProfile *p2 = h2->ProfileX();
49 for (
int i = 1;
i <= h2->GetNbinsX();
i++)
51 TH1D *
h1 = h2->ProjectionY(Form(
"htmp_%d", rand()),
i,
i);
53 if (h1->GetSum() < 10)
56 TF1 fgaus(
"fgaus",
"gaus", -p2->GetBinError(
i) * 4,
57 p2->GetBinError(
i) * 4);
59 TF1
f2(Form(
"dgaus"),
"gaus + [3]*exp(-0.5*((x-[1])/[4])**2) + [5]",
60 -p2->GetBinError(
i) * 4, p2->GetBinError(
i) * 4);
62 fgaus.SetParameter(1, p2->GetBinContent(
i));
63 fgaus.SetParameter(2, p2->GetBinError(
i));
65 h1->Fit(&fgaus,
"MQ0");
67 x[
n] = p2->GetBinCenter(
i);
68 ex[
n] = (p2->GetBinCenter(2) - p2->GetBinCenter(1)) / 2;
70 const double norm = normalize_mean ? fgaus.GetParameter(1) : 1;
72 y[
n] = fgaus.GetParameter(param) /
norm;
73 ey[
n] = fgaus.GetParError(param) /
norm;
79 TGraphErrors *ge =
new TGraphErrors(n, x, y, 0, ey);
80 ge->SetName(TString(h2->GetName()) +
"_FitResolution");
82 ge->SetLineColor(kBlue + 3);
83 ge->SetMarkerColor(kBlue + 3);
85 ge->SetMarkerStyle(kFullCircle);
94 TProfile *p2 = h2->ProfileX();
102 for (
int i = 1;
i <= h2->GetNbinsX();
i++)
104 TH1D *
h1 = h2->ProjectionY(Form(
"htmp_%d", rand()),
i,
i);
106 if (h1->GetSum() < 10)
109 TF1 fgaus(
"fgaus",
"gaus", -p2->GetBinError(
i) * 4,
110 p2->GetBinError(
i) * 4);
112 TF1
f2(Form(
"dgaus"),
"gaus + [3]*exp(-0.5*((x-[1])/[4])**2) + [5]",
113 -p2->GetBinError(
i) * 4, p2->GetBinError(
i) * 4);
115 fgaus.SetParameter(1, p2->GetBinContent(
i));
116 fgaus.SetParameter(2, p2->GetBinError(
i));
118 h1->Fit(&fgaus,
"MQ0");
131 x[
n] = p2->GetBinCenter(
i);
132 ex[
n] = p2->GetBinWidth(
i) / 2;
133 y[
n] = fgaus.GetParameter(1);
134 ey[
n] = fgaus.GetParameter(2);
143 TGraphErrors *ge =
new TGraphErrors(n, x, y, ex, ey);
144 ge->SetName(TString(h2->GetName()) +
"_FitProfile");
145 ge->SetLineColor(kBlue + 3);
146 ge->SetMarkerColor(kBlue + 3);
148 ge->SetMarkerStyle(kFullCircle);
149 ge->SetMarkerSize(1);
159 assert(h_pass->GetNbinsX() == h_n_trial->GetNbinsX());
160 assert(h_pass->GetNbinsY() == h_n_trial->GetNbinsY());
161 assert(h_pass->GetNbinsZ() == h_n_trial->GetNbinsZ());
163 TH1 *h_ratio = (TH1 *) h_pass->Clone(TString(h_pass->GetName()) +
"_Ratio");
165 h_ratio->Divide(h_n_trial);
167 for (
int x = 1; x <= h_n_trial->GetNbinsX(); ++
x)
168 for (
int y = 1; y <= h_n_trial->GetNbinsY(); ++
y)
169 for (
int z = 1;
z <= h_n_trial->GetNbinsZ(); ++
z)
171 const double n_trial = h_n_trial->GetBinContent(x, y,
z);
175 const double p = h_pass->GetBinContent(x, y,
z) / n_trial;
178 h_ratio->SetBinContent(x, y,
z,
179 (p + 1 / (2 * n_trial)) / (1 + 1 / n_trial));
180 h_ratio->SetBinError(x, y,
183 1. / n_trial * p * (1 - p) + 1. / (4 * n_trial * n_trial)) /
186 else if (process_zero_bins)
188 h_ratio->SetBinContent(x, y,
z, 0.5);
189 h_ratio->SetBinError(x, y,
z, 0.5);
202 Double_t yMin = p->GetUymin();
203 Double_t yMax = p->GetUymax();
207 yMin = std::pow(10, yMin);
208 yMax = std::pow(10, yMax);
211 TLine *
line =
new TLine(x, yMin, x, yMax);
212 line->SetLineStyle(2);
213 line->SetLineWidth(1);
214 line->SetLineColor(1);
217 double DrawReference(TH1 *hnew, TH1 *href,
bool draw_href_error =
false,
bool do_kstest =
true)
219 hnew->SetLineColor(kBlue + 3);
220 hnew->SetMarkerColor(kBlue + 3);
222 hnew->SetMarkerStyle(kFullCircle);
229 href->SetLineColor(kGreen + 1);
230 href->SetFillColor(kGreen + 1);
231 href->SetLineStyle(kSolid);
232 href->SetMarkerColor(kGreen + 1);
234 href->SetMarkerStyle(kDot);
235 href->SetMarkerSize(0);
239 href->SetLineColor(kGreen + 1);
240 href->SetFillColor(kGreen + 1);
241 href->SetLineStyle(0);
242 href->SetMarkerColor(kGreen + 1);
243 href->SetLineWidth(0);
244 href->SetMarkerStyle(kDot);
245 href->SetMarkerSize(0);
251 double ks_test = numeric_limits<double>::signaling_NaN();
257 href->DrawClone(
"E2 same");
258 href->SetFillStyle(0);
259 href->SetLineWidth(8);
260 href->DrawClone(
"HIST same ][");
263 href->Draw(
"HIST same");
267 ks_test = hnew->KolmogorovTest(href,
"");
275 gPad->SetTopMargin(.14);
276 TLegend *legend =
new TLegend(0, .93, 0, 1, hnew->GetTitle(),
"NB NDC");
278 legend =
new TLegend(0, .86, .3, .93, NULL,
"NB NDC");
279 legend->AddEntry(href, Form(
"Reference"),
"f");
281 legend =
new TLegend(0.3, .86, 1, .93, NULL,
"NB NDC");
285 TLegendEntry *le = legend->AddEntry(hnew, Form(
"New: KS-Test P=%.3f", ks_test),
"lpe");
287 le->SetTextColor(kBlue + 1);
288 else if (ks_test >= .2)
289 le->SetTextColor(kGreen + 2);
290 else if (ks_test >= .05)
291 le->SetTextColor(kYellow + 1);
293 le->SetTextColor(kRed + 1);
298 TLegendEntry *le = legend->AddEntry(hnew, Form(
"New Result"),
"lpe");
304 gPad->SetTopMargin(.07);
305 TLegend *legend =
new TLegend(0, .93, 0, 1, hnew->GetTitle(),
"NB NDC");
317 hnew->SetLineColor(kBlue + 3);
318 hnew->SetMarkerColor(kBlue + 3);
319 hnew->SetLineWidth(2);
320 hnew->SetMarkerStyle(kFullCircle);
321 hnew->SetMarkerSize(1);
327 href->SetLineColor(kGreen + 1);
328 href->SetFillColor(kGreen + 1);
329 href->SetFillStyle(0);
330 href->SetLineStyle(kSolid);
331 href->SetMarkerColor(kGreen + 1);
332 href->SetLineWidth(4);
333 href->SetMarkerStyle(kDot);
334 href->SetMarkerSize(0);
338 href->SetLineColor(kGreen + 1);
339 href->SetFillColor(kGreen + 1);
340 href->SetLineStyle(0);
341 href->SetMarkerColor(kGreen + 1);
342 href->SetLineWidth(0);
343 href->SetMarkerStyle(kDot);
344 href->SetMarkerSize(0);
352 href->DrawClone(
"E2");
355 href->Draw(
"HIST same");
364 gPad->SetTopMargin(.14);
365 TLegend *legend =
new TLegend(0, .93, 0, 1, hnew->GetTitle(),
"NB NDC");
367 legend =
new TLegend(0, .86, .3, .93, NULL,
"NB NDC");
368 legend->AddEntry(href, Form(
"Reference"),
"f");
370 legend =
new TLegend(0.3, .86, 1, .93, NULL,
"NB NDC");
371 TLegendEntry *le = legend->AddEntry(hnew, Form(
"New"),
"lpe");
376 gPad->SetTopMargin(.07);
377 TLegend *legend =
new TLegend(0, .93, 0, 1, hnew->GetTitle(),
"NB NDC");
388 const double ratio =
double(p->GetWw()) / p->GetWh();
389 Int_t columns = std::max(1,
int(std::sqrt(npads * ratio)));
390 Int_t
rows = std::max(1,
int(npads / columns));
391 while (rows * columns < npads)
394 if (rows * columns < npads) rows++;
396 p->Divide(rows, columns);