ATLAS Offline Software
Loading...
Searching...
No Matches
CP::HistHandler_TH2 Class Reference

#include <HistHandler.h>

Inheritance diagram for CP::HistHandler_TH2:
Collaboration diagram for CP::HistHandler_TH2:

Public Member Functions

 HistHandler_TH2 (columnar::ColumnarTool<> *parent, TH1 *hist)
 The HistHandler TH2 handles 2D histograms which are not TH2Poly, since TH2 inhertis from TH1, a TH1* object is parsed avoiding the dynamic cast.
virtual ~HistHandler_TH2 ()
int nBins () const override
 Return the total number of bins in the histogram -> (GetNbins() +2)**n.
int nOverFlowBins () const override
 Return the number of overflow bins.
bool isOverFlowBin (int b) const override
 States whether a bin is overflow or not.
std::string GetBinName (unsigned int bin) const override
 Translates the bin number into the borders and return them as name.
CorrectionCode FindBin (columnar::MuonId muon, int &bin) const override
 Function that changes from Implementation to implementation.
double GetBinContent (int bin) const
void SetBinContent (int bin, float val)
double GetBinError (int bin) const
TH1 * GetHist () const
void SetBinError (int bin, float val)

Private Attributes

std::unique_ptr< AxisHandlerm_x_handler
std::unique_ptr< AxisHandlerm_y_handler
std::unique_ptr< TH1 > m_H

Detailed Description

Definition at line 112 of file HistHandler.h.

Constructor & Destructor Documentation

◆ HistHandler_TH2()

CP::HistHandler_TH2::HistHandler_TH2 ( columnar::ColumnarTool<> * parent,
TH1 * hist )

The HistHandler TH2 handles 2D histograms which are not TH2Poly, since TH2 inhertis from TH1, a TH1* object is parsed avoiding the dynamic cast.

Via the GetDimension() method of the TH1 the class ensures that the histogram has actual dimension 2. No specific TH2 method is required in all considered usecases of TH1.

Definition at line 187 of file HistHandler.cxx.

187 :
188 HistHandler(parent, h),
189 m_x_handler(h == nullptr ? 0 : AxisHandlerProvider::GetAxisHandler(parent, h->GetXaxis())),
190 m_y_handler(h == nullptr ? 0 : AxisHandlerProvider::GetAxisHandler(parent, h->GetYaxis())) {
191
192 }
static std::unique_ptr< AxisHandler > GetAxisHandler(columnar::ColumnarTool<> *parent, const TAxis *axis)
std::unique_ptr< AxisHandler > m_x_handler
std::unique_ptr< AxisHandler > m_y_handler
HistHandler(columnar::ColumnarTool<> *parent, TH1 *Hist)

◆ ~HistHandler_TH2()

CP::HistHandler_TH2::~HistHandler_TH2 ( )
virtual

Definition at line 219 of file HistHandler.cxx.

219 {
220 }

Member Function Documentation

◆ FindBin()

CorrectionCode CP::HistHandler_TH2::FindBin ( columnar::MuonId muon,
int & bin ) const
overridevirtual

Function that changes from Implementation to implementation.

Implements CP::HistHandler.

Definition at line 202 of file HistHandler.cxx.

202 {
203 if (!GetHist()) return CorrectionCode::Error;
204 float parx = 0;
205 float pary = 0;
206 if (m_x_handler->GetBinningParameter(muon, parx) == CorrectionCode::Error ||
207 m_y_handler->GetBinningParameter(muon, pary) == CorrectionCode::Error) {
209 } else {
210 int binx = GetHist()->GetXaxis()->FindBin(parx);
211 int biny = GetHist()->GetYaxis()->FindBin(pary);
212 if (binx < 1 || binx > GetHist()->GetNbinsX() || biny < 1 || biny > GetHist()->GetNbinsY()) {
214 }
215 bin = GetHist()->GetBin(binx, biny);
216 }
217 return CorrectionCode::Ok;
218 }
@ Error
Some error happened during the object correction.
@ OutOfValidityRange
Input object is out of validity range.
@ Ok
The correction was done successfully.
TH1 * GetHist() const
Definition HistHandler.h:63

