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);
107 legend->SetNColumns(2);
113 std::unique_ptr<TFile>
file(TFile::Open(TString(
m_datapaths[i]+
"Histograms.root"),
"read"));
114 TH1* pH =
static_cast<TH1*
>(
file->Get(name));
120 legend->AddEntry(
h,
m_labels[i].c_str(),
"L");
122 maxy = pH->GetMaximum() > maxy ? pH->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);
185 double axisRescaling = (y2-y1)/(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(
static_cast<TH1*
>(obj));
205 TGraphAsymmErrors* ratio =
getRatio(hists[1], hists[0]);
206 TGraphAsymmErrors* denomErrNorm =
getNormalisedGraph(
new TGraphAsymmErrors(hists[0]));
207 drawRatio(ratio, denomErrNorm, xlabel_original, hstackInfo->plot->GetXaxis(), hstackInfo->plot->GetYaxis(), axisRescaling);
218 else if (name.Contains(
"MDT") || name.Contains(
"RPC") || name.Contains(
"TGC")) plotpath =
m_plotdir_recoVtxHits+name;
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);
255 legend->SetNColumns(2);
261 std::unique_ptr<TFile>
file(TFile::Open(TString(
m_datapaths[i]+
"Histograms.root"),
"read"));
262 TEfficiency* pH =
static_cast<TEfficiency*
>(
file->Get(name));
267 pH->SetMarkerSize(0.5);
271 TGraphAsymmErrors* g = pH->GetPaintedGraph();
273 legend->AddEntry(pH,
m_labels[i].c_str(),
"PEL");
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);
330 double axisRescaling = (y2-y1)/(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);
349 std::vector<TGraphAsymmErrors*> efficiencies;
350 for(TObject *obj : *(mgInfo->plot->GetListOfGraphs())) efficiencies.push_back(
static_cast<TGraphAsymmErrors*
>(obj));
351 TGraphAsymmErrors* ratio =
getRatio(efficiencies[1], efficiencies[0]);
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;
388 Int_t num_idx =
getPointIdx(num, denom->GetPointX(i));
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);
395 ratio->AddPoint(denom->GetPointX(i), ratio_val);
396 ratio->SetPointError(ratio->GetN()-1, denom->GetErrorXlow(i), denom->GetErrorXhigh(i), error_low, error_up);
403void 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);
414 mg->Add(ratio,
"PEZ");
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);
432 mg->GetYaxis()->SetTitle(TString::Format(
"#frac{%s}{%s}",
m_labels[1].c_str(),
m_labels[0].c_str()).
Data());
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) <= 1e-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.);
TString m_plotdir_truthVtx
void drawRatio(TGraphAsymmErrors *ratio, TGraphAsymmErrors *denomErrNorm, const TString &xlabel, const TAxis *plotXaxis, const TAxis *plotYaxis, double axisRescaling)
Bool_t isTEfficiency(const TClass *objectClass)
std::vector< std::string > m_labels
const TString getTMultigraphplotpath(const TString &name)
TGraphAsymmErrors * getNormalisedGraph(const TGraphAsymmErrors *graph)
static constexpr std::array m_markers
Bool_t ignorePlot(TKey *key)
TString m_plotdir_vtxFakeRate
const TString getTHStackplotpath(const TString &name)
const std::array< Int_t, 10 > m_colors
MSVtxPlotComparison(const std::vector< std::string > &datapaths, const std::vector< std::string > &labels, const std::string &pltdir)
void drawTHStack(std::unique_ptr< PlotInfo< THStack > > &hstackInfo)
void drawTMultigraph(std::unique_ptr< PlotInfo< TMultiGraph > > &mgInfo)
std::unique_ptr< MSVtxPlotComparison::PlotInfo< THStack > > getTHStackPlotInfo(const TH1 *h)
TString m_plotdir_inputObjects
Bool_t isTH1(const TClass *objectClass)
TString m_plotdir_recoVtxHits
void drawTMultigraphRatioPlot(std::unique_ptr< PlotInfo< TMultiGraph > > &mgInfo)
void makeTH1Comparison(TKey *key)
Int_t getPointIdx(const TGraphAsymmErrors *graph, double x)
TGraphAsymmErrors * getRatio(const TH1 *num, const TH1 *denom)
void makeTEfficiencyComparison(TKey *key)
TString m_plotdir_recoVtx
void drawTHStackRatioPlot(std::unique_ptr< PlotInfo< THStack > > &hstackInfo)
std::unique_ptr< TFile > m_output_file
std::unique_ptr< TCanvas > m_c
virtual ~MSVtxPlotComparison()
void drawTMultigraphPlot(std::unique_ptr< PlotInfo< TMultiGraph > > &mgInfo)
void drawTHStackPlot(std::unique_ptr< PlotInfo< THStack > > &hstackInfo)
std::unique_ptr< MSVtxPlotComparison::PlotInfo< TMultiGraph > > getTMultigraphPlotInfo(TEfficiency *h)
TString m_plotdir_vtxEfficiency
TString m_plotdir_vtxResiduals
std::vector< std::string > m_datapaths
double getMaxy(const TGraphAsymmErrors *graph, double current_max)
void drawATLASlabel(const char *text, double x, double y, double textsize)
TLegend * makeLegend(double lower_x, double lower_y, double upper_x, double upper_y, double textsize)
void drawDetectorRegionLabel(const char *name, const char *customlabel, double x, double y, double textsize)
void drawDetectorBoundaryLines(const char *bin_var, double y_max)