Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
25 #include <ColumnarMuon/MuonDef.h>
27 
28 // STL includes
29 #include <string>
30 #include <iostream>
31 #include <exception>
32 #include <map>
33 #include <memory>
34 #include <cmath>
35 
36 namespace CP {
37 
39  class AxisHandler;
40 
41 
42  class HistHandler {
49  public:
50 
51  inline double GetBinContent(int bin) const{
52  if (!m_H) return DBL_MAX;
53  return m_H->GetBinContent(bin);
54  }
55 
56  void SetBinContent(int bin, float val);
57 
58  inline double GetBinError(int bin) const{
59  if (!m_H) return DBL_MAX;
60  return m_H->GetBinError(bin);
61  }
62 
63  inline TH1* GetHist() const{
64  return m_H.get();
65  }
66 
67  void SetBinError(int bin, float val);
68 
70  virtual CorrectionCode FindBin(columnar::MuonId muon, int & bin) const = 0;
72  virtual int nBins() const = 0;
74  virtual int nOverFlowBins() const = 0;
76  virtual bool isOverFlowBin(int b) const =0;
78  virtual std::string GetBinName(unsigned int bin) const=0;
79 
80  virtual ~HistHandler();
81  protected:
83  HistHandler(const HistHandler & other) = delete;
85  private:
86  std::unique_ptr<TH1> m_H;
87 
88  };
89 
90 
91 
92  class HistHandler_TH1: public HistHandler {
93 
94  public:
95 
97  virtual ~HistHandler_TH1();
98 
99  int nBins() const override;
100 
101  int nOverFlowBins() const override;
102  bool isOverFlowBin(int b) const override;
103 
104 
105  std::string GetBinName(unsigned int bin) const override;
106  CorrectionCode FindBin(columnar::MuonId muon, int & bin) const override;
107 
108  private:
109  std::unique_ptr<AxisHandler> m_x_handler;
110  };
111 
112  class HistHandler_TH2: public HistHandler {
113 
114  public:
120  virtual ~HistHandler_TH2();
121 
122  int nBins() const override;
123 
124  int nOverFlowBins() const override;
125  bool isOverFlowBin(int b) const override;
126 
127  std::string GetBinName(unsigned int bin) const override;
128 
129  CorrectionCode FindBin(columnar::MuonId muon, int & bin) const override;
130 
131  private:
132  std::unique_ptr<AxisHandler> m_x_handler;
133  std::unique_ptr<AxisHandler> m_y_handler;
134  };
135 
136  class HistHandler_TH3: public HistHandler {
137 
138  public:
142 
144  virtual ~HistHandler_TH3();
145 
146  int nBins() const override;
147 
148  int nOverFlowBins() const override;
149  bool isOverFlowBin(int b) const override;
150 
151 
152  std::string GetBinName(unsigned int bin) const override;
153 
154  CorrectionCode FindBin(columnar::MuonId muon, int & bin) const override;
155 
156  private:
157  std::unique_ptr<AxisHandler> m_x_handler;
158  std::unique_ptr<AxisHandler> m_y_handler;
159  std::unique_ptr<AxisHandler> m_z_handler;
160  };
161 
163 
164  public:
169  virtual ~HistHandler_TH2Poly();
170 
171  int nOverFlowBins() const override;
172  bool isOverFlowBin(int b) const override;
173 
174  int nBins() const override;
175  std::string GetBinName(unsigned int bin) const override;
176  CorrectionCode FindBin(columnar::MuonId muon, int & bin) const override;
177 
178  private:
179  TH2Poly* m_h;
180  std::unique_ptr<AxisHandler> m_x_handler;
181  std::unique_ptr<AxisHandler> m_y_handler;
182  };
183 
185  public:
188  virtual ~AxisHandler()= default;
189  };
191  public:
192  static std::unique_ptr<AxisHandler> GetAxisHandler(columnar::ColumnarTool<> * parent, const TAxis* axis);
193  };
194 
195  class PtAxisHandler: public AxisHandler {
196  public:
199  virtual ~PtAxisHandler() = default;
201  };
202 
204  public:
207  virtual ~ChargeAxisHandler() = default;
209  };
210 
211  class EtaAxisHandler: public AxisHandler {
212  public:
215  virtual ~EtaAxisHandler() = default;
217  };
219  public:
220  CorrectionCode GetBinningParameter(columnar::MuonId mu, float & value) const override;
222  virtual ~AbsEtaAxisHandler() = default;
224  };
225  class PhiAxisHandler: public AxisHandler {
226  public:
229  virtual ~PhiAxisHandler() = default;
231  };
233  public:
235 
237  virtual ~dRJetAxisHandler() = default;
238 
239  //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
240  static void set_close_jet_decorator(const std::string& decor_name);
241  //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
242  static void set_use_2D_sf(const bool);
243 
244  private:
245  //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
246  static std::string s_close_jet_decor ATLAS_THREAD_SAFE;
247  //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
248  static bool s_use_2D_sf ATLAS_THREAD_SAFE;
249 
251 
252  public:
254  columnar::MuonAccessor<float> acc_dR_deriv {*this, "DFCommonJetDr"};
255  };
257  public:
258  CorrectionCode GetBinningParameter(columnar::MuonId, float &) const override;
260  virtual ~UndefinedAxisHandler() = default;
261  };
262 
263 } // namespace CP
264 #endif
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:196
CP::HistHandler_TH3::nBins
int nBins() const override
Return the total number of bins in the histogram -> (GetNbins() +2)**n.
Definition: HistHandler.cxx:245
CP::AxisHandlerProvider
Definition: HistHandler.h:190
CP::UndefinedAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(columnar::MuonId, float &) const override
Definition: HistHandler.cxx:116
CP::HistHandler_TH2::nBins
int nBins() const override
Return the total number of bins in the histogram -> (GetNbins() +2)**n.
Definition: HistHandler.cxx:193
CP::HistHandler::SetBinError
void SetBinError(int bin, float val)
Definition: HistHandler.cxx:145
CP::HistHandler_TH2::isOverFlowBin
bool isOverFlowBin(int b) const override
States whether a bin is overflow or not.
Definition: HistHandler.cxx:197
CP::UndefinedAxisHandler::UndefinedAxisHandler
UndefinedAxisHandler(columnar::ColumnarTool<> *parent)
Definition: HistHandler.h:259
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:278
CP::PhiAxisHandler::~PhiAxisHandler
virtual ~PhiAxisHandler()=default
CP::HistHandler_TH1::m_x_handler
std::unique_ptr< AxisHandler > m_x_handler
Definition: HistHandler.h:109
CP::PhiAxisHandler
Definition: HistHandler.h:225
Muon.h
CP::HistHandler_TH1::isOverFlowBin
bool isOverFlowBin(int b) const override
States whether a bin is overflow or not.
Definition: HistHandler.cxx:162
plotmaker.hist
hist
Definition: plotmaker.py:148
CP::HistHandler::HistHandler
HistHandler(columnar::ColumnarTool<> *parent, TH1 *Hist)
Definition: HistHandler.cxx:122
CP::AxisHandler::~AxisHandler
virtual ~AxisHandler()=default
CP::HistHandler_TH2Poly::m_h
TH2Poly * m_h
Definition: HistHandler.h:179
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::EtaAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(columnar::MuonId mu, float &value) const override
Definition: HistHandler.cxx:57
CP::HistHandler_TH2::nOverFlowBins
int nOverFlowBins() const override
Return the number of overflow bins.
Definition: HistHandler.cxx:196
CP::HistHandler_TH2Poly::~HistHandler_TH2Poly
virtual ~HistHandler_TH2Poly()
Definition: HistHandler.cxx:305
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:251
CP::HistHandler_TH2Poly::FindBin
CorrectionCode FindBin(columnar::MuonId muon, int &bin) const override
Function that changes from Implementation to implementation.
Definition: HistHandler.cxx:314
CP::HistHandler_TH3::FindBin
CorrectionCode FindBin(columnar::MuonId muon, int &bin) const override
Function that changes from Implementation to implementation.
Definition: HistHandler.cxx:258
CP::HistHandler_TH2Poly::nOverFlowBins
int nOverFlowBins() const override
Return the number of overflow bins.
Definition: HistHandler.cxx:311
athena.value
value
Definition: athena.py:124
CP::HistHandler::FindBin
virtual CorrectionCode FindBin(columnar::MuonId muon, int &bin) const =0
Function that changes from Implementation to implementation.
CP::HistHandler_TH3::HistHandler_TH3
HistHandler_TH3(columnar::ColumnarTool<> *parent, TH1 *hist)
The HistHandler TH3 handles 3D histograms, since TH3 inhertis from TH1,a TH1* object is parsed avoidi...
Definition: HistHandler.cxx:236
CP::HistHandler::HistHandler
HistHandler(const HistHandler &other)=delete
CP::HistHandler_TH2::~HistHandler_TH2
virtual ~HistHandler_TH2()
Definition: HistHandler.cxx:219
CP::AbsEtaAxisHandler::AbsEtaAxisHandler
AbsEtaAxisHandler(columnar::ColumnarTool<> *parent)
Definition: HistHandler.h:221
CP::HistHandler::GetBinContent
double GetBinContent(int bin) const
Definition: HistHandler.h:51
CP::PtAxisHandler
Definition: HistHandler.h:195
CP::ChargeAxisHandler
Definition: HistHandler.h:203
CP::HistHandler_TH1::FindBin
CorrectionCode FindBin(columnar::MuonId muon, int &bin) const override
Function that changes from Implementation to implementation.
Definition: HistHandler.cxx:167
CP::HistHandler_TH1
Definition: HistHandler.h:92
CP
Select isolated Photons, Electrons and Muons.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:49
CP::HistHandler_TH3::m_y_handler
std::unique_ptr< AxisHandler > m_y_handler
Definition: HistHandler.h:158
CP::EtaAxisHandler
Definition: HistHandler.h:211
CP::AxisHandler::AxisHandler
AxisHandler(columnar::ColumnarTool<> *parent)
Definition: HistHandler.h:187
CP::AbsEtaAxisHandler
Definition: HistHandler.h:218
CP::dRJetAxisHandler::ATLAS_THREAD_SAFE
static bool s_use_2D_sf ATLAS_THREAD_SAFE
Definition: HistHandler.h:248
CP::HistHandler::isOverFlowBin
virtual bool isOverFlowBin(int b) const =0
States whether a bin is overflow or not.
CP::HistHandler_TH2Poly::isOverFlowBin
bool isOverFlowBin(int b) const override
States whether a bin is overflow or not.
Definition: HistHandler.cxx:312
CP::AxisHandler::GetBinningParameter
virtual CorrectionCode GetBinningParameter(columnar::MuonId mu, float &value) const =0
CP::dRJetAxisHandler::dRJetAxisHandler
dRJetAxisHandler(columnar::ColumnarTool<> *parent)
Definition: HistHandler.cxx:80
CP::HistHandler_TH1::nOverFlowBins
int nOverFlowBins() const override
Return the number of overflow bins.
Definition: HistHandler.cxx:161
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:248
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:328
CP::HistHandler::GetHist
TH1 * GetHist() const
Definition: HistHandler.h:63
CP::AbsEtaAxisHandler::etaAcc
columnar::MuonAccessor< float > etaAcc
Definition: HistHandler.h:223
CP::AbsEtaAxisHandler::~AbsEtaAxisHandler
virtual ~AbsEtaAxisHandler()=default
CP::PhiAxisHandler::PhiAxisHandler
PhiAxisHandler(columnar::ColumnarTool<> *parent)
Definition: HistHandler.h:228
CP::PhiAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(columnar::MuonId mu, float &value) const override
Definition: HistHandler.cxx:65
CP::HistHandler_TH3::m_z_handler
std::unique_ptr< AxisHandler > m_z_handler
Definition: HistHandler.h:159
CP::HistHandler_TH3
Definition: HistHandler.h:136
CP::ChargeAxisHandler::chargeAcc
columnar::MuonAccessor< float > chargeAcc
Definition: HistHandler.h:208
CP::ChargeAxisHandler::~ChargeAxisHandler
virtual ~ChargeAxisHandler()=default
CP::HistHandler_TH2Poly::m_y_handler
std::unique_ptr< AxisHandler > m_y_handler
Definition: HistHandler.h:181
CP::HistHandler_TH2::FindBin
CorrectionCode FindBin(columnar::MuonId muon, int &bin) const override
Function that changes from Implementation to implementation.
Definition: HistHandler.cxx:202
CP::AbsEtaAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(columnar::MuonId mu, float &value) const override
Definition: HistHandler.cxx:61
CP::AxisHandlerProvider::GetAxisHandler
static std::unique_ptr< AxisHandler > GetAxisHandler(columnar::ColumnarTool<> *parent, const TAxis *axis)
Definition: HistHandler.cxx:20
CP::HistHandler::SetBinContent
void SetBinContent(int bin, float val)
Definition: HistHandler.cxx:140
CP::PtAxisHandler::ptAcc
columnar::MuonAccessor< float > ptAcc
Definition: HistHandler.h:200
CP::PtAxisHandler::PtAxisHandler
PtAxisHandler(columnar::ColumnarTool<> *parent)
Definition: HistHandler.h:198
ColumnAccessor.h
CP::HistHandler_TH2Poly
Definition: HistHandler.h:162
CP::HistHandler
Definition: HistHandler.h:42
CP::dRJetAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(columnar::MuonId mu, float &value) const override
Definition: HistHandler.cxx:85
CP::ChargeAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(columnar::MuonId mu, float &value) const override
Definition: HistHandler.cxx:53
CP::dRJetAxisHandler
Definition: HistHandler.h:232
CP::HistHandler_TH1::HistHandler_TH1
HistHandler_TH1(columnar::ColumnarTool<> *parent, TH1 *hist)
Definition: HistHandler.cxx:153
CP::AxisHandler
Definition: HistHandler.h:184
CP::HistHandler_TH2
Definition: HistHandler.h:112
test_pyathena.parent
parent
Definition: test_pyathena.py:15
CP::dRJetAxisHandler::acc_dR_deriv
columnar::MuonAccessor< float > acc_dR_deriv
Definition: HistHandler.h:254
CP::dRJetAxisHandler::m_use_2D_sf
bool m_use_2D_sf
Definition: HistHandler.h:250
ObjectColumn.h
ColumnarTool.h
CP::HistHandler_TH2::m_x_handler
std::unique_ptr< AxisHandler > m_x_handler
Definition: HistHandler.h:132
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:221
MuonDef.h
CP::PtAxisHandler::GetBinningParameter
CorrectionCode GetBinningParameter(columnar::MuonId mu, float &value) const override
Definition: HistHandler.cxx:49
CP::HistHandler_TH2::HistHandler_TH2
HistHandler_TH2(columnar::ColumnarTool<> *parent, TH1 *hist)
The HistHandler TH2 handles 2D histograms which are not TH2Poly, since TH2 inhertis from TH1,...
Definition: HistHandler.cxx:187
CP::dRJetAxisHandler::~dRJetAxisHandler
virtual ~dRJetAxisHandler()=default
columnar::ObjectId
a class representing a single object (electron, muons, etc.)
Definition: ObjectId.h:18
CP::dRJetAxisHandler::ATLAS_THREAD_SAFE
static std::string s_close_jet_decor ATLAS_THREAD_SAFE
Definition: HistHandler.h:246
CP::EtaAxisHandler::etaAcc
columnar::MuonAccessor< float > etaAcc
Definition: HistHandler.h:216
CP::HistHandler_TH2Poly::nBins
int nBins() const override
Return the total number of bins in the histogram -> (GetNbins() +2)**n.
Definition: HistHandler.cxx:307
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:160
CP::dRJetAxisHandler::m_acc
columnar::MuonAccessor< float > m_acc
Definition: HistHandler.h:253
CP::EtaAxisHandler::~EtaAxisHandler
virtual ~EtaAxisHandler()=default
CP::HistHandler_TH1::~HistHandler_TH1
virtual ~HistHandler_TH1()
Definition: HistHandler.cxx:158
CP::PhiAxisHandler::phiAcc
columnar::MuonAccessor< float > phiAcc
Definition: HistHandler.h:230
CP::ChargeAxisHandler::ChargeAxisHandler
ChargeAxisHandler(columnar::ColumnarTool<> *parent)
Definition: HistHandler.h:206
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:163
CP::EtaAxisHandler::EtaAxisHandler
EtaAxisHandler(columnar::ColumnarTool<> *parent)
Definition: HistHandler.h:214
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CP::HistHandler_TH2Poly::m_x_handler
std::unique_ptr< AxisHandler > m_x_handler
Definition: HistHandler.h:180
columnar
Definition: ClusterDef.h:16
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
CP::HistHandler::operator=
HistHandler & operator=(const HistHandler &other)=delete
columnar::ColumnarTool<>
CP::HistHandler_TH3::m_x_handler
std::unique_ptr< AxisHandler > m_x_handler
Definition: HistHandler.h:157
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:133
CP::HistHandler::~HistHandler
virtual ~HistHandler()
Definition: HistHandler.cxx:138
CorrectionCode.h
CP::HistHandler_TH2Poly::HistHandler_TH2Poly
HistHandler_TH2Poly(columnar::ColumnarTool<> *parent, TH2Poly *hist)
The HistHandler_TH2Poly handles the TH2Poly histograms of the scale-factor maps.
Definition: HistHandler.cxx:297
columnar::AccessorTemplate
the raw column accessor template class
Definition: ColumnAccessor.h:81
CP::UndefinedAxisHandler
Definition: HistHandler.h:256
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::m_H
std::unique_ptr< TH1 > m_H
Definition: HistHandler.h:86
CP::HistHandler_TH3::~HistHandler_TH3
virtual ~HistHandler_TH3()
Definition: HistHandler.cxx:243
CP::HistHandler::GetBinError
double GetBinError(int bin) const
Definition: HistHandler.h:58