◆ GetBinContent()

double CP::HistHandler::GetBinContent ( int bin) const
inlineinherited

Definition at line 51 of file HistHandler.h.

51 {
52 if (!m_H) return DBL_MAX;
53 return m_H->GetBinContent(bin);
54 }
std::unique_ptr< TH1 > m_H
Definition HistHandler.h:86

◆ GetBinError()

double CP::HistHandler::GetBinError ( int bin) const
inlineinherited

Definition at line 58 of file HistHandler.h.

58 {
59 if (!m_H) return DBL_MAX;
60 return m_H->GetBinError(bin);
61 }

◆ GetBinName()

std::string CP::HistHandler_TH2::GetBinName ( unsigned int bin) const
overridevirtual

Translates the bin number into the borders and return them as name.

Implements CP::HistHandler.

Definition at line 221 of file HistHandler.cxx.

221 {
222 int x(0), y(0), z(0);
223 GetHist()->GetBinXYZ(bin, x, y, z);
224 TAxis* xAx = GetHist()->GetXaxis();
225 TAxis* yAx = GetHist()->GetYaxis();
226 return Form("%s_%.2f_to_%.2f_times_%s_%.2f_to_%.2f",
227 //xAxis
228 xAx->GetTitle(), xAx->GetBinLowEdge(x), xAx->GetBinUpEdge(x),
229 //yAxis
230 yAx->GetTitle(), yAx->GetBinLowEdge(y), yAx->GetBinUpEdge(y));
231 }
#define y
#define x
#define z

◆ GetHist()

TH1 * CP::HistHandler::GetHist ( ) const
inlineinherited

Definition at line 63 of file HistHandler.h.

63 {
64 return m_H.get();
65 }

◆ isOverFlowBin()

bool CP::HistHandler_TH2::isOverFlowBin ( int b) const
overridevirtual

States whether a bin is overflow or not.

Implements CP::HistHandler.

Definition at line 197 of file HistHandler.cxx.

197 {
198 int x(-1),y(-1), z(-1);
199 GetHist()->GetBinXYZ(b,x,y,z);
200 return x == 0 || x == GetHist()->GetXaxis()->GetNbins() + 1 || y == 0 || y == GetHist()->GetYaxis()->GetNbins() + 1;
201 }

◆ nBins()

int CP::HistHandler_TH2::nBins ( ) const
overridevirtual

Return the total number of bins in the histogram -> (GetNbins() +2)**n.

Implements CP::HistHandler.

Definition at line 193 of file HistHandler.cxx.

193 {
194 return (GetHist()->GetNbinsX() + 2) * (GetHist()->GetNbinsY() + 2);
195 }

◆ nOverFlowBins()

int CP::HistHandler_TH2::nOverFlowBins ( ) const
overridevirtual

Return the number of overflow bins.

Implements CP::HistHandler.

Definition at line 196 of file HistHandler.cxx.

196{return 2*GetHist()->GetNbinsX() + 2*GetHist()->GetNbinsY() + 4; }

◆ SetBinContent()

void HistHandler::SetBinContent ( int bin,
float val )
inherited

Definition at line 140 of file HistHandler.cxx.

140 {
141 if (m_H) {
142 m_H->SetBinContent(bin, val);
143 }
144 }

◆ SetBinError()

void HistHandler::SetBinError ( int bin,
float val )
inherited

Definition at line 145 of file HistHandler.cxx.

145 {
146 if (m_H) {
147 m_H->SetBinError(bin, val);
148 }
149 }

Member Data Documentation

◆ m_H

std::unique_ptr<TH1> CP::HistHandler::m_H
privateinherited

Definition at line 86 of file HistHandler.h.

◆ m_x_handler

std::unique_ptr<AxisHandler> CP::HistHandler_TH2::m_x_handler
private

Definition at line 132 of file HistHandler.h.

◆ m_y_handler

std::unique_ptr<AxisHandler> CP::HistHandler_TH2::m_y_handler
private

Definition at line 133 of file HistHandler.h.


The documentation for this class was generated from the following files: