ATLAS Offline Software
Loading...
Searching...
No Matches
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
27
28// STL includes
29#include <string>
30#include <iostream>
31#include <exception>
32#include <map>
33#include <memory>
34#include <cmath>
35
36namespace ADD_CMODE(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 CP::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:
82 HistHandler(columnar::ColumnarTool<>* parent, TH1* Hist);
83 HistHandler(const HistHandler & other) = delete;
84 HistHandler& operator =(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
96 HistHandler_TH1(columnar::ColumnarTool<>* parent, TH1* hist);
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 CP::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:
119 HistHandler_TH2(columnar::ColumnarTool<>* parent, TH1* hist);
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 CP::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
143 HistHandler_TH3(columnar::ColumnarTool<>* parent, TH1* hist);
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 CP::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
162 class HistHandler_TH2Poly: public HistHandler {
163
164 public:
168 HistHandler_TH2Poly(columnar::ColumnarTool<>* parent, TH2Poly* hist);
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 CP::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
184 class AxisHandler : public columnar::ColumnarTool<> {
185 public:
186 virtual CP::CorrectionCode GetBinningParameter(columnar::MuonId mu, float & value) const =0;
187 AxisHandler (columnar::ColumnarTool<> * parent) : columnar::ColumnarTool<>(parent) {}
188 virtual ~AxisHandler()= default;
189 };
190 class AxisHandlerProvider {
191 public:
192 static std::unique_ptr<AxisHandler> GetAxisHandler(columnar::ColumnarTool<> * parent, const TAxis* axis);
193 };
194
195 class PtAxisHandler: public AxisHandler {
196 public:
197 CP::CorrectionCode GetBinningParameter(columnar::MuonId mu, float & value) const override;
198 PtAxisHandler (columnar::ColumnarTool<> * parent) : AxisHandler(parent) {}
199 virtual ~PtAxisHandler() = default;
200 columnar::MuonAccessor<float> ptAcc {*this, "pt"};
201 };
202
203 class ChargeAxisHandler: public AxisHandler {
204 public:
205 CP::CorrectionCode GetBinningParameter(columnar::MuonId mu, float & value) const override;
206 ChargeAxisHandler (columnar::ColumnarTool<> * parent) : AxisHandler(parent) {}
207 virtual ~ChargeAxisHandler() = default;
208 columnar::MuonAccessor<float> chargeAcc {*this, "charge"};
209 };
210
211 class EtaAxisHandler: public AxisHandler {
212 public:
213 CP::CorrectionCode GetBinningParameter(columnar::MuonId mu, float & value) const override;
214 EtaAxisHandler (columnar::ColumnarTool<> * parent) : AxisHandler(parent) {}
215 virtual ~EtaAxisHandler() = default;
216 columnar::MuonAccessor<float> etaAcc {*this, "eta"};
217 };
218 class AbsEtaAxisHandler: public AxisHandler {
219 public:
220 CP::CorrectionCode GetBinningParameter(columnar::MuonId mu, float & value) const override;
221 AbsEtaAxisHandler (columnar::ColumnarTool<> * parent) : AxisHandler(parent) {}
222 virtual ~AbsEtaAxisHandler() = default;
223 columnar::MuonAccessor<float> etaAcc {*this, "eta"};
224 };
225 class PhiAxisHandler: public AxisHandler {
226 public:
227 CP::CorrectionCode GetBinningParameter(columnar::MuonId mu, float & value) const override;
228 PhiAxisHandler (columnar::ColumnarTool<> * parent) : AxisHandler(parent) {}
229 virtual ~PhiAxisHandler() = default;
230 columnar::MuonAccessor<float> phiAcc {*this, "phi"};
231 };
232 class dRJetAxisHandler: public AxisHandler {
233 public:
234 dRJetAxisHandler(columnar::ColumnarTool<> * parent);
235
236 CP::CorrectionCode GetBinningParameter(columnar::MuonId mu, float & value) const override;
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
250 bool m_use_2D_sf;
251
252 public:
254 columnar::MuonAccessor<float> acc_dR_deriv {*this, "DFCommonJetDr"};
255 };
256 class UndefinedAxisHandler: public AxisHandler {
257 public:
258 CP::CorrectionCode GetBinningParameter(columnar::MuonId, float &) const override;
259 UndefinedAxisHandler (columnar::ColumnarTool<> * parent) : AxisHandler(parent) {}
260 virtual ~UndefinedAxisHandler() = default;
261 };
262
263} // namespace ADD_CMODE(CP)
264#endif
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
Int_t FindBin(const TAxis *axis, const double x)
ObjectId< MuonDef > MuonId
Definition MuonDef.h:22
AccessorTemplate< MuonDef, CT, ColumnAccessMode::input, CM > MuonAccessor
Definition MuonDef.h:24