ATLAS Offline Software
Loading...
Searching...
No Matches
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(std::move(xlabel)), ylabel(std::move(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{};
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
#define x
Header file for AthHistogramAlgorithm.
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)
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)
Bool_t isTH1(const TClass *objectClass)
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)
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)
std::vector< std::string > m_datapaths
STL namespace.
PlotInfo(std::unique_ptr< T > plot, TLegend *legend, double maxy, TString xlabel, const TString ylabel)