ATLAS Offline Software
Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
MSVtxPlotComparison Class Reference

#include <MSVtxPlotComparison.h>

Collaboration diagram for MSVtxPlotComparison:

Classes

struct  PlotInfo
 

Public Member Functions

 MSVtxPlotComparison (const std::vector< std::string > &datapaths, const std::vector< std::string > &labels, const std::string &pltdir)
 
virtual ~MSVtxPlotComparison ()
 
void makeComparison ()
 

Private Member Functions

void setup ()
 
void setPlotStyle ()
 
void makeTH1Comparison (TKey *key)
 
std::unique_ptr< MSVtxPlotComparison::PlotInfo< THStack > > getTHStackPlotInfo (const TH1 *h)
 
void drawTHStack (std::unique_ptr< PlotInfo< THStack >> &hstackInfo)
 
void drawTHStackPlot (std::unique_ptr< PlotInfo< THStack >> &hstackInfo)
 
void drawTHStackRatioPlot (std::unique_ptr< PlotInfo< THStack >> &hstackInfo)
 
const TString getTHStackplotpath (const TString &name)
 
void makeTEfficiencyComparison (TKey *key)
 
std::unique_ptr< MSVtxPlotComparison::PlotInfo< TMultiGraph > > getTMultigraphPlotInfo (TEfficiency *h)
 
void drawTMultigraph (std::unique_ptr< PlotInfo< TMultiGraph >> &mgInfo)
 
void drawTMultigraphPlot (std::unique_ptr< PlotInfo< TMultiGraph >> &mgInfo)
 
void drawTMultigraphRatioPlot (std::unique_ptr< PlotInfo< TMultiGraph >> &mgInfo)
 
const TString getTMultigraphplotpath (const TString &name)
 
TGraphAsymmErrors * getRatio (const TH1 *num, const TH1 *denom)
 
TGraphAsymmErrors * getRatio (const TGraphAsymmErrors *num, const TGraphAsymmErrors *denom)
 
void drawRatio (TGraphAsymmErrors *ratio, TGraphAsymmErrors *denomErrNorm, const TString &xlabel, const TAxis *plotXaxis, const TAxis *plotYaxis, double axisRescaling)
 
Bool_t ignorePlot (TKey *key)
 
Bool_t isTH1 (const TClass *objectClass)
 
Bool_t isTEfficiency (const TClass *objectClass)
 
void makeSinglePad ()
 
Int_t getPointIdx (const TGraphAsymmErrors *graph, double x)
 
TGraphAsymmErrors * getNormalisedGraph (const TGraphAsymmErrors *graph)
 

Private Attributes

std::vector< std::string > m_datapaths {}
 
std::vector< std::string > m_labels {}
 
bool m_makeRatioPlots {}
 
TString m_plotdir {}
 
TString m_plotdir_truthVtx {}
 
TString m_plotdir_recoVtx {}
 
TString m_plotdir_recoVtxHits {}
 
TString m_plotdir_vtxResiduals {}
 
TString m_plotdir_inputObjects {}
 
TString m_plotdir_vtxEfficiency {}
 
TString m_plotdir_vtxFakeRate {}
 
std::unique_ptr< TFile > m_output_file {nullptr}
 
std::unique_ptr< TCanvas > m_c {nullptr}
 
const Int_t m_kP10Blue = TColor::GetColor("#3f90da")
 
const Int_t m_kP10Yellow = TColor::GetColor("#ffa90e")
 
const Int_t m_kP10Red = TColor::GetColor("#bd1f01")
 
const Int_t m_kP10Grey = TColor::GetColor("#832db6")
 
const Int_t m_kP10Violet = TColor::GetColor("#a96b59")
 
const Int_t m_kP10Brown = TColor::GetColor("#94a4a2")
 
const Int_t m_kP10Orange = TColor::GetColor("#e76300")
 
const Int_t m_kP10Green = TColor::GetColor("#b9ac70")
 
const Int_t m_kP10Ash = TColor::GetColor("#717581")
 
const Int_t m_kP10Cyan = TColor::GetColor("#92dadd")
 
const std::array< Int_t, 10 > m_colors {m_kP10Blue, m_kP10Yellow, m_kP10Red, m_kP10Grey, m_kP10Violet, m_kP10Brown, m_kP10Orange, m_kP10Green, m_kP10Ash, m_kP10Cyan}
 

Static Private Attributes

static constexpr std::array m_markers {kOpenCircle, kOpenSquare, kOpenTriangleUp, kOpenDiamond, kOpenStar, kOpenTriangleDown, kOpenDoubleDiamond, kOpenCrossX}
 

Detailed Description

Definition at line 37 of file MSVtxPlotComparison.h.

Constructor & Destructor Documentation

◆ MSVtxPlotComparison()

MSVtxPlotComparison::MSVtxPlotComparison ( const std::vector< std::string > &  datapaths,
const std::vector< std::string > &  labels,
const std::string &  pltdir 
)

Definition at line 10 of file MSVtxPlotComparison.cxx.

10  :
11  m_datapaths(datapaths), m_labels(labels), m_makeRatioPlots(m_datapaths.size()==2),
12  m_plotdir(pltdir),
13  m_plotdir_truthVtx(m_plotdir+"truthVtx/"),
14  m_plotdir_recoVtx(m_plotdir+"recoVtx/"),
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/")
20  {}

