11 m_datapaths(datapaths), m_labels(
labels), m_makeRatioPlots(m_datapaths.
size()==2),
13 m_plotdir_truthVtx(m_plotdir+
"truthVtx/"),
14 m_plotdir_recoVtx(m_plotdir+
"recoVtx/"),
15 m_plotdir_recoVtxHits(m_plotdir_recoVtx+
"hits/"),
16 m_plotdir_vtxResiduals(m_plotdir+
"vtxResiduals/"),
17 m_plotdir_inputObjects(m_plotdir+
"inputObjects/"),
18 m_plotdir_vtxEfficiency(m_plotdir+
"vtxEfficiency/"),
19 m_plotdir_vtxFakeRate(m_plotdir+
"vtxFakeRate/")
34 std::unique_ptr<TFile> file_0(TFile::Open(TString(
m_datapaths[0]+
"Histograms.root"),
"read"));
35 TIter keyIter(file_0->GetListOfKeys());
39 while ((
key = (TKey*)keyIter())) {
40 TClass *objectClass = gROOT->GetClass(
key->GetClassName());
63 m_c = std::make_unique<TCanvas>();
71 gROOT->SetStyle(
"ATLAS");
72 TStyle* plotStyle = gROOT->GetStyle(
"ATLAS");
73 plotStyle->SetOptTitle(0);
74 plotStyle->SetHistLineWidth(1.);
88 TH1 *
h =
static_cast<TH1*
>(
key->ReadObj());
100 const TString
name(
h->GetName());
101 TString xlabel(
h->GetXaxis()->GetTitle());
102 TString ylabel(
h->GetYaxis()->GetTitle());
105 auto hstack = std::make_unique<THStack>(
name,
name);
113 std::unique_ptr<TFile>
file(TFile::Open(TString(
m_datapaths[
i]+
"Histograms.root"),
"read"));
114 TH1*
h =
static_cast<TH1*
>(
file->Get(
name));
122 maxy =
h->GetMaximum() > maxy ?
h->GetMaximum() : maxy;
125 return std::make_unique<PlotInfo<THStack>>(std::move(hstack),
legend, maxy, xlabel, ylabel);
149 hstackInfo->plot->Draw(
"nostack");
151 const TString
name(hstackInfo->plot->GetName());
152 double maxy_factor{1.4};
158 hstackInfo->plot->SetMaximum(maxy_factor*hstackInfo->maxy);
160 hstackInfo->plot->GetXaxis()->SetTitle(hstackInfo->xlabel);
161 hstackInfo->plot->GetYaxis()->SetTitle(hstackInfo->ylabel);
163 hstackInfo->legend->Draw();
167 hstackInfo->plot->Write();
180 double x1{0.},
x2{1.};
181 double y1{0.3},
y2{1.};
183 TPad* padPlot =
new TPad(
"padPlot",
"padPlot",
x1,
y1,
x2,
y2);
184 TPad* padRatio =
new TPad(
"padRatio",
"padRatio",
x1, 0.,
x2,
y1-
gap);
188 padPlot->SetBottomMargin(0);
191 TString xlabel_original = hstackInfo->xlabel;
192 hstackInfo->xlabel = TString(
"");
195 hstackInfo->plot->GetYaxis()->ChangeLabel(1, -1, -1, -1, -1, -1,
" ");
198 padRatio->SetTopMargin(0);
199 padRatio->SetBottomMargin(0.45);
203 std::vector<TH1*>
hists{};
204 for(TObject *
obj : *(hstackInfo->plot->GetHists()))
hists.push_back((TH1*)
obj);
207 drawRatio(
ratio, denomErrNorm, xlabel_original, hstackInfo->plot->GetXaxis(), hstackInfo->plot->GetYaxis(), axisRescaling);
233 TEfficiency *
h =
static_cast<TEfficiency*
>(
key->ReadObj());
245 const TString
name(
h->GetName());
248 const TString xlabel(
h->GetPaintedGraph()->GetXaxis()->GetTitle());
249 const TString ylabel(
h->GetPaintedGraph()->GetYaxis()->GetTitle());
253 auto mg = std::make_unique<TMultiGraph>(
name,
name);
261 std::unique_ptr<TFile>
file(TFile::Open(TString(
m_datapaths[
i]+
"Histograms.root"),
"read"));
262 TEfficiency*
h =
static_cast<TEfficiency*
>(
file->Get(
name));
267 h->SetMarkerSize(0.5);
271 TGraphAsymmErrors*
g =
h->GetPaintedGraph();
278 return std::make_unique<PlotInfo<TMultiGraph>>(std::move(
mg),
legend, maxy, xlabel, ylabel);
300 mgInfo->plot->Draw(
"AP");
302 mgInfo->plot->GetYaxis()->SetRangeUser(0, 1.4*mgInfo->maxy);
304 mgInfo->plot->GetXaxis()->SetTitle(mgInfo->xlabel);
305 mgInfo->plot->GetYaxis()->SetTitle(mgInfo->ylabel);
307 mgInfo->legend->Draw();
308 const TString
name(mgInfo->plot->GetName());
314 mgInfo->plot->Write();
325 double x1{0.},
x2{1.};
326 double y1{0.3},
y2{1.};
328 TPad* padPlot =
new TPad(
"padPlot",
"padPlot",
x1,
y1,
x2,
y2);
329 TPad* padRatio =
new TPad(
"padRatio",
"padRatio",
x1, 0.,
x2,
y1-
gap);
333 padPlot->SetBottomMargin(0);
336 TString xlabel_original = mgInfo->xlabel;
337 mgInfo->xlabel = TString(
"");
340 mgInfo->plot->GetYaxis()->ChangeLabel(1, -1, -1, -1, -1, -1,
" ");
344 padRatio->SetTopMargin(0);
345 padRatio->SetBottomMargin(0.45);
350 for(TObject *
obj : *(mgInfo->plot->GetListOfGraphs()))
efficiencies.push_back((TGraphAsymmErrors*)
obj);
353 drawRatio(
ratio, denomErrNorm, xlabel_original, mgInfo->plot->GetXaxis(), mgInfo->plot->GetYaxis(), axisRescaling);
375 TGraphAsymmErrors*
ratio =
new TGraphAsymmErrors(
num,
denom,
"pois");
383 TGraphAsymmErrors*
ratio =
new TGraphAsymmErrors();
386 for (Int_t
i=0;
i<
denom->GetN(); ++
i){
387 if (
denom->GetPointY(
i) <= 0.0)
continue;
389 if (num_idx < 0)
continue;
391 Double_t ratio_val =
num->GetPointY(num_idx)/
denom->GetPointY(
i);
392 Double_t error_low =
num->GetErrorYlow(num_idx)/
denom->GetPointY(
i);
393 Double_t error_up =
num->GetErrorYhigh(num_idx)/
denom->GetPointY(
i);
396 ratio->SetPointError(
ratio->GetN()-1,
denom->GetErrorXlow(
i),
denom->GetErrorXhigh(
i), error_low, error_up);
403 void MSVtxPlotComparison::drawRatio(TGraphAsymmErrors*
ratio, TGraphAsymmErrors* denomErrNorm,
const TString &xlabel,
const TAxis* plotXaxis,
const TAxis* plotYaxis,
double axisRescaling){
407 TMultiGraph*
mg =
new TMultiGraph();
413 ratio->SetMarkerSize(0.5);
416 denomErrNorm->SetFillColorAlpha(
m_colors[0], 0.3);
417 denomErrNorm->SetFillStyle(1001);
418 mg->Add(denomErrNorm,
"2");
424 mg->GetXaxis()->ImportAttributes(plotXaxis);
425 mg->GetXaxis()->SetLimits(plotXaxis->GetXmin(), plotXaxis->GetXmax());
426 mg->GetXaxis()->SetTitle(xlabel);
427 mg->GetXaxis()->SetTitleSize(axisRescaling*plotXaxis->GetTitleSize());
428 mg->GetXaxis()->SetTickLength(axisRescaling*plotXaxis->GetTickLength());
429 mg->GetXaxis()->SetLabelSize(axisRescaling*plotXaxis->GetLabelSize());
431 mg->GetYaxis()->SetRangeUser(-0.2, 2.2);
433 mg->GetYaxis()->SetTitleOffset(0.5);
434 mg->GetYaxis()->SetTitleSize(axisRescaling*plotYaxis->GetTitleSize());
435 mg->GetYaxis()->SetLabelSize(axisRescaling*plotYaxis->GetLabelSize());
438 const std::vector<double> vlines{1.};
439 for (
double height : vlines) {
440 TLine*
l =
new TLine(
mg->GetXaxis()->GetXmin(), height,
mg->GetXaxis()->GetXmax(), height);
454 Bool_t isfromTH1 = objectClass->InheritsFrom(
"TH1");
455 Bool_t isNotTH2 = !objectClass->InheritsFrom(
"TH2");
456 Bool_t isNotTHStack = !objectClass->InheritsFrom(
"THStack");
457 return isfromTH1 && isNotTH2 && isNotTHStack;
463 return objectClass->InheritsFrom(
"TEfficiency");
470 TObject *
h =
key->ReadObj();
471 const TString
name(
h->GetName());
473 return name.Contains(
"Reco") ||
name.Contains(
"Truth") ||
name.Contains(
"stack");
479 TPad *pad =
new TPad(
"fullCanvas",
"fullCanvas", 0, 0, 1, 1);
490 Double_t *xs = graph->GetX();
491 for (Int_t
i=0;
i<graph->GetN(); ++
i)
if (std::abs(xs[
i]-
x) <= 1
e-6)
return i;
498 TGraphAsymmErrors* graphErrNorm =
new TGraphAsymmErrors();
499 for (Int_t
i=0;
i<graph->GetN(); ++
i){
500 if (graph->GetPointY(
i) == 0)
continue;
501 graphErrNorm->AddPoint(graph->GetPointX(
i), 1.);
502 graphErrNorm->SetPointError(
i, graph->GetErrorXlow(
i), graph->GetErrorXhigh(
i), graph->GetErrorYlow(
i)/graph->GetPointY(
i), graph->GetErrorYhigh(
i)/graph->GetPointY(
i));
503 graphErrNorm->SetPoint(
i, graph->GetPointX(
i), 1.);