ATLAS Offline Software
MSVtxPlotComparison.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MSVTXPLOTCOMPARISON_H
6 #define MSVTXPLOTCOMPARISON_H
7 
8 #include <memory>
9 #include <vector>
10 #include <array>
11 #include <string>
12 #include <tuple>
13 
14 #include "TTree.h"
15 #include "TFile.h"
16 #include "TSystem.h"
17 
18 #include "TClass.h"
19 #include "TKey.h"
20 
21 #include "TROOT.h"
22 #include "TStyle.h"
23 
24 #include "TCanvas.h"
25 #include "TH1.h"
26 #include "THStack.h"
27 #include "TEfficiency.h"
28 #include "TGraphAsymmErrors.h"
29 #include "TMultiGraph.h"
30 #include "TAxis.h"
31 
32 #include "TString.h"
33 #include "TLegend.h"
34 #include "TColor.h"
35 
36 
38  public:
39  MSVtxPlotComparison(const std::vector<std::string> &datapaths, const std::vector<std::string> &labels, const std::string &pltdir);
41  void makeComparison();
42  private:
43  // struct to contain the plot and additional information about it
44  template <typename T>
45  struct PlotInfo {
46  std::unique_ptr<T> plot{nullptr};
47  TLegend* legend{nullptr};
48  double maxy{0.};
49  TString xlabel{};
50  const TString ylabel{};
51 
52  PlotInfo(std::unique_ptr<T> plot, TLegend* legend, double maxy, TString xlabel, const TString ylabel)
53  : plot(std::move(plot)), legend(legend), maxy(maxy), xlabel(xlabel), ylabel(ylabel) {};
54  };
55 
56  void setup();
57  void setPlotStyle();
58  // comparing TH1s
59  void makeTH1Comparison(TKey *key);
60  std::unique_ptr<MSVtxPlotComparison::PlotInfo<THStack>> getTHStackPlotInfo(const TH1* h);
61  void drawTHStack(std::unique_ptr<PlotInfo<THStack>> &hstackInfo);
62  void drawTHStackPlot(std::unique_ptr<PlotInfo<THStack>> &hstackInfo);
63  void drawTHStackRatioPlot(std::unique_ptr<PlotInfo<THStack>> &hstackInfo);
64  const TString getTHStackplotpath(const TString &name);
65  // comparing TEfficiencies
66  void makeTEfficiencyComparison(TKey *key);
67  std::unique_ptr<MSVtxPlotComparison::PlotInfo<TMultiGraph>> getTMultigraphPlotInfo(TEfficiency *h);
68  void drawTMultigraph(std::unique_ptr<PlotInfo<TMultiGraph>> &mgInfo);
69  void drawTMultigraphPlot(std::unique_ptr<PlotInfo<TMultiGraph>> &mgInfo);
70  void drawTMultigraphRatioPlot(std::unique_ptr<PlotInfo<TMultiGraph>> &mgInfo);
71  const TString getTMultigraphplotpath(const TString &name);
72  // ratio computation and drawing functions
73  TGraphAsymmErrors* getRatio(const TH1* num, const TH1* denom);
74  TGraphAsymmErrors* getRatio(const TGraphAsymmErrors* num, const TGraphAsymmErrors* denom);
75  void drawRatio(TGraphAsymmErrors* ratio, TGraphAsymmErrors* denomErrNorm, const TString &xlabel, const TAxis* plotXaxis, const TAxis* plotYaxis, double axisRescaling);
76  // helper functions
77  Bool_t ignorePlot(TKey *key);
78  Bool_t isTH1(const TClass *objectClass);
79  Bool_t isTEfficiency(const TClass *objectClass);
80  void makeSinglePad();
81  Int_t getPointIdx(const TGraphAsymmErrors* graph, double x);
82  TGraphAsymmErrors* getNormalisedGraph(const TGraphAsymmErrors* graph);
83 
84  // input/output variables
85  std::vector<std::string> m_datapaths{};
86  std::vector<std::string> m_labels{};
87  bool m_makeRatioPlots{}; // flag showing if ratio plots are made
88  TString m_plotdir{};
89  TString m_plotdir_truthVtx{};
90  TString m_plotdir_recoVtx{};
96  std::unique_ptr<TFile> m_output_file{nullptr};
97  std::unique_ptr<TCanvas> m_c{nullptr};
98 
99  // custom color and marker cycle
100  // Accessible Color Schemes not available in ROOT v6.32.
101  // Once it is, can remove this and make m_colors static constexpr and removing leading "m_" from elements
102  const Int_t m_kP10Blue = TColor::GetColor("#3f90da");
103  const Int_t m_kP10Yellow = TColor::GetColor("#ffa90e");
104  const Int_t m_kP10Red = TColor::GetColor("#bd1f01");
105  const Int_t m_kP10Grey = TColor::GetColor("#832db6");
106  const Int_t m_kP10Violet = TColor::GetColor("#a96b59");
107  const Int_t m_kP10Brown = TColor::GetColor("#94a4a2");
108  const Int_t m_kP10Orange = TColor::GetColor("#e76300");
109  const Int_t m_kP10Green = TColor::GetColor("#b9ac70");
110  const Int_t m_kP10Ash = TColor::GetColor("#717581");
111  const Int_t m_kP10Cyan = TColor::GetColor("#92dadd");
112 
114  static constexpr std::array m_markers{kOpenCircle, kOpenSquare, kOpenTriangleUp, kOpenDiamond, kOpenStar, kOpenTriangleDown, kOpenDoubleDiamond, kOpenCrossX};
115 };
116 
117 #endif // MSVTXPLOTCOMPARISON_H
MSVtxPlotComparison::getNormalisedGraph
TGraphAsymmErrors * getNormalisedGraph(const TGraphAsymmErrors *graph)
Definition: MSVtxPlotComparison.cxx:496
MSVtxPlotComparison::isTEfficiency
Bool_t isTEfficiency(const TClass *objectClass)
Definition: MSVtxPlotComparison.cxx:461
MSVtxPlotComparison::ignorePlot
Bool_t ignorePlot(TKey *key)
Definition: MSVtxPlotComparison.cxx:467
MSVtxPlotComparison::PlotInfo::xlabel
TString xlabel
Definition: MSVtxPlotComparison.h:49
MSVtxPlotComparison::m_kP10Green
const Int_t m_kP10Green
Definition: MSVtxPlotComparison.h:109
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
MSVtxPlotComparison::makeTEfficiencyComparison
void makeTEfficiencyComparison(TKey *key)
Definition: MSVtxPlotComparison.cxx:229
MSVtxPlotComparison::m_kP10Cyan
const Int_t m_kP10Cyan
Definition: MSVtxPlotComparison.h:111
MSVtxPlotComparison::isTH1
Bool_t isTH1(const TClass *objectClass)
Definition: MSVtxPlotComparison.cxx:452
MSVtxPlotComparison::m_kP10Red
const Int_t m_kP10Red
Definition: MSVtxPlotComparison.h:104
MSVtxPlotComparison::m_plotdir_inputObjects
TString m_plotdir_inputObjects
Definition: MSVtxPlotComparison.h:93
plot
Definition: PhysicsAnalysis/ElectronPhotonID/ElectronPhotonFourMomentumCorrection/python/plot.py:1
MSVtxPlotComparison::~MSVtxPlotComparison
virtual ~MSVtxPlotComparison()
x
#define x
MSVtxPlotComparison::PlotInfo::legend
TLegend * legend
Definition: MSVtxPlotComparison.h:47
MSVtxPlotComparison::m_kP10Grey
const Int_t m_kP10Grey
Definition: MSVtxPlotComparison.h:105
MSVtxPlotComparison::m_plotdir_recoVtxHits
TString m_plotdir_recoVtxHits
Definition: MSVtxPlotComparison.h:91
MSVtxPlotComparison
Definition: MSVtxPlotComparison.h:37
MSVtxPlotComparison::m_kP10Ash
const Int_t m_kP10Ash
Definition: MSVtxPlotComparison.h:110
beamspotnt.labels
list labels
Definition: bin/beamspotnt.py:1447
MSVtxPlotComparison::m_labels
std::vector< std::string > m_labels
Definition: MSVtxPlotComparison.h:86
MSVtxPlotComparison::m_kP10Brown
const Int_t m_kP10Brown
Definition: MSVtxPlotComparison.h:107
MSVtxPlotComparison::m_markers
static constexpr std::array m_markers
Definition: MSVtxPlotComparison.h:114
MSVtxPlotComparison::MSVtxPlotComparison
MSVtxPlotComparison(const std::vector< std::string > &datapaths, const std::vector< std::string > &labels, const std::string &pltdir)
Definition: MSVtxPlotComparison.cxx:10
MSVtxPlotComparison::setPlotStyle
void setPlotStyle()
Definition: MSVtxPlotComparison.cxx:70
MSVtxPlotComparison::m_colors
const std::array< Int_t, 10 > m_colors
Definition: MSVtxPlotComparison.h:113
MSVtxPlotComparison::m_plotdir_vtxFakeRate
TString m_plotdir_vtxFakeRate
Definition: MSVtxPlotComparison.h:95
MSVtxPlotComparison::makeComparison
void makeComparison()
Definition: MSVtxPlotComparison.cxx:26
MSVtxPlotComparison::drawTHStackRatioPlot
void drawTHStackRatioPlot(std::unique_ptr< PlotInfo< THStack >> &hstackInfo)
Definition: MSVtxPlotComparison.cxx:175
MSVtxPlotComparison::m_kP10Orange
const Int_t m_kP10Orange
Definition: MSVtxPlotComparison.h:108
MSVtxPlotComparison::setup
void setup()
Definition: MSVtxPlotComparison.cxx:53
MSVtxPlotComparison::drawTHStackPlot
void drawTHStackPlot(std::unique_ptr< PlotInfo< THStack >> &hstackInfo)
Definition: MSVtxPlotComparison.cxx:142
MSVtxPlotComparison::m_plotdir_vtxResiduals
TString m_plotdir_vtxResiduals
Definition: MSVtxPlotComparison.h:92
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
MSVtxPlotComparison::m_kP10Blue
const Int_t m_kP10Blue
Definition: MSVtxPlotComparison.h:102
compute_lumi.denom
denom
Definition: compute_lumi.py:76
lumiFormat.array
array
Definition: lumiFormat.py:91
trigbs_pickEvents.num
num
Definition: trigbs_pickEvents.py:76
MSVtxPlotComparison::PlotInfo
Definition: MSVtxPlotComparison.h:45
MSVtxPlotComparison::m_plotdir_recoVtx
TString m_plotdir_recoVtx
Definition: MSVtxPlotComparison.h:90
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MSVtxPlotComparison::m_kP10Violet
const Int_t m_kP10Violet
Definition: MSVtxPlotComparison.h:106
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::PlotInfo::maxy
double maxy
Definition: MSVtxPlotComparison.h:48
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
h
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::PlotInfo::PlotInfo
PlotInfo(std::unique_ptr< T > plot, TLegend *legend, double maxy, TString xlabel, const TString ylabel)
Definition: MSVtxPlotComparison.h:52
MSVtxPlotComparison::makeSinglePad
void makeSinglePad()
Definition: MSVtxPlotComparison.cxx:477
MSVtxPlotComparison::PlotInfo::ylabel
const TString ylabel
Definition: MSVtxPlotComparison.h:50
MSVtxPlotComparison::m_kP10Yellow
const Int_t m_kP10Yellow
Definition: MSVtxPlotComparison.h:103
MSVtxPlotComparison::getTHStackplotpath
const TString getTHStackplotpath(const TString &name)
Definition: MSVtxPlotComparison.cxx:213
MSVtxPlotComparison::m_datapaths
std::vector< std::string > m_datapaths
Definition: MSVtxPlotComparison.h:85
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37