◆ ~MSVtxPlotComparison()

MSVtxPlotComparison::~MSVtxPlotComparison ( )
virtualdefault

Member Function Documentation

◆ drawRatio()

void MSVtxPlotComparison::drawRatio ( TGraphAsymmErrors *  ratio,
TGraphAsymmErrors *  denomErrNorm,
const TString &  xlabel,
const TAxis *  plotXaxis,
const TAxis *  plotYaxis,
double  axisRescaling 
)
private

Definition at line 403 of file MSVtxPlotComparison.cxx.

403  {
404  // Draw the ratio plot to the currently active pad.
405  // The error on the ratio is assumed to be numeratorError/denominator while denominatorError/denominator is shows as a shaded band around a ratio of 1.
406 
407  TMultiGraph* mg = new TMultiGraph();
408 
409  // add ratio
410  ratio->SetLineColor(m_colors[1]);
411  ratio->SetMarkerColor(m_colors[1]);
412  ratio->SetMarkerStyle(m_markers[1]);
413  ratio->SetMarkerSize(0.5);
414  mg->Add(ratio, "PEZ"); // draw markers and no vertical lines on the error bars
415  // add error band for the denominator error
416  denomErrNorm->SetFillColorAlpha(m_colors[0], 0.3);
417  denomErrNorm->SetFillStyle(1001);
418  mg->Add(denomErrNorm, "2");
419 
420  mg->Draw("AP");
421 
422  // axis formatting: scale to pad size
423  // import x axis attributes and limits from the original plot
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());
430 
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());
436 
437  // draw horizontal lines
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);
441  l->SetLineColor(m_colors[8]);
442  l->SetLineStyle(7);
443  l->Draw();
444  }
445 
446  return;
447 }

◆ drawTHStack()

void MSVtxPlotComparison::drawTHStack ( std::unique_ptr< PlotInfo< THStack >> &  hstackInfo)
private

Definition at line 129 of file MSVtxPlotComparison.cxx.

129  {
130  // The results are saved to the output directory in the `m_output_file` and as a pdf figure.
131  m_output_file->cd(); // needed here as previously histograms are loaded from input files
132  if (m_makeRatioPlots) drawTHStackRatioPlot(hstackInfo);
133  else drawTHStackPlot(hstackInfo);
134 
135  m_c->SaveAs(getTHStackplotpath(TString(hstackInfo->plot->GetName()))+".pdf");
136  m_c->Clear();
137 
138  return;
139 }

◆ drawTHStackPlot()

void MSVtxPlotComparison::drawTHStackPlot ( std::unique_ptr< PlotInfo< THStack >> &  hstackInfo)
private

Definition at line 142 of file MSVtxPlotComparison.cxx.

142  {
143  // Draws the THStack plot to the currently active pad and writes it to the m_output_file root file.
144  // adjust maximum for sufficient space for annotations and draw annotations
145 
146  // required to set a new pad for the full canvas in order for style settings to apply
148 
149  hstackInfo->plot->Draw("nostack");
150  // adjust maximum for sufficient space for annotations and draw annotations
151  const TString name(hstackInfo->plot->GetName());
152  double maxy_factor{1.4};
153 // TODO: fix this
154  // if (name.Contains("log")){
155  // gPad->SetLogy();
156  // maxy_factor = 4;
157  // }
158  hstackInfo->plot->SetMaximum(maxy_factor*hstackInfo->maxy);
159  // axis labels
160  hstackInfo->plot->GetXaxis()->SetTitle(hstackInfo->xlabel);
161  hstackInfo->plot->GetYaxis()->SetTitle(hstackInfo->ylabel);
162  // annotations
163  hstackInfo->legend->Draw();
165  drawATLASlabel("Simulation Internal");
166 
167  hstackInfo->plot->Write();
168 // TODO: adjust this when the above is fixed
169  // gPad->SetLogy(0); // reset log scale for next plots
170 
171  return;
172 }

◆ drawTHStackRatioPlot()

void MSVtxPlotComparison::drawTHStackRatioPlot ( std::unique_ptr< PlotInfo< THStack >> &  hstackInfo)
private

Definition at line 175 of file MSVtxPlotComparison.cxx.

175  {
176  // Creates two pads to draw the THStack plot and its ratio to.
177  // The ratio is formed as the second/first histograms in the THStack.
178 
179  // create pads
180  double x1{0.}, x2{1.};
181  double y1{0.3}, y2{1.};
182  double gap{0.05};
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);
186 
187  // draw THStack in upper pad
188  padPlot->SetBottomMargin(0);
189  padPlot->Draw();
190  padPlot->cd();
191  TString xlabel_original = hstackInfo->xlabel;
192  hstackInfo->xlabel = TString("");
193  drawTHStackPlot(hstackInfo);
194  // remove first y axis label for the upper plot as it gets cut off
195  hstackInfo->plot->GetYaxis()->ChangeLabel(1, -1, -1, -1, -1, -1, " ");
196  // compute and draw the ratio plot
197  m_c->cd();
198  padRatio->SetTopMargin(0);
199  padRatio->SetBottomMargin(0.45);
200  padRatio->Draw();
201  padRatio->cd();
202 
203  std::vector<TH1*> hists{};
204  for(TObject *obj : *(hstackInfo->plot->GetHists())) hists.push_back((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);
208 
209  return;
210 }

