ATLAS Offline Software
SafeTH1.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 #ifndef __EGSELECTOR_SAFETH1L__
6 #define __EGSELECTOR_SAFETH1L__
7 
8 #include "TH1.h"
9 
10 namespace Root{
11 namespace EGSelectors{
12 class SafeTH1{
13 
14 public :
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  }
26  ~SafeTH1(){};
27 
28  int GetNbinsX() const {
29  int n = m_binContent.size();
30  return n;
31  }
32 
33  int FindBin(double value) const{
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  }
46 
47  double GetBinContent(int bin) const {
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  }
54  double GetBinLowEdge(int bin) const {
56  }
57  double Integral() const{
58  return m_integral;
59  }
60 
61 private:
62  std::vector<float> m_binContent;
65  double m_binWidth;
66  double m_integral;
67 };
68 }
69 }
70 #endif
Root::EGSelectors::SafeTH1::m_firstBinLowEdge
double m_firstBinLowEdge
Definition: SafeTH1.h:63
Root::EGSelectors::SafeTH1
Definition: SafeTH1.h:12
Root
Definition: GoodRunsListSelectorTool.h:30
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:122
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
Root::EGSelectors::SafeTH1::FindBin
int FindBin(double value) const
Definition: SafeTH1.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
Root::EGSelectors::SafeTH1::Integral
double Integral() const
Definition: SafeTH1.h:57
Root::EGSelectors::SafeTH1::GetBinLowEdge
double GetBinLowEdge(int bin) const
Definition: SafeTH1.h:54
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
Root::EGSelectors::SafeTH1::~SafeTH1
~SafeTH1()
Definition: SafeTH1.h:26
Root::EGSelectors::SafeTH1::SafeTH1
SafeTH1(TH1F *hist)
Definition: SafeTH1.h:15
Root::EGSelectors::SafeTH1::m_integral
double m_integral
Definition: SafeTH1.h:66
TH1F
Definition: rootspy.cxx:320
Root::EGSelectors::SafeTH1::GetBinContent
double GetBinContent(int bin) const
Definition: SafeTH1.h:47
Root::EGSelectors::SafeTH1::m_binContent
std::vector< float > m_binContent
Definition: SafeTH1.h:62