11 #ifndef QA_Draw_Utility_C
12 #define QA_Draw_Utility_C
16 #include <TDirectory.h>
20 #include <TGraphErrors.h>
29 #include <TLegendEntry.h>
46 TList *l = p->GetListOfPrimitives();
51 while ((obj = next()))
53 if (obj->IsA()->GetBaseClassOffset(TClass::GetClass(
"TPad")) >= 0)
55 if ((TPad *) obj !=
p)
58 else if (obj->IsA()->GetBaseClassOffset(TClass::GetClass(
"TH1")) >= 0)
60 cout <<
"Save TH1 " << obj->GetName() << endl;
61 obj->Clone()->Write(obj->GetName(), TObject::kOverwrite);
63 else if (obj->IsA()->GetBaseClassOffset(TClass::GetClass(
"TF1")) >= 0)
65 cout <<
"Save TF1 " << obj->GetName() << endl;
66 obj->Clone()->Write(obj->GetName(), TObject::kOverwrite);
68 else if (obj->IsA()->GetBaseClassOffset(TClass::GetClass(
"TGraph")) >= 0)
70 cout <<
"Save TGraph " << obj->GetName() << endl;
71 obj->Clone()->Write(obj->GetName(), TObject::kOverwrite);
84 if (
name.Length() == 0)
87 c->Print(
name +
".png");
89 TDirectory *oldd = gDirectory;
93 c->Print(rootfilename =
name +
".root");
95 TFile f(rootfilename,
"update");
109 gStyle->GetPaperSize(x, y);
111 gStyle->SetPaperSize(c->GetWindowWidth() / 72 * 2.54,
112 c->GetWindowHeight() / 72 * 2.54);
114 c->Print(
name +
".svg");
115 gSystem->Exec(
"rsvg-convert -f pdf -o " +
name +
".pdf " +
name +
".svg");
116 gSystem->Exec(
"rm -fv " +
name +
".svg");
118 gStyle->SetPaperSize(x, y);
127 hnew->SetLineColor(kBlue + 3);
128 hnew->SetMarkerColor(kBlue + 3);
130 hnew->SetMarkerStyle(kFullCircle);
137 href->SetLineColor(kGreen + 1);
138 href->SetFillColor(kGreen + 1);
139 href->SetLineStyle(kSolid);
140 href->SetMarkerColor(kGreen + 1);
142 href->SetMarkerStyle(kDot);
143 href->SetMarkerSize(0);
147 href->SetLineColor(kGreen + 1);
148 href->SetFillColor(kGreen + 1);
149 href->SetLineStyle(0);
150 href->SetMarkerColor(kGreen + 1);
151 href->SetLineWidth(0);
152 href->SetMarkerStyle(kDot);
153 href->SetMarkerSize(0);
159 double ks_test = numeric_limits<double>::signaling_NaN();
165 href->DrawClone(
"E2 same");
166 href->SetFillStyle(0);
167 href->SetLineWidth(8);
168 href->DrawClone(
"HIST same ][");
171 href->Draw(
"HIST same");
174 ks_test = hnew->KolmogorovTest(href,
"D");
182 gPad->SetTopMargin(.14);
183 TLegend *legend =
new TLegend(0, .93, 0, 1, hnew->GetTitle(),
"NB NDC");
185 legend =
new TLegend(0, .86, .3, .93, NULL,
"NB NDC");
186 legend->AddEntry(href, Form(
"Reference"),
"f");
188 legend =
new TLegend(0.3, .86, 1, .93, NULL,
"NB NDC");
189 TLegendEntry *le = legend->AddEntry(hnew, Form(
"New: KS-Test P=%.3f", ks_test),
"lpe");
191 le->SetTextColor(kBlue+1);
192 else if (ks_test>=.2)
193 le->SetTextColor(kGreen+2);
194 else if (ks_test>=.05)
195 le->SetTextColor(kYellow+1);
197 le->SetTextColor(kRed+1);
202 gPad->SetTopMargin(.07);
203 TLegend *legend =
new TLegend(0, .93, 0, 1, hnew->GetTitle(),
"NB NDC");
214 hnew->SetLineColor(kBlue + 3);
215 hnew->SetMarkerColor(kBlue + 3);
216 hnew->SetLineWidth(2);
217 hnew->SetMarkerStyle(kFullCircle);
218 hnew->SetMarkerSize(1);
224 href->SetLineColor(kGreen + 1);
225 href->SetFillColor(kGreen + 1);
226 href->SetFillStyle(0);
227 href->SetLineStyle(kSolid);
228 href->SetMarkerColor(kGreen + 1);
229 href->SetLineWidth(4);
230 href->SetMarkerStyle(kDot);
231 href->SetMarkerSize(0);
235 href->SetLineColor(kGreen + 1);
236 href->SetFillColor(kGreen + 1);
237 href->SetLineStyle(0);
238 href->SetMarkerColor(kGreen + 1);
239 href->SetLineWidth(0);
240 href->SetMarkerStyle(kDot);
241 href->SetMarkerSize(0);
249 href->DrawClone(
"E2");
252 href->Draw(
"HIST same");
261 TProfile *p2 = h2->ProfileX();
269 for (
int i = 1; i <= h2->GetNbinsX(); i++)
271 TH1D *
h1 = h2->ProjectionY(Form(
"htmp_%d",
rand()), i, i);
273 if (h1->GetSum() < 10)
276 TF1 fgaus(
"fgaus",
"gaus", -p2->GetBinError(i) * 4,
277 p2->GetBinError(i) * 4);
279 TF1
f2(Form(
"dgaus"),
"gaus + [3]*exp(-0.5*((x-[1])/[4])**2) + [5]",
280 -p2->GetBinError(i) * 4, p2->GetBinError(i) * 4);
282 fgaus.SetParameter(1, p2->GetBinContent(i));
283 fgaus.SetParameter(2, p2->GetBinError(i));
285 h1->Fit(&fgaus,
"MQ0");
287 x[
n] = p2->GetBinCenter(i);
288 ex[
n] = (p2->GetBinCenter(2) - p2->GetBinCenter(1)) / 2;
290 const double norm = normalize_mean ? fgaus.GetParameter(1) : 1;
292 y[
n] = fgaus.GetParameter(2) / norm;
293 ey[
n] = fgaus.GetParError(2) / norm;
299 TGraphErrors *ge =
new TGraphErrors(n, x, y, 0, ey);
300 ge->SetName(TString(h2->GetName()) +
"_FitResolution");
302 ge->SetLineColor(kBlue + 3);
303 ge->SetMarkerColor(kBlue + 3);
305 ge->SetMarkerStyle(kFullCircle);
306 ge->SetMarkerSize(1);
314 TProfile *p2 = h2->ProfileX();
322 for (
int i = 1; i <= h2->GetNbinsX(); i++)
324 TH1D *
h1 = h2->ProjectionY(Form(
"htmp_%d",
rand()), i, i);
326 if (h1->GetSum() < 10)
329 TF1 fgaus(
"fgaus",
"gaus", -p2->GetBinError(i) * 4,
330 p2->GetBinError(i) * 4);
332 TF1
f2(Form(
"dgaus"),
"gaus + [3]*exp(-0.5*((x-[1])/[4])**2) + [5]",
333 -p2->GetBinError(i) * 4, p2->GetBinError(i) * 4);
335 fgaus.SetParameter(1, p2->GetBinContent(i));
336 fgaus.SetParameter(2, p2->GetBinError(i));
338 h1->Fit(&fgaus,
"MQ0");
351 x[
n] = p2->GetBinCenter(i);
352 ex[
n] = (p2->GetBinCenter(2) - p2->GetBinCenter(1)) / 2;
353 y[
n] = fgaus.GetParameter(1);
354 ey[
n] = fgaus.GetParameter(2);
363 TGraphErrors *ge =
new TGraphErrors(n, x, y, ex, ey);
364 ge->SetName(TString(h2->GetName()) +
"_FitProfile");
365 ge->SetLineColor(kBlue + 3);
366 ge->SetMarkerColor(kBlue + 3);
368 ge->SetMarkerStyle(kFullCircle);
369 ge->SetMarkerSize(1);
379 assert(h_pass->GetNbinsX() == h_n_trial->GetNbinsX());
380 assert(h_pass->GetNbinsY() == h_n_trial->GetNbinsY());
381 assert(h_pass->GetNbinsZ() == h_n_trial->GetNbinsZ());
383 TH1 *h_ratio = (TH1 *) h_pass->Clone(TString(h_pass->GetName()) +
"_Ratio");
385 h_ratio->Divide(h_n_trial);
387 for (
int x = 1;
x <= h_n_trial->GetNbinsX(); ++
x)
388 for (
int y = 1;
y <= h_n_trial->GetNbinsY(); ++
y)
389 for (
int z = 1;
z <= h_n_trial->GetNbinsZ(); ++
z)
391 const double n_trial = h_n_trial->GetBinContent(
x,
y,
z);
395 const double p = h_pass->GetBinContent(
x,
y,
z) / n_trial;
398 h_ratio->SetBinContent(
x,
y,
z,
399 (p + 1 / (2 * n_trial)) / (1 + 1 / n_trial));
400 h_ratio->SetBinError(
x,
y,
403 1. / n_trial * p * (1 - p) + 1. / (4 * n_trial * n_trial)) /
406 else if (process_zero_bins)
408 h_ratio->SetBinContent(
x,
y,
z, 0.5);
409 h_ratio->SetBinError(
x,
y,
z, 0.5);
421 void PutInputFileName(TCanvas *
c1,
const double height,
const char *new_file_name,
const char *ref_file_name)
424 TPad *pad =
new TPad(
"PutInputFileName",
"PutInputFileName", 0, 0, 1, height, 18);
430 TText *
t =
new TText(0.05, 0.75, TString(
"New QA File: ") + TString(new_file_name));
432 t->SetTextColor(kBlue + 3);
438 TText *
t =
new TText(0.05, 0.25, TString(
"Reference QA File: ") + TString(ref_file_name));
440 t->SetTextColor(kGreen + 1);