◆ drawTMultigraph()

void MSVtxPlotComparison::drawTMultigraph ( std::unique_ptr< PlotInfo< TMultiGraph >> &  mgInfo)
private

Definition at line 282 of file MSVtxPlotComparison.cxx.

282  {
283  // The results are saved to the output directory in the `m_output_file` and as a pdf figure.
284  m_output_file->cd();
286  else drawTMultigraphPlot(mgInfo);
287 
288  m_c->SaveAs(getTMultigraphplotpath(TString(mgInfo->plot->GetName()))+".pdf");
289  m_c->Clear();
290  return;
291 }

◆ drawTMultigraphPlot()

void MSVtxPlotComparison::drawTMultigraphPlot ( std::unique_ptr< PlotInfo< TMultiGraph >> &  mgInfo)
private

Definition at line 294 of file MSVtxPlotComparison.cxx.

294  {
295  // Draws the TMultiGraph plot to the currently active pad and writes it to the `m_output_file` root file.
296 
297  // required to set a new pad for the full canvas in order for style settings to apply
299 
300  mgInfo->plot->Draw("AP");
301  // adjust maximum for sufficient space for annotations and draw annotations
302  mgInfo->plot->GetYaxis()->SetRangeUser(0, 1.4*mgInfo->maxy);
303  // axis labels
304  mgInfo->plot->GetXaxis()->SetTitle(mgInfo->xlabel);
305  mgInfo->plot->GetYaxis()->SetTitle(mgInfo->ylabel);
306  // annotations
307  mgInfo->legend->Draw();
308  const TString name(mgInfo->plot->GetName());
309  if (name.Contains("_Lxy_")) drawDetectorBoundaryLines("Lxy", 1.1*mgInfo->maxy);
310  if (name.Contains("_z_")) drawDetectorBoundaryLines("z", 1.1*mgInfo->maxy);
312  drawATLASlabel("Simulation Internal");
313 
314  mgInfo->plot->Write();
315 
316  return;
317 }

◆ drawTMultigraphRatioPlot()

void MSVtxPlotComparison::drawTMultigraphRatioPlot ( std::unique_ptr< PlotInfo< TMultiGraph >> &  mgInfo)
private

Definition at line 320 of file MSVtxPlotComparison.cxx.

320  {
321  // Creates two pads to draw the TMultiGraph plot and its ratio to.
322  // The ratio is formed between the first and second graph in the TMultiGraph.
323 
324  // create pads
325  double x1{0.}, x2{1.};
326  double y1{0.3}, y2{1.};
327  double gap{0.05};
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);
331 
332  // draw TMultiGraph in upper pad
333  padPlot->SetBottomMargin(0);
334  padPlot->Draw();
335  padPlot->cd();
336  TString xlabel_original = mgInfo->xlabel;
337  mgInfo->xlabel = TString("");
338  drawTMultigraphPlot(mgInfo);
339  // remove first y axis label for the upper plot as it gets cut off
340  mgInfo->plot->GetYaxis()->ChangeLabel(1, -1, -1, -1, -1, -1, " ");
341 
342  // compute and draw the ratio plot
343  m_c->cd();
344  padRatio->SetTopMargin(0);
345  padRatio->SetBottomMargin(0.45);
346  padRatio->Draw();
347  padRatio->cd();
348 
349  std::vector<TGraphAsymmErrors*> efficiencies;
350  for(TObject *obj : *(mgInfo->plot->GetListOfGraphs())) efficiencies.push_back((TGraphAsymmErrors*)obj);
351  TGraphAsymmErrors* ratio = getRatio(efficiencies[1], efficiencies[0]);
352  TGraphAsymmErrors* denomErrNorm = getNormalisedGraph(efficiencies[0]);
353  drawRatio(ratio, denomErrNorm, xlabel_original, mgInfo->plot->GetXaxis(), mgInfo->plot->GetYaxis(), axisRescaling);
354 
355  return;
356 }

◆ getNormalisedGraph()

TGraphAsymmErrors * MSVtxPlotComparison::getNormalisedGraph ( const TGraphAsymmErrors *  graph)
private

Definition at line 496 of file MSVtxPlotComparison.cxx.

496  {
497  // returns a TGraphAsymmErrors object with unit y values and the y error normalized to the y value at the point.
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.); // need to set point again to avoid ROOT overwriting the point value to (0,0)
504  }
505 
506  return graphErrNorm;
507 
508 }

◆ getPointIdx()

Int_t MSVtxPlotComparison::getPointIdx ( const TGraphAsymmErrors *  graph,
double  x 
)
private

Definition at line 487 of file MSVtxPlotComparison.cxx.

487  {
488  // Returns the index of the point in graph at position x
489  // if x is not contained in the graph, returns -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;
492  return -1;
493 }

◆ getRatio() [1/2]

TGraphAsymmErrors * MSVtxPlotComparison::getRatio ( const TGraphAsymmErrors *  num,
const TGraphAsymmErrors *  denom 
)
private

Definition at line 381 of file MSVtxPlotComparison.cxx.

