ATLAS Offline Software
Loading...
Searching...
No Matches
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
10namespace Root{
11namespace EGSelectors{
12class SafeTH1{
13
14public :
15 SafeTH1(TH1F* hist){
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 }
27
28 int GetNbinsX() const {
29 int n = m_binContent.size();
30 return n;
31 }
32
33 int FindBin(double value) const{
34
35 if(value < m_firstBinLowEdge){
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
61private:
62 std::vector<float> m_binContent;
65 double m_binWidth;
66 double m_integral;
67};
68}
69}
70#endif
double Integral() const
Definition SafeTH1.h:57
double GetBinContent(int bin) const
Definition SafeTH1.h:47
int FindBin(double value) const
Definition SafeTH1.h:33
double GetBinLowEdge(int bin) const
Definition SafeTH1.h:54
std::vector< float > m_binContent
Definition SafeTH1.h:62