ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
Root::EGSelectors::SafeTH1 Class Reference

#include <SafeTH1.h>

Collaboration diagram for Root::EGSelectors::SafeTH1:

Public Member Functions

 SafeTH1 (TH1F *hist)
 
 ~SafeTH1 ()
 
int GetNbinsX () const
 
int FindBin (double value) const
 
double GetBinContent (int bin) const
 
double GetBinLowEdge (int bin) const
 
double Integral () const
 

Private Attributes

std::vector< float > m_binContent
 
double m_firstBinLowEdge
 
double m_lastBinLowEdge
 
double m_binWidth
 
double m_integral
 

Detailed Description

Definition at line 12 of file SafeTH1.h.

Constructor & Destructor Documentation

◆ SafeTH1()

Root::EGSelectors::SafeTH1::SafeTH1 ( TH1F *  hist)
inline

Definition at line 15 of file SafeTH1.h.

15  {
16  const int nbins = hist->GetNbinsX();
17  m_binContent.resize(nbins,0); // Note that the PDF over/underflows are unused and thus unrepresented here!
18  for(int i = 0; i < nbins; ++i){
19  m_binContent[i] = hist->GetBinContent(i+1);
20  }
21  m_firstBinLowEdge = hist->GetBinLowEdge(1);
22  m_lastBinLowEdge = hist->GetBinLowEdge(nbins);
24  m_integral = hist->Integral(1,nbins);
25  }

◆ ~SafeTH1()

Root::EGSelectors::SafeTH1::~SafeTH1 ( )
inline

Definition at line 26 of file SafeTH1.h.

26 {};

Member Function Documentation

◆ FindBin()

int Root::EGSelectors::SafeTH1::FindBin ( double  value) const
inline

Definition at line 33 of file SafeTH1.h.

33  {
34 
36  return 0; // first bin of m_binContent
37  }
38  if(value > m_lastBinLowEdge){
39  return GetNbinsX() - 1; // last bin of m_binContent
40  }
41  // note double rather than float due to incorrect rounding in O(1/10000) cases if float is used
42  double bin_double = (value - m_firstBinLowEdge) / m_binWidth;
43  int bin = static_cast<int>(bin_double);
44  return bin;
45  }

◆ GetBinContent()

double Root::EGSelectors::SafeTH1::GetBinContent ( int  bin) const
inline

Definition at line 47 of file SafeTH1.h.

47  {
48  int nbins = this->GetNbinsX();
49  // since we store the bin content in a vector we need a protection
50  // for cases where we try to access a non-existing bin. In these
51  // cases just go to the last bin
52  return (bin>nbins) ? m_binContent[nbins-1] : m_binContent[bin];
53  }

◆ GetBinLowEdge()

double Root::EGSelectors::SafeTH1::GetBinLowEdge ( int  bin) const
inline

Definition at line 54 of file SafeTH1.h.

54  {
56  }

◆ GetNbinsX()

int Root::EGSelectors::SafeTH1::GetNbinsX ( ) const
inline

Definition at line 28 of file SafeTH1.h.

28  {
29  int n = m_binContent.size();
30  return n;
31  }

◆ Integral()

double Root::EGSelectors::SafeTH1::Integral ( ) const
inline

Definition at line 57 of file SafeTH1.h.

57  {
58  return m_integral;
59  }

Member Data Documentation

◆ m_binContent

std::vector<float> Root::EGSelectors::SafeTH1::m_binContent
private

Definition at line 62 of file SafeTH1.h.

◆ m_binWidth

double Root::EGSelectors::SafeTH1::m_binWidth
private

Definition at line 65 of file SafeTH1.h.

◆ m_firstBinLowEdge

double Root::EGSelectors::SafeTH1::m_firstBinLowEdge
private

Definition at line 63 of file SafeTH1.h.

◆ m_integral

double Root::EGSelectors::SafeTH1::m_integral
private

Definition at line 66 of file SafeTH1.h.

◆ m_lastBinLowEdge

double Root::EGSelectors::SafeTH1::m_lastBinLowEdge
private

Definition at line 64 of file SafeTH1.h.


The documentation for this class was generated from the following file:
Root::EGSelectors::SafeTH1::m_firstBinLowEdge
double m_firstBinLowEdge
Definition: SafeTH1.h:63
Root::EGSelectors::SafeTH1::m_lastBinLowEdge
double m_lastBinLowEdge
Definition: SafeTH1.h:64
plotmaker.hist
hist
Definition: plotmaker.py:148
bin
Definition: BinsDiffFromStripMedian.h:43
athena.value
value
Definition: athena.py:124
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
lumiFormat.i
int i
Definition: lumiFormat.py:85
Root::EGSelectors::SafeTH1::m_binWidth
double m_binWidth
Definition: SafeTH1.h:65
beamspotman.n
n
Definition: beamspotman.py:731
Root::EGSelectors::SafeTH1::GetNbinsX
int GetNbinsX() const
Definition: SafeTH1.h:28
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
Root::EGSelectors::SafeTH1::m_integral
double m_integral
Definition: SafeTH1.h:66
Root::EGSelectors::SafeTH1::m_binContent
std::vector< float > m_binContent
Definition: SafeTH1.h:62