381  {
382  // returns ratio of two TEfficiency histograms as a TGraphAsymmErrors object with manual ratio and error computation.
383  TGraphAsymmErrors* ratio = new TGraphAsymmErrors();
384 
385  // can only compute the ratio for points where the denominator is non-zero and denominator and numerator values exist
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;
390 
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);
394 
395  ratio->AddPoint(denom->GetPointX(i), ratio_val);
396  ratio->SetPointError(ratio->GetN()-1, denom->GetErrorXlow(i), denom->GetErrorXhigh(i), error_low, error_up);
397  }
398 
399  return ratio;
400 }

◆ getRatio() [2/2]

TGraphAsymmErrors * MSVtxPlotComparison::getRatio ( const TH1 *  num,
const TH1 *  denom 
)
private

Definition at line 372 of file MSVtxPlotComparison.cxx.

372  {
373  // returns ratio of two TH1 histograms as a TGraphAsymmErrors object by treating the histograms as two Poisson means.
374 // TODO: suppress warnings from TGraphAsymmErrors::Divide
375  TGraphAsymmErrors* ratio = new TGraphAsymmErrors(num, denom, "pois"); // prints warning when denom is zero, in which case no ratio is computed
376 
377  return ratio;
378 }

◆ getTHStackPlotInfo()

std::unique_ptr< MSVtxPlotComparison::PlotInfo< THStack > > MSVtxPlotComparison::getTHStackPlotInfo ( const TH1 *  h)
private

Definition at line 97 of file MSVtxPlotComparison.cxx.

97  {
98  // Extracts the histogram with `name` form the Histograms.root files for each passed data path and adds them to a THStack object.
99 
100  const TString name(h->GetName());
101  TString xlabel(h->GetXaxis()->GetTitle());
102  TString ylabel(h->GetYaxis()->GetTitle());
103 
104  // create a named THStack and the legend
105  auto hstack = std::make_unique<THStack>(name, name);
106  TLegend* legend = makeLegend();
107  legend->SetNColumns(2);
108 
109  // loop on TH1 histograms and add them to the THStack and legend
110  double maxy{0.};
111  for (unsigned int i=0; i<m_datapaths.size(); ++i){
112  // retrieve histogram and set drawing style
113  std::unique_ptr<TFile> file(TFile::Open(TString(m_datapaths[i]+"Histograms.root"), "read"));
114  TH1* h = static_cast<TH1*>(file->Get(name));
115  h->SetDirectory(0); // histogram doesn't belong to any directory now to avoid clashing memory management with the smart pointer file
116  h->SetLineColor(m_colors[i]);
117  h->SetLineStyle(1);
118  // add to THStack and legend
119  hstack->Add(h);
120  legend->AddEntry(h, m_labels[i].c_str(), "L");
121  // update maximal y value
122  maxy = h->GetMaximum() > maxy ? h->GetMaximum() : maxy;
123  }
124 
125  return std::make_unique<PlotInfo<THStack>>(std::move(hstack), legend, maxy, xlabel, ylabel);
126 }

◆ getTHStackplotpath()

const TString MSVtxPlotComparison::getTHStackplotpath ( const TString &  name)
private

Definition at line 213 of file MSVtxPlotComparison.cxx.

213  {
214  // choose plot path based on the name
215  TString plotpath{};
216  if (name.Contains("truth")) plotpath = m_plotdir_truthVtx+name;
217  // else if (name.Contains("reco")) plotpath = m_plotdir_recoVtx+name;
218  else if (name.Contains("MDT") || name.Contains("RPC") || name.Contains("TGC")) plotpath = m_plotdir_recoVtxHits+name;
219  else if (name.Contains("delta")) plotpath = m_plotdir_vtxResiduals+name;
220  else if (name.Contains("obj")) plotpath = m_plotdir_inputObjects+name;
221  else plotpath = m_plotdir_recoVtx+name;
222 
223  return plotpath;
224 }

◆ getTMultigraphPlotInfo()

std::unique_ptr< MSVtxPlotComparison::PlotInfo< TMultiGraph > > MSVtxPlotComparison::getTMultigraphPlotInfo ( TEfficiency *  h)
private

Definition at line 242 of file MSVtxPlotComparison.cxx.

242  {
243  // Extracts the histogram with `name` form the Histograms.root files for each passed data path to draw and adds them to a TMultiGraph object.
244 
245  const TString name(h->GetName());
246  h->Draw();
247  gPad->Update();
248  const TString xlabel(h->GetPaintedGraph()->GetXaxis()->GetTitle());
249  const TString ylabel(h->GetPaintedGraph()->GetYaxis()->GetTitle());
250  m_c->Clear(); // needed to clear the canvas after drawing the TEfficiency object
251 
252  // create a named multigraph and the legend
253  auto mg = std::make_unique<TMultiGraph>(name, name);
254  TLegend* legend = makeLegend();
255  legend->SetNColumns(2);
256 
257  // loop on histograms and add them to the multigraph and legend
258  double maxy{0.};
259  for (unsigned int i=0; i<m_datapaths.size(); ++i){
260  // retrieve histogram and set drawing style
261  std::unique_ptr<TFile> file(TFile::Open(TString(m_datapaths[i]+"Histograms.root"), "read"));
262  TEfficiency* h = static_cast<TEfficiency*>(file->Get(name));
263  h->SetLineColor(m_colors[i]);
264  h->SetLineStyle(1);
265  h->SetMarkerColor(m_colors[i]);
266  h->SetMarkerStyle(m_markers[i]);
267  h->SetMarkerSize(0.5);
268  // add to multigraph and legend
269  h->Draw();
270  gPad->Update();
271  TGraphAsymmErrors* g = h->GetPaintedGraph();
272  mg->Add(g, "PEZ"); // draw markers and no vertical lines on the error bars
273  legend->AddEntry(h, m_labels[i].c_str(), "PEL"); // draw marker, vertical error bar and line in legend
274  maxy = getMaxy(g, maxy);
275  m_c->Clear(); // needed to clear the canvas after drawing the TEfficiency object
276  }
277 
278  return std::make_unique<PlotInfo<TMultiGraph>>(std::move(mg), legend, maxy, xlabel, ylabel);
279 }

