ATLAS Offline Software
HistHandler.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #ifndef MUONEFFICIENCYCORRECTIONS_HISTOHANDLER_H
6 #define MUONEFFICIENCYCORRECTIONS_HISTOHANDLER_H
7 
8 // EDM include(s):
9 #include "xAODMuon/Muon.h"
10 
11 // supported SF histogram types
12 #include <TH1D.h>
13 #include <TH2D.h>
14 #include <TH3D.h>
15 #include <TH2Poly.h>
16 
19 // further ROOT includes
20 #include <TFile.h>
21 #include <TDirectory.h>
22 
23 // STL includes
24 #include <string>
25 #include <iostream>
26 #include <exception>
27 #include <map>
28 #include <memory>
29 #include <cmath>
30 
31 namespace CP {
32 
34  class AxisHandler;
35 
36 
37  class HistHandler {
44  public:
45 
46  inline double GetBinContent(int bin) const{
47  if (!m_H) return DBL_MAX;
48  return m_H->GetBinContent(bin);
49  }
50 
51  void SetBinContent(int bin, float val);
52 
53  inline double GetBinError(int bin) const{
54  if (!m_H) return DBL_MAX;
55  return m_H->GetBinError(bin);
56  }
57 
58  inline TH1* GetHist() const{
59  return m_H.get();
60  }
61 
62  void SetBinError(int bin, float val);
63 
65  virtual CorrectionCode FindBin(const xAOD::Muon & muon, int & bin) const = 0;
67  virtual int nBins() const = 0;
69  virtual int nOverFlowBins() const = 0;
71  virtual bool isOverFlowBin(int b) const =0;
73  virtual std::string GetBinName(unsigned int bin) const=0;
74 
75  virtual ~HistHandler();
76  protected:
77  HistHandler(TH1* Hist);
78  HistHandler(const HistHandler & other);
79  void Copy(const HistHandler & other);
80  private:
81  std::unique_ptr<TH1> m_H;
82 
83  };
84 
85 
86 
87  class HistHandler_TH1: public HistHandler {
88 
89  public:
90 
94  virtual ~HistHandler_TH1();
95 
96  int nBins() const override;
97 
98  int nOverFlowBins() const override;
99  bool isOverFlowBin(int b) const override;
100 
101 
102  std::string GetBinName(unsigned int bin) const override;
103  CorrectionCode FindBin(const xAOD::Muon & muon, int & bin) const override;
104  private:
105  std::unique_ptr<AxisHandler> m_x_handler;
106  };
107 
108  class HistHandler_TH2: public HistHandler {
109 
110  public:
117  virtual HistHandler_TH2 & operator =(const HistHandler_TH2 & other);
118  virtual ~HistHandler_TH2();
119 
120  int nBins() const override;
121 
122  int nOverFlowBins() const override;
123  bool isOverFlowBin(int b) const override;
124 
125  std::string GetBinName(unsigned int bin) const override;
126 
127  CorrectionCode FindBin(const xAOD::Muon & muon, int & bin) const override;
128  private:
129  std::unique_ptr<AxisHandler> m_x_handler;
130  std::unique_ptr<AxisHandler> m_y_handler;
131  };
132 
133  class HistHandler_TH3: public HistHandler {
134 
135  public:
139 
142  virtual HistHandler_TH3 & operator =(const HistHandler_TH3 & other);
143  virtual ~HistHandler_TH3();
144 
145  int nBins() const override;
146 
147  int nOverFlowBins() const override;
148  bool isOverFlowBin(int b) const override;
149 
150 
151  std::string GetBinName(unsigned int bin) const override;
152 
153  CorrectionCode FindBin(const xAOD::Muon & muon, int & bin) const override;
154 
155  private:
156  std::unique_ptr<AxisHandler> m_x_handler;
157  std::unique_ptr<AxisHandler> m_y_handler;
158  std::unique_ptr<AxisHandler> m_z_handler;
159  };
160 
162 
163  public:
167  HistHandler_TH2Poly(TH2Poly* hist);
170  virtual ~HistHandler_TH2Poly();
171 
172  int nOverFlowBins() const override;
173  bool isOverFlowBin(int b) const override;
174 
175  int nBins() const override;
176  std::string GetBinName(unsigned int bin) const override;
177  CorrectionCode FindBin(const xAOD::Muon & muon, int & bin) const override;
178 
179  private:
180  TH2Poly* m_h;
181  std::unique_ptr<AxisHandler> m_x_handler;
182  std::unique_ptr<AxisHandler> m_y_handler;
183  };
184 
185  class AxisHandler {
186  public:
187  virtual CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) const =0;
188  virtual ~AxisHandler()= default;
189  };
191  public:
192  static std::unique_ptr<AxisHandler> GetAxisHandler(const TAxis* axis);
193  };
194 
195  class PtAxisHandler: public AxisHandler {
196  public:
197  CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) const override;
198  virtual ~PtAxisHandler() = default;
199  };
200 
202  public:
203  CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) const override;
204  virtual ~ChargeAxisHandler() = default;
205  };
206 
207  class EtaAxisHandler: public AxisHandler {
208  public:
209  CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) const override;
210  virtual ~EtaAxisHandler() = default;
211  };
213  public:
214  CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) const override;
215  virtual ~AbsEtaAxisHandler() = default;
216  };
217  class PhiAxisHandler: public AxisHandler {
218  public:
219  CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) const override;
220  virtual ~PhiAxisHandler() = default;
221  };
223  public:
225 
226  CorrectionCode GetBinningParameter(const xAOD::Muon & mu, float & value) const override;
227  virtual ~dRJetAxisHandler() = default;
228 
229  //this method must be called only before any object creation, since it sets the static variable s_close_jet_decor, that is used only to initialize the m_acc member variable, and for nothing else; using it after object creation will not change the behaviour of the class
230  static void set_close_jet_decorator(const std::string& decor_name);
231  //this method must be called only before any object creation, since it sets the static variable s_use_2D_sf, that is used only to initialize the m_use_2D_sf member variable, and for nothing else; using it after object creation will not change the behaviour of the class
232  static void set_use_2D_sf(const bool);
233 
234  private:
235  //this static variable is safe because it is only used during object creation (to set the value of m_acc) and avoiding it would require a significant rewrite
236  static std::string s_close_jet_decor ATLAS_THREAD_SAFE;
237  //this static variable is safe because it is only used during object creation (to set the value of m_use_2D_sf) and avoiding it would require a significant rewrite
238  static bool s_use_2D_sf ATLAS_THREAD_SAFE;
239 
242  };
244  public:
245  CorrectionCode GetBinningParameter(const xAOD::Muon &, float &) const override;
246  virtual ~UndefinedAxisHandler() = default;
247  };
248 
249 } // namespace CP
250 #endif
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
CP::HistHandler_TH3::nBins
int nBins() const override
Return the total number of bins in the histogram -> (GetNbins() +2)**n.
Definition: HistHandler.cxx:289
CP::AxisHandlerProvider
Definition: HistHandler.h:190
CP::HistHandler::Copy
void Copy(const HistHandler &other)
Definition: HistHandler.cxx:126
CP::HistHandler_TH3::FindBin
CorrectionCode FindBin(const xAOD::Muon &muon, int &bin) const override
Function that changes from Implementation to implementation.
Definition: HistHandler.cxx:302
CP::HistHandler_TH2::nBins
int nBins() const override
Return the total number of bins in the histogram -> (GetNbins() +2)**n.
Definition: HistHandler.cxx:206
CP::HistHandler::SetBinError
void SetBinError(int bin, float val)
Definition: HistHandler.cxx:145
CP::HistHandler_TH1::HistHandler_TH1
HistHandler_TH1(TH1 *hist)
Definition: HistHandler.cxx:153
CP::HistHandler_TH2::isOverFlowBin
bool isOverFlowBin(int b) const override
States whether a bin is overflow or not.
Definition: HistHandler.cxx:210
CP::HistHandler_TH3::GetBinName
std::string GetBinName(unsigned int bin) const override
Translates the bin number into the borders and return them as name.
Definition: HistHandler.cxx:322
CP::PhiAxisHandler::~PhiAxisHandler
virtual ~PhiAxisHandler()=default
CP::HistHandler_TH1::m_x_handler
std::unique_ptr< AxisHandler > m_x_handler
Definition: HistHandler.h:105
CP::HistHandler_TH1::FindBin
CorrectionCode FindBin(const xAOD::Muon &muon, int &bin) const override
Function that changes from Implementation to implementation.
Definition: HistHandler.cxx:180
CP::PhiAxisHandler
Definition: HistHandler.h:217
Muon.h
CP::HistHandler_TH1::isOverFlowBin
bool isOverFlowBin(int b) const override
States whether a bin is overflow or not.
Definition: HistHandler.cxx:175
plotmaker.hist
hist
Definition: plotmaker.py:148
CP::AxisHandler::~AxisHandler
virtual ~AxisHandler()=default
CP::HistHandler_TH2Poly::m_h
TH2Poly * m_h
Definition: HistHandler.h:180
yodamerge_tmp.axis
list axis
Definition: yodamerge_tmp.py:241
CP::HistHandler::GetBinName
virtual std::string GetBinName(unsigned int bin) const =0
Translates the bin number into the borders and return them as name.
CP::HistHandler_TH2::FindBin
CorrectionCode FindBin(const xAOD::Muon &muon, int &bin) const override
Function that changes from Implementation to implementation.
Definition: HistHandler.cxx:215
CP::HistHandler_TH2::nOverFlowBins
int nOverFlowBins() const override
Return the number of overflow bins.
Definition: HistHandler.cxx:209
CP::HistHandler_TH2Poly::~HistHandler_TH2Poly
virtual ~HistHandler_TH2Poly()
Definition: HistHandler.cxx:368
bin
Definition: BinsDiffFromStripMedian.h:43
CP::HistHandler_TH3::isOverFlowBin
bool isOverFlowBin(int b) const override
States whether a bin is overflow or not.
Definition: HistHandler.cxx:295
CP::HistHandler_TH2Poly::nOverFlowBins
int nOverFlowBins() const override
Return the number of overflow bins.
Definition: HistHandler.cxx:374
athena.value
value
Definition: athena.py:122
CP::HistHandler_TH3::HistHandler_TH3
HistHandler_TH3(TH1 *hist)
The HistHandler TH3 handles 3D histograms, since TH3 inhertis from TH1,a TH1* object is parsed avoidi...
Definition: HistHandler.cxx:263
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:54
CP::HistHandler_TH2::~HistHandler_TH2
virtual ~HistHandler_TH2()
Definition: HistHandler.cxx:241
CP::HistHandler_TH1::operator=
virtual HistHandler_TH1 & operator=(const HistHandler_TH1 &other)
Definition: HistHandler.cxx:163
CP::HistHandler::GetBinContent
double GetBinContent(int bin) const
Definition: HistHandler.h:46
CP::PtAxisHandler
Definition: HistHandler.h:195
CP::ChargeAxisHandler
Definition: HistHandler.h:201
CP::AbsEtaAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(const xAOD::Muon &mu, float &value) const override
Definition: HistHandler.cxx:61
CP::HistHandler_TH1
Definition: HistHandler.h:87
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:48
CP::HistHandler_TH3::m_y_handler
std::unique_ptr< AxisHandler > m_y_handler
Definition: HistHandler.h:157
CP::EtaAxisHandler
Definition: HistHandler.h:207
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
CP::HistHandler::HistHandler
HistHandler(TH1 *Hist)
Definition: HistHandler.cxx:122
CP::AbsEtaAxisHandler
Definition: HistHandler.h:212
CP::dRJetAxisHandler::ATLAS_THREAD_SAFE
static bool s_use_2D_sf ATLAS_THREAD_SAFE
Definition: HistHandler.h:238
CP::HistHandler_TH2::operator=
virtual HistHandler_TH2 & operator=(const HistHandler_TH2 &other)
Definition: HistHandler.cxx:232
CP::HistHandler::isOverFlowBin
virtual bool isOverFlowBin(int b) const =0
States whether a bin is overflow or not.
CP::EtaAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(const xAOD::Muon &mu, float &value) const override
Definition: HistHandler.cxx:57
CP::HistHandler_TH2Poly::isOverFlowBin
bool isOverFlowBin(int b) const override
States whether a bin is overflow or not.
Definition: HistHandler.cxx:375
CP::HistHandler_TH1::nOverFlowBins
int nOverFlowBins() const override
Return the number of overflow bins.
Definition: HistHandler.cxx:174
CP::HistHandler::nOverFlowBins
virtual int nOverFlowBins() const =0
Return the number of overflow bins.
CP::HistHandler_TH3::nOverFlowBins
int nOverFlowBins() const override
Return the number of overflow bins.
Definition: HistHandler.cxx:292
CP::HistHandler_TH2Poly::GetBinName
std::string GetBinName(unsigned int bin) const override
Translates the bin number into the borders and return them as name.
Definition: HistHandler.cxx:391
CP::HistHandler::GetHist
TH1 * GetHist() const
Definition: HistHandler.h:58
CP::dRJetAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(const xAOD::Muon &mu, float &value) const override
Definition: HistHandler.cxx:84
CP::AbsEtaAxisHandler::~AbsEtaAxisHandler
virtual ~AbsEtaAxisHandler()=default
CP::HistHandler_TH3::m_z_handler
std::unique_ptr< AxisHandler > m_z_handler
Definition: HistHandler.h:158
CP::HistHandler_TH3
Definition: HistHandler.h:133
CP::ChargeAxisHandler::~ChargeAxisHandler
virtual ~ChargeAxisHandler()=default
CP::HistHandler_TH2Poly::m_y_handler
std::unique_ptr< AxisHandler > m_y_handler
Definition: HistHandler.h:182
CP::HistHandler::SetBinContent
void SetBinContent(int bin, float val)
Definition: HistHandler.cxx:140
CP::HistHandler_TH2Poly::FindBin
CorrectionCode FindBin(const xAOD::Muon &muon, int &bin) const override
Function that changes from Implementation to implementation.
Definition: HistHandler.cxx:377
CP::HistHandler_TH2Poly
Definition: HistHandler.h:161
CP::HistHandler
Definition: HistHandler.h:37
CP::dRJetAxisHandler
Definition: HistHandler.h:222
CP::AxisHandler
Definition: HistHandler.h:185
CP::HistHandler_TH2
Definition: HistHandler.h:108
CP::PhiAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(const xAOD::Muon &mu, float &value) const override
Definition: HistHandler.cxx:65
CP::dRJetAxisHandler::m_use_2D_sf
bool m_use_2D_sf
Definition: HistHandler.h:241
CP::HistHandler_TH2::m_x_handler
std::unique_ptr< AxisHandler > m_x_handler
Definition: HistHandler.h:129
CP::dRJetAxisHandler::set_use_2D_sf
static void set_use_2D_sf(const bool)
Definition: HistHandler.cxx:73
CP::HistHandler_TH2::GetBinName
std::string GetBinName(unsigned int bin) const override
Translates the bin number into the borders and return them as name.
Definition: HistHandler.cxx:248
CP::HistHandler_TH3::operator=
virtual HistHandler_TH3 & operator=(const HistHandler_TH3 &other)
Definition: HistHandler.cxx:279
CP::dRJetAxisHandler::m_acc
SG::AuxElement::ConstAccessor< float > m_acc
Definition: HistHandler.h:240
CP::PtAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(const xAOD::Muon &mu, float &value) const override
Definition: HistHandler.cxx:49
CP::dRJetAxisHandler::~dRJetAxisHandler
virtual ~dRJetAxisHandler()=default
CP::dRJetAxisHandler::ATLAS_THREAD_SAFE
static std::string s_close_jet_decor ATLAS_THREAD_SAFE
Definition: HistHandler.h:236
CP::HistHandler_TH2Poly::nBins
int nBins() const override
Return the total number of bins in the histogram -> (GetNbins() +2)**n.
Definition: HistHandler.cxx:370
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CP::HistHandler_TH1::nBins
int nBins() const override
Return the total number of bins in the histogram -> (GetNbins() +2)**n.
Definition: HistHandler.cxx:173
CP::EtaAxisHandler::~EtaAxisHandler
virtual ~EtaAxisHandler()=default
CP::HistHandler::FindBin
virtual CorrectionCode FindBin(const xAOD::Muon &muon, int &bin) const =0
Function that changes from Implementation to implementation.
CP::HistHandler_TH1::~HistHandler_TH1
virtual ~HistHandler_TH1()
Definition: HistHandler.cxx:171
CP::AxisHandler::GetBinningParameter
virtual CorrectionCode GetBinningParameter(const xAOD::Muon &mu, float &value) const =0
CP::ChargeAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(const xAOD::Muon &mu, float &value) const override
Definition: HistHandler.cxx:53
CP::dRJetAxisHandler::dRJetAxisHandler
dRJetAxisHandler()
Definition: HistHandler.cxx:80
CP::HistHandler_TH1::GetBinName
std::string GetBinName(unsigned int bin) const override
Translates the bin number into the borders and return them as name.
Definition: HistHandler.cxx:176
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CP::HistHandler_TH2Poly::m_x_handler
std::unique_ptr< AxisHandler > m_x_handler
Definition: HistHandler.h:181
CP::dRJetAxisHandler::set_close_jet_decorator
static void set_close_jet_decorator(const std::string &decor_name)
Definition: HistHandler.cxx:69
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
CP::PtAxisHandler::~PtAxisHandler
virtual ~PtAxisHandler()=default
TH1
Definition: rootspy.cxx:268
CP::AxisHandlerProvider::GetAxisHandler
static std::unique_ptr< AxisHandler > GetAxisHandler(const TAxis *axis)
Definition: HistHandler.cxx:20
CP::HistHandler_TH3::m_x_handler
std::unique_ptr< AxisHandler > m_x_handler
Definition: HistHandler.h:156
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
CP::HistHandler_TH2::m_y_handler
std::unique_ptr< AxisHandler > m_y_handler
Definition: HistHandler.h:130
CP::HistHandler::~HistHandler
virtual ~HistHandler()
Definition: HistHandler.cxx:138
CorrectionCode.h
CP::HistHandler_TH2Poly::HistHandler_TH2Poly
HistHandler_TH2Poly(TH2Poly *hist)
The HistHandler_TH2Poly handles the TH2Poly histograms of the scale-factor maps.
Definition: HistHandler.cxx:341
CP::UndefinedAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(const xAOD::Muon &, float &) const override
Definition: HistHandler.cxx:116
CP::UndefinedAxisHandler
Definition: HistHandler.h:243
CP::UndefinedAxisHandler::~UndefinedAxisHandler
virtual ~UndefinedAxisHandler()=default
checker_macros.h
Define macros for attributes used to control the static checker.
CP::HistHandler::nBins
virtual int nBins() const =0
Return the total number of bins in the histogram -> (GetNbins() +2)**n.
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
CP::HistHandler_TH2Poly::operator=
virtual HistHandler_TH2Poly & operator=(const HistHandler_TH2Poly &other)
Definition: HistHandler.cxx:357
CP::HistHandler_TH2::HistHandler_TH2
HistHandler_TH2(TH1 *hist)
The HistHandler TH2 handles 2D histograms which are not TH2Poly, since TH2 inhertis from TH1,...
Definition: HistHandler.cxx:200
CP::HistHandler::m_H
std::unique_ptr< TH1 > m_H
Definition: HistHandler.h:81
CP::HistHandler_TH3::~HistHandler_TH3
virtual ~HistHandler_TH3()
Definition: HistHandler.cxx:277
CP::HistHandler::GetBinError
double GetBinError(int bin) const
Definition: HistHandler.h:53