ATLAS Offline Software
TFCS1DFunctionTemplateHistogram.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 ISF_FASTCALOSIMEVENT_TFCS1DFunctionTemplateHistogram_h
6 #define ISF_FASTCALOSIMEVENT_TFCS1DFunctionTemplateHistogram_h
7 
10 
11 #include "TH1.h"
12 #include <iostream>
13 
14 template <typename Txvec, typename Ty, typename Trandom = float>
16 public:
18  typedef Trandom random_type;
19  typedef Txvec xvec_type;
20  typedef Ty y_value_type;
21 
22  TFCS1DFunctionTemplateHistogram(TH1 *hist = nullptr, bool doprint = true) {
23  if (hist)
24  Initialize(hist, doprint);
25  };
27 
28  std::size_t MemorySizeArray() const {
29  return m_HistoBorders.MemorySizeArray() + m_HistoContents.MemorySizeArray();
30  };
31  std::size_t MemorySize() const { return sizeof(*this) + MemorySizeArray(); };
32 
34  void set_nbins(size_t nbins) {
35  m_HistoBorders.set_nbins(nbins);
36  m_HistoContents.set_nbins(nbins);
37  };
38 
40  inline size_t get_nbins() const { return m_HistoContents.get_nbins(); };
41 
44  void Initialize(const TH1 *hist, bool doprint = true) {
45  Int_t nbins = hist->GetNbinsX();
46 
47  std::vector<double> temp_HistoContents;
48  int first, last;
49  double integral =
50  CheckAndIntegrate1DHistogram(hist, temp_HistoContents, first, last);
51  if (integral <= 0) {
52  set_nbins(0);
53  } else {
55 
56  m_HistoBorders.SetMinMax(hist->GetXaxis()->GetBinLowEdge(first + 1),
57  hist->GetXaxis()->GetBinUpEdge(last + 1));
58  Int_t ihist = 0;
59  for (Int_t ibin = first; ibin <= last; ++ibin) {
60  m_HistoBorders.SetBinLowEdge(ihist,
61  hist->GetXaxis()->GetBinLowEdge(ibin + 1));
62  if (ihist > 0)
63  if (m_HistoBorders.GetBinLowEdge(ihist - 1) ==
64  m_HistoBorders.GetBinLowEdge(ihist)) {
65  if (doprint)
66  ATH_MSG_INFO("Skip bin="
67  << ibin + 1
68  << " x=" << hist->GetXaxis()->GetBinLowEdge(ibin + 1)
69  << " fx=" << m_HistoBorders.GetBinLowEdge(ihist));
70  --ihist;
71  if (doprint)
72  ATH_MSG_INFO(" bin="
73  << ibin
74  << " x=" << hist->GetXaxis()->GetBinLowEdge(ibin)
75  << " fx=" << m_HistoBorders.GetBinLowEdge(ihist));
76  }
77  m_HistoContents.set_fraction(ihist,
78  temp_HistoContents[ibin] / integral);
79  if (ihist > 0)
80  if (m_HistoContents.get_fraction(ihist - 1) ==
81  m_HistoContents.get_fraction(ihist)) {
82  if (doprint)
83  ATH_MSG_INFO("Skip fbin="
84  << ihist
85  << " fx=" << m_HistoBorders.GetBinLowEdge(ihist)
86  << " frac=" << m_HistoContents.get_fraction(ihist));
87  --ihist;
88  if (doprint)
89  ATH_MSG_INFO(" fbin="
90  << ihist
91  << " fx=" << m_HistoBorders.GetBinLowEdge(ihist)
92  << " frac=" << m_HistoContents.get_fraction(ihist));
93  }
94 
95  if (doprint)
96  ATH_MSG_INFO("bin=" << ibin + 1 << " fbin=" << ihist << "/"
97  << m_HistoBorders.get_nbins() << " x=["
98  << hist->GetXaxis()->GetBinLowEdge(ibin + 1)
99  << "," << hist->GetXaxis()->GetBinUpEdge(ibin + 1)
100  << "] fx=" << m_HistoBorders.GetBinLowEdge(ihist)
101  << " int=" << temp_HistoContents[ibin] / integral
102  << " frac="
103  << m_HistoContents.get_fraction(ihist));
104 
105  ++ihist;
106  }
107  if (ihist != nbins) {
108  set_nbins(ihist);
109  m_HistoBorders.SetMinMax(hist->GetXaxis()->GetBinLowEdge(first + 1),
110  hist->GetXaxis()->GetBinUpEdge(last + 1));
111  }
112  }
113  }
114 
116 
119  virtual double rnd_to_fct(double rnd) const {
120  if (m_HistoContents.get_nbins() == 0)
121  return 0;
122  Trandom residual_rnd;
123  size_t ibin = m_HistoContents.get_bin(rnd, residual_rnd);
124  // ATH_MSG_INFO( fx="<<m_HistoBorders.GetBinLowEdge(ibin)<<"
125  // frac="<<m_HistoContents.get_fraction(ibin)<<"
126  // residual_rnd="<<residual_rnd);
127  return m_HistoBorders.position(ibin, residual_rnd);
128  }
129 
130  inline const Txvec &get_HistoBordersx() const { return m_HistoBorders; };
131  inline Txvec &get_HistoBordersx() { return m_HistoBorders; };
132 
135  return m_HistoContents;
136  };
138  return m_HistoContents;
139  };
140 
141 protected:
144 
145 private:
147  1) // TFCS1DFunctionTemplateHistogram
148 };
149 
152  TFCS1DFunction_HistogramInt8BinEdges, uint8_t, float> {
153 public:
156  uint8_t, float>(h){};
157 
159  1) // TFCS1DFunctionInt8Int8Histogram
160 };
161 
164  TFCS1DFunction_HistogramInt8BinEdges, uint16_t, float> {
165 public:
168  uint16_t, float>(h){};
169 
171  1) // TFCS1DFunctionInt8Int16Histogram
172 };
173 
176  TFCS1DFunction_HistogramInt8BinEdges, uint32_t, float> {
177 public:
180  uint32_t, float>(h){};
181 
183  1) // TFCS1DFunctionInt8Int32Histogram
184 };
185 
188  TFCS1DFunction_HistogramInt16BinEdges, uint16_t, float> {
189 public:
192  uint16_t, float>(h){};
193 
195  1) // TFCS1DFunctionInt16Int16Histogram
196 };
197 
200  TFCS1DFunction_HistogramInt16BinEdges, uint32_t, float> {
201 public:
204  uint32_t, float>(h){};
205 
207  1) // TFCS1DFunctionInt16Int32Histogram
208 };
209 
212  TFCS1DFunction_HistogramInt32BinEdges, uint32_t, float> {
213 public:
216  uint32_t, float>(h){};
217 
219  1) // TFCS1DFunctionInt32Int32Histogram
220 };
221 
222 #endif
TFCS1DFunctionInt8Int16Histogram
Definition: TFCS1DFunctionTemplateHistogram.h:164
TFCS1DFunction_size_t
uint32_t TFCS1DFunction_size_t
Definition: TFCS1DFunctionTemplateHelpers.h:16
TFCS1DFunctionInt16Int32Histogram::TFCS1DFunctionInt16Int32Histogram
TFCS1DFunctionInt16Int32Histogram(TH1 *h=nullptr)
Definition: TFCS1DFunctionTemplateHistogram.h:202
TFCS1DFunctionTemplateHistogram::rnd_to_fct
virtual double rnd_to_fct(double rnd) const
Function gets random number rnd in the range [0,1) as argument and returns function value according t...
Definition: TFCS1DFunctionTemplateHistogram.h:119
TFCS1DFunctionTemplateHistogram::random_type
Trandom random_type
Definition: TFCS1DFunctionTemplateHistogram.h:18
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
integral
double integral(TH1 *h)
Definition: computils.cxx:57
TFCS1DFunctionInt8Int8Histogram
Definition: TFCS1DFunctionTemplateHistogram.h:152
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TFCS1DFunction_HistogramInt16BinEdges
Definition: TFCS1DFunctionTemplateHelpers.h:517
TFCS1DFunctionTemplateHistogram::get_HistoBordersx
const Txvec & get_HistoBordersx() const
Definition: TFCS1DFunctionTemplateHistogram.h:130
plotmaker.hist
hist
Definition: plotmaker.py:148
TFCS1DFunctionInt16Int16Histogram
Definition: TFCS1DFunctionTemplateHistogram.h:188
TFCS1DFunction_HistogramInt32BinEdges
Definition: TFCS1DFunctionTemplateHelpers.h:528
TFCS1DFunctionTemplateHistogram::y_value_type
Ty y_value_type
Definition: TFCS1DFunctionTemplateHistogram.h:20
TFCS1DFunction::rnd_to_fct
virtual void rnd_to_fct(float value[], const float rnd[]) const
Function gets array of random numbers rnd[] in the range [0,1) as arguments and returns function valu...
Definition: TFCS1DFunction.cxx:17
TFCS1DFunctionInt16Int16Histogram::TFCS1DFunctionInt16Int16Histogram
TFCS1DFunctionInt16Int16Histogram(TH1 *h=nullptr)
Definition: TFCS1DFunctionTemplateHistogram.h:190
TFCS1DFunctionInt16Int32Histogram
Definition: TFCS1DFunctionTemplateHistogram.h:200
TFCS1DFunctionInt8Int32Histogram::TFCS1DFunctionInt8Int32Histogram
TFCS1DFunctionInt8Int32Histogram(TH1 *h=nullptr)
Definition: TFCS1DFunctionTemplateHistogram.h:178
TFCS1DFunctionTemplateHistogram::MemorySizeArray
std::size_t MemorySizeArray() const
Definition: TFCS1DFunctionTemplateHistogram.h:28
TFCS1DFunctionTemplateHistogram::MemorySize
std::size_t MemorySize() const
Gives the total memory size, including the size of additional memory allocated inside the class.
Definition: TFCS1DFunctionTemplateHistogram.h:31
TFCS1DFunctionInt32Int32Histogram
Definition: TFCS1DFunctionTemplateHistogram.h:212
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
TFCS1DFunctionTemplateHistogram::TFCS1DFunctionTemplateHistogram
TFCS1DFunctionTemplateHistogram(TH1 *hist=nullptr, bool doprint=true)
Definition: TFCS1DFunctionTemplateHistogram.h:22
TFCS1DFunctionTemplateHistogram::get_nbins
size_t get_nbins() const
return number of bins
Definition: TFCS1DFunctionTemplateHistogram.h:40
TFCS1DFunctionTemplateHistogram::Initialize
void Initialize(const TH1 *hist, bool doprint=true)
Initialize from root histogram.
Definition: TFCS1DFunctionTemplateHistogram.h:44
TFCS1DFunctionTemplateHistogram::m_HistoBorders
Txvec m_HistoBorders
Definition: TFCS1DFunctionTemplateHistogram.h:139
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
TFCS1DFunctionTemplateHistogram::xvec_type
Txvec xvec_type
Definition: TFCS1DFunctionTemplateHistogram.h:19
TFCS1DFunction::CheckAndIntegrate1DHistogram
static double CheckAndIntegrate1DHistogram(const TH1 *hist, std::vector< double > &integral_vec, int &first, int &last)
Definition: TFCS1DFunction.cxx:52
TFCS1DFunctionInt8Int16Histogram::TFCS1DFunctionInt8Int16Histogram
TFCS1DFunctionInt8Int16Histogram(TH1 *h=nullptr)
Definition: TFCS1DFunctionTemplateHistogram.h:166
TFCS1DFunction_HistogramInt8BinEdges
Definition: TFCS1DFunctionTemplateHelpers.h:507
TFCS1DFunctionTemplateHistogram::set_nbins
void set_nbins(size_t nbins)
set number of bins
Definition: TFCS1DFunctionTemplateHistogram.h:34
TFCS1DFunctionTemplateHistogram::m_HistoContents
TFCS1DFunction_HistogramContent< Ty, Trandom > m_HistoContents
Definition: TFCS1DFunctionTemplateHistogram.h:143
TFCS1DFunctionInt32Int32Histogram::TFCS1DFunctionInt32Int32Histogram
TFCS1DFunctionInt32Int32Histogram(TH1 *h=nullptr)
Definition: TFCS1DFunctionTemplateHistogram.h:214
TFCS1DFunction_HistogramContent
Definition: TFCS1DFunctionTemplateHelpers.h:157
h
TFCS1DFunctionTemplateHistogram::size_t
TFCS1DFunction_size_t size_t
Definition: TFCS1DFunctionTemplateHistogram.h:17
TH1
Definition: rootspy.cxx:268
DeMoScan.first
bool first
Definition: DeMoScan.py:534
TFCS1DFunctionTemplateHistogram::~TFCS1DFunctionTemplateHistogram
~TFCS1DFunctionTemplateHistogram()
Definition: TFCS1DFunctionTemplateHistogram.h:26
TFCS1DFunctionTemplateHistogram::get_HistoBordersx
Txvec & get_HistoBordersx()
Definition: TFCS1DFunctionTemplateHistogram.h:131
TFCS1DFunctionTemplateHelpers.h
TFCS1DFunction.h
TFCS1DFunctionTemplateHistogram
Definition: TFCS1DFunctionTemplateHistogram.h:15
TFCS1DFunctionInt8Int32Histogram
Definition: TFCS1DFunctionTemplateHistogram.h:176
TFCS1DFunctionInt8Int8Histogram::TFCS1DFunctionInt8Int8Histogram
TFCS1DFunctionInt8Int8Histogram(TH1 *h=nullptr)
Definition: TFCS1DFunctionTemplateHistogram.h:154
TFCS1DFunctionTemplateHistogram::get_HistoContents
TFCS1DFunction_HistogramContent< Ty, Trandom > & get_HistoContents()
Definition: TFCS1DFunctionTemplateHistogram.h:137
TFCS1DFunctionTemplateHistogram::get_HistoContents
const TFCS1DFunction_HistogramContent< Ty, Trandom > & get_HistoContents() const
Definition: TFCS1DFunctionTemplateHistogram.h:134
TFCS1DFunction
Definition: TFCS1DFunction.h:17
readCCLHist.float
float
Definition: readCCLHist.py:83