◆ getTMultigraphplotpath()

const TString MSVtxPlotComparison::getTMultigraphplotpath ( const TString &  name)
private

Definition at line 359 of file MSVtxPlotComparison.cxx.

359  {
360  // choose plot path based on the name
361  TString plotpath{};
362  if (name.Contains("eff_")) plotpath = m_plotdir_vtxEfficiency+name;
363  else if (name.Contains("frate_")) plotpath = m_plotdir_vtxFakeRate+name;
364  else plotpath = m_plotdir_recoVtx+name;
365 
366  return plotpath;
367 }

◆ ignorePlot()

Bool_t MSVtxPlotComparison::ignorePlot ( TKey *  key)
private

Definition at line 467 of file MSVtxPlotComparison.cxx.

467  {
468  // Specifies conditions to ignore certain plots:
469  // stacked plots for efficiency numerator, denominator
470  TObject *h = key->ReadObj();
471  const TString name(h->GetName());
472 
473  return name.Contains("Reco") || name.Contains("Truth") || name.Contains("stack");
474 }

◆ isTEfficiency()

Bool_t MSVtxPlotComparison::isTEfficiency ( const TClass *  objectClass)
private

Definition at line 461 of file MSVtxPlotComparison.cxx.

461  {
462  // returns true if the object class is a TEfficiency object
463  return objectClass->InheritsFrom("TEfficiency");
464 }

◆ isTH1()

Bool_t MSVtxPlotComparison::isTH1 ( const TClass *  objectClass)
private

Definition at line 452 of file MSVtxPlotComparison.cxx.

452  {
453  // returns true if the object class is a TH1 object
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;
458 }

◆ makeComparison()

void MSVtxPlotComparison::makeComparison ( )

Definition at line 26 of file MSVtxPlotComparison.cxx.

26  {
27  // Generates a series of comparison plots, stored in the output directory `m_plotdir` as a root file and a pdf figure.
28  // When only two data paths are passed, a ratio plot is also drawn.
29 
30  setup();
31  setPlotStyle();
32 
33  // get list of histogram keys from one of the input files
34  std::unique_ptr<TFile> file_0(TFile::Open(TString(m_datapaths[0]+"Histograms.root"), "read"));
35  TIter keyIter(file_0->GetListOfKeys());
36 
37  // loop over the keys and call the appropriate comparison maker
38  TKey* key{nullptr};
39  while ((key = (TKey*)keyIter())) {
40  TClass *objectClass = gROOT->GetClass(key->GetClassName());
41  if (ignorePlot(key)) continue;
42  if (isTH1(objectClass)) makeTH1Comparison(key);
43  if (isTEfficiency(objectClass)) makeTEfficiencyComparison(key);
44  }
45 
46  m_output_file->Write();
47  m_output_file->Close();
48 
49  return;
50 }

◆ makeSinglePad()

void MSVtxPlotComparison::makeSinglePad ( )
private

Definition at line 477 of file MSVtxPlotComparison.cxx.

477  {
478  // creates and moves to a single pad for the full canvas
479  TPad *pad = new TPad("fullCanvas", "fullCanvas", 0, 0, 1, 1);
480  pad->Draw();
481  pad->cd();
482 
483  return;
484 }

◆ makeTEfficiencyComparison()

void MSVtxPlotComparison::makeTEfficiencyComparison ( TKey *  key)
private

Definition at line 229 of file MSVtxPlotComparison.cxx.

229  {
230  // Finds the name and axis labels for the passed key which is assumed to belong to a TEfficiency object
231  // Then calls the TEfficiency comparison maker to produce the plots
232 
233  TEfficiency *h = static_cast<TEfficiency*>(key->ReadObj());
234 
235  std::unique_ptr<PlotInfo<TMultiGraph>> mgInfo = getTMultigraphPlotInfo(h);
236  drawTMultigraph(mgInfo);
237 
238  return;
239 }

◆ makeTH1Comparison()

void MSVtxPlotComparison::makeTH1Comparison ( TKey *  key)
private

Definition at line 84 of file MSVtxPlotComparison.cxx.

84  {
85  // Finds the name and axis labels for the passed key which is assumed to belong to a TH1 object
86  // Then calls the TH1 comparison maker to produce the plots
87 
88  TH1 *h = static_cast<TH1*>(key->ReadObj());
89 
90  std::unique_ptr<PlotInfo<THStack>> hstackInfo = getTHStackPlotInfo(h);
91  drawTHStack(hstackInfo);
92 
93  return;
94 }

◆ setPlotStyle()

void MSVtxPlotComparison::setPlotStyle ( )
private

Definition at line 70 of file MSVtxPlotComparison.cxx.

70  {
71  gROOT->SetStyle("ATLAS");
72  TStyle* plotStyle = gROOT->GetStyle("ATLAS");
73  plotStyle->SetOptTitle(0);
74  plotStyle->SetHistLineWidth(1.);
75  plotStyle->cd();
76  gROOT->ForceStyle();
77 
78  return;
79 }

◆ setup()

void MSVtxPlotComparison::setup ( )
private

Definition at line 53 of file MSVtxPlotComparison.cxx.

53  {
54  // set up the output directories, the output root file, and canvas.
55  gSystem->mkdir(m_plotdir, kTRUE);
56  gSystem->mkdir(m_plotdir_truthVtx, kTRUE);
57  gSystem->mkdir(m_plotdir_recoVtx, kTRUE);
58  gSystem->mkdir(m_plotdir_recoVtxHits, kTRUE);
59  gSystem->mkdir(m_plotdir_vtxResiduals, kTRUE);
60  gSystem->mkdir(m_plotdir_inputObjects, kTRUE);
61  gSystem->mkdir(m_plotdir_vtxEfficiency, kTRUE);
62  gSystem->mkdir(m_plotdir_vtxFakeRate, kTRUE);
63  m_c = std::make_unique<TCanvas>();
64  m_output_file = std::make_unique<TFile>(m_plotdir+"Histograms.root", "recreate");
65 
66  return;
67 }

Member Data Documentation

◆ m_c

std::unique_ptr<TCanvas> MSVtxPlotComparison::m_c {nullptr}
private

Definition at line 97 of file MSVtxPlotComparison.h.

◆ m_colors

const std::array<Int_t, 10> MSVtxPlotComparison::m_colors {m_kP10Blue, m_kP10Yellow, m_kP10Red, m_kP10Grey, m_kP10Violet, m_kP10Brown, m_kP10Orange, m_kP10Green, m_kP10Ash, m_kP10Cyan}
private

Definition at line 113 of file MSVtxPlotComparison.h.

◆ m_datapaths

std::vector<std::string> MSVtxPlotComparison::m_datapaths {}
private

Definition at line 85 of file MSVtxPlotComparison.h.

◆ m_kP10Ash

const Int_t MSVtxPlotComparison::m_kP10Ash = TColor::GetColor("#717581")
private

Definition at line 110 of file MSVtxPlotComparison.h.

◆ m_kP10Blue

const Int_t MSVtxPlotComparison::m_kP10Blue = TColor::GetColor("#3f90da")
private

Definition at line 102 of file MSVtxPlotComparison.h.

◆ m_kP10Brown

const Int_t MSVtxPlotComparison::m_kP10Brown = TColor::GetColor("#94a4a2")
private

Definition at line 107 of file MSVtxPlotComparison.h.

◆ m_kP10Cyan

const Int_t MSVtxPlotComparison::m_kP10Cyan = TColor::GetColor("#92dadd")
private

Definition at line 111 of file MSVtxPlotComparison.h.

◆ m_kP10Green

const Int_t MSVtxPlotComparison::m_kP10Green = TColor::GetColor("#b9ac70")
private

Definition at line 109 of file MSVtxPlotComparison.h.

◆ m_kP10Grey

const Int_t MSVtxPlotComparison::m_kP10Grey = TColor::GetColor("#832db6")
private

Definition at line 105 of file MSVtxPlotComparison.h.

◆ m_kP10Orange

const Int_t MSVtxPlotComparison::m_kP10Orange = TColor::GetColor("#e76300")
private

Definition at line 108 of file MSVtxPlotComparison.h.

◆ m_kP10Red

const Int_t MSVtxPlotComparison::m_kP10Red = TColor::GetColor("#bd1f01")
private

Definition at line 104 of file MSVtxPlotComparison.h.

◆ m_kP10Violet

const Int_t MSVtxPlotComparison::m_kP10Violet = TColor::GetColor("#a96b59")
private

Definition at line 106 of file MSVtxPlotComparison.h.

◆ m_kP10Yellow

const Int_t MSVtxPlotComparison::m_kP10Yellow = TColor::GetColor("#ffa90e")
private

Definition at line 103 of file MSVtxPlotComparison.h.

◆ m_labels

std::vector<std::string> MSVtxPlotComparison::m_labels {}
private

Definition at line 86 of file MSVtxPlotComparison.h.

◆ m_makeRatioPlots

bool MSVtxPlotComparison::m_makeRatioPlots {}
private

Definition at line 87 of file MSVtxPlotComparison.h.

◆ m_markers

constexpr std::array MSVtxPlotComparison::m_markers {kOpenCircle, kOpenSquare, kOpenTriangleUp, kOpenDiamond, kOpenStar, kOpenTriangleDown, kOpenDoubleDiamond, kOpenCrossX}
staticconstexprprivate

Definition at line 114 of file MSVtxPlotComparison.h.

◆ m_output_file

std::unique_ptr<TFile> MSVtxPlotComparison::m_output_file {nullptr}
private

Definition at line 96 of file MSVtxPlotComparison.h.

◆ m_plotdir

TString MSVtxPlotComparison::m_plotdir {}
private

Definition at line 88 of file MSVtxPlotComparison.h.

◆ m_plotdir_inputObjects

TString MSVtxPlotComparison::m_plotdir_inputObjects {}
private

Definition at line 93 of file MSVtxPlotComparison.h.

◆ m_plotdir_recoVtx

TString MSVtxPlotComparison::m_plotdir_recoVtx {}
private

Definition at line 90 of file MSVtxPlotComparison.h.

◆ m_plotdir_recoVtxHits

TString MSVtxPlotComparison::m_plotdir_recoVtxHits {}
private

Definition at line 91 of file MSVtxPlotComparison.h.

◆ m_plotdir_truthVtx

TString MSVtxPlotComparison::m_plotdir_truthVtx {}
private

Definition at line 89 of file MSVtxPlotComparison.h.

◆ m_plotdir_vtxEfficiency

TString MSVtxPlotComparison::m_plotdir_vtxEfficiency {}
private

Definition at line 94 of file MSVtxPlotComparison.h.

◆ m_plotdir_vtxFakeRate

TString MSVtxPlotComparison::m_plotdir_vtxFakeRate {}
private

Definition at line 95 of file MSVtxPlotComparison.h.

◆ m_plotdir_vtxResiduals

TString MSVtxPlotComparison::m_plotdir_vtxResiduals {}
private

Definition at line 92 of file MSVtxPlotComparison.h.


The documentation for this class was generated from the following files:
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
sTgcDigitEffiDump.efficiencies
list efficiencies
translate the station name indices into the string staiton name
Definition: sTgcDigitEffiDump.py:23
MSVtxPlotComparison::getNormalisedGraph
TGraphAsymmErrors * getNormalisedGraph(const TGraphAsymmErrors *graph)
Definition: MSVtxPlotComparison.cxx:496
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
MSVtxPlotComparison::isTEfficiency
Bool_t isTEfficiency(const TClass *objectClass)
Definition: MSVtxPlotComparison.cxx:461
MSVtxPlotComparison::ignorePlot
Bool_t ignorePlot(TKey *key)
Definition: MSVtxPlotComparison.cxx:467
MuonVertexValidationMacroPlotAnnotations::getMaxy
double getMaxy(const TGraphAsymmErrors *graph, double current_max)
Definition: PlotAnnotations.cxx:103
MSVtxPlotComparison::drawTMultigraph
void drawTMultigraph(std::unique_ptr< PlotInfo< TMultiGraph >> &mgInfo)
Definition: MSVtxPlotComparison.cxx:282
MSVtxPlotComparison::m_c
std::unique_ptr< TCanvas > m_c
Definition: MSVtxPlotComparison.h:97
MSVtxPlotComparison::makeTH1Comparison
void makeTH1Comparison(TKey *key)
Definition: MSVtxPlotComparison.cxx:84
MSVtxPlotComparison::drawTMultigraphPlot
void drawTMultigraphPlot(std::unique_ptr< PlotInfo< TMultiGraph >> &mgInfo)
Definition: MSVtxPlotComparison.cxx:294
python.SystemOfUnits.mg
int mg
Definition: SystemOfUnits.py:171
Data
@ Data
Definition: BaseObject.h:11
MSVtxPlotComparison::makeTEfficiencyComparison
void makeTEfficiencyComparison(TKey *key)
Definition: MSVtxPlotComparison.cxx:229
StateLessPT_NewConfig.Format
Format
Definition: StateLessPT_NewConfig.py:146
plotBeamSpotCompare.x2
x2
Definition: plotBeamSpotCompare.py:218
MSVtxPlotComparison::isTH1
Bool_t isTH1(const TClass *objectClass)
Definition: MSVtxPlotComparison.cxx:452
MSVtxPlotComparison::m_plotdir_inputObjects
TString m_plotdir_inputObjects
Definition: MSVtxPlotComparison.h:93
MuonVertexValidationMacroPlotAnnotations::drawATLASlabel
void drawATLASlabel(const char *text, double x, double y, double textsize)
Definition: PlotAnnotations.cxx:23
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
x
#define x
CaloSwCorrections.gap
def gap(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:212
MSVtxPlotComparison::m_plotdir_recoVtxHits
TString m_plotdir_recoVtxHits
Definition: MSVtxPlotComparison.h:91
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
beamspotnt.labels
list labels
Definition: bin/beamspotnt.py:1447
MSVtxPlotComparison::m_labels
std::vector< std::string > m_labels
Definition: MSVtxPlotComparison.h:86
MuonVertexValidationMacroPlotAnnotations::drawDetectorRegionLabel
void drawDetectorRegionLabel(const char *name, const char *customlabel, double x, double y, double textsize)
Definition: PlotAnnotations.cxx:35
MSVtxPlotComparison::m_markers
static constexpr std::array m_markers
Definition: MSVtxPlotComparison.h:114
lumiFormat.i
int i
Definition: lumiFormat.py:85
MSVtxPlotComparison::setPlotStyle
void setPlotStyle()
Definition: MSVtxPlotComparison.cxx:70
MSVtxPlotComparison::m_colors
const std::array< Int_t, 10 > m_colors
Definition: MSVtxPlotComparison.h:113
h
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
MSVtxPlotComparison::m_plotdir_vtxFakeRate
TString m_plotdir_vtxFakeRate
Definition: MSVtxPlotComparison.h:95
makeTRTBarrelCans.y2
tuple y2
Definition: makeTRTBarrelCans.py:18
MuonVertexValidationMacroPlotAnnotations::drawDetectorBoundaryLines
void drawDetectorBoundaryLines(const char *bin_var, double y_max)
Definition: PlotAnnotations.cxx:84
file
TFile * file
Definition: tile_monitor.h:29
MSVtxPlotComparison::drawTHStackRatioPlot
void drawTHStackRatioPlot(std::unique_ptr< PlotInfo< THStack >> &hstackInfo)
Definition: MSVtxPlotComparison.cxx:175
MSVtxPlotComparison::setup
void setup()
Definition: MSVtxPlotComparison.cxx:53
MSVtxPlotComparison::drawTHStackPlot
void drawTHStackPlot(std::unique_ptr< PlotInfo< THStack >> &hstackInfo)
Definition: MSVtxPlotComparison.cxx:142
MakeTH3DFromTH2Ds.hists
hists
Definition: MakeTH3DFromTH2Ds.py:72
MSVtxPlotComparison::m_plotdir_vtxResiduals
TString m_plotdir_vtxResiduals
Definition: MSVtxPlotComparison.h:92
MuonVertexValidationMacroPlotAnnotations::makeLegend
TLegend * makeLegend(double lower_x, double lower_y, double upper_x, double upper_y, double textsize)
Definition: PlotAnnotations.cxx:13
MSVtxPlotComparison::m_makeRatioPlots
bool m_makeRatioPlots
Definition: MSVtxPlotComparison.h:87
MSVtxPlotComparison::getTMultigraphPlotInfo
std::unique_ptr< MSVtxPlotComparison::PlotInfo< TMultiGraph > > getTMultigraphPlotInfo(TEfficiency *h)
Definition: MSVtxPlotComparison.cxx:242
MSVtxPlotComparison::m_output_file
std::unique_ptr< TFile > m_output_file
Definition: MSVtxPlotComparison.h:96
MSVtxPlotComparison::getPointIdx
Int_t getPointIdx(const TGraphAsymmErrors *graph, double x)
Definition: MSVtxPlotComparison.cxx:487
compute_lumi.denom
denom
Definition: compute_lumi.py:76
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
plotBeamSpotVxVal.legend
legend
Definition: plotBeamSpotVxVal.py:98
MSVtxPlotComparison::m_plotdir_recoVtx
TString m_plotdir_recoVtx
Definition: MSVtxPlotComparison.h:90
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MSVtxPlotComparison::getTHStackPlotInfo
std::unique_ptr< MSVtxPlotComparison::PlotInfo< THStack > > getTHStackPlotInfo(const TH1 *h)
Definition: MSVtxPlotComparison.cxx:97
MSVtxPlotComparison::m_plotdir
TString m_plotdir
Definition: MSVtxPlotComparison.h:88
MSVtxPlotComparison::m_plotdir_vtxEfficiency
TString m_plotdir_vtxEfficiency
Definition: MSVtxPlotComparison.h:94
MSVtxPlotComparison::drawTHStack
void drawTHStack(std::unique_ptr< PlotInfo< THStack >> &hstackInfo)
Definition: MSVtxPlotComparison.cxx:129
MSVtxPlotComparison::drawTMultigraphRatioPlot
void drawTMultigraphRatioPlot(std::unique_ptr< PlotInfo< TMultiGraph >> &mgInfo)
Definition: MSVtxPlotComparison.cxx:320
MSVtxPlotComparison::drawRatio
void drawRatio(TGraphAsymmErrors *ratio, TGraphAsymmErrors *denomErrNorm, const TString &xlabel, const TAxis *plotXaxis, const TAxis *plotYaxis, double axisRescaling)
Definition: MSVtxPlotComparison.cxx:403
MSVtxPlotComparison::m_plotdir_truthVtx
TString m_plotdir_truthVtx
Definition: MSVtxPlotComparison.h:89
python.compareTCTs.ratio
ratio
Definition: compareTCTs.py:295
MSVtxPlotComparison::getTMultigraphplotpath
const TString getTMultigraphplotpath(const TString &name)
Definition: MSVtxPlotComparison.cxx:359
MSVtxPlotComparison::getRatio
TGraphAsymmErrors * getRatio(const TH1 *num, const TH1 *denom)
Definition: MSVtxPlotComparison.cxx:372
MSVtxPlotComparison::makeSinglePad
void makeSinglePad()
Definition: MSVtxPlotComparison.cxx:477
MSVtxPlotComparison::getTHStackplotpath
const TString getTHStackplotpath(const TString &name)
Definition: MSVtxPlotComparison.cxx:213
python.PyAthena.obj
obj
Definition: PyAthena.py:132
MSVtxPlotComparison::m_datapaths
std::vector< std::string > m_datapaths
Definition: MSVtxPlotComparison.h:85
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37