ATLAS Offline Software
TFCS1DFunctionTemplateInterpolationHistogram.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 ISF_FASTCALOSIMEVENT_TFCS1DFunctionTemplateInterpolationHistogram_h
6 #define ISF_FASTCALOSIMEVENT_TFCS1DFunctionTemplateInterpolationHistogram_h
7 
9 
10 template <typename Txvec, typename Ty, typename Trandom = float>
12  : public TFCS1DFunctionTemplateHistogram<Txvec, Ty, Trandom> {
13 public:
15  : TFCS1DFunctionTemplateHistogram<Txvec, Ty, Trandom>(hist){};
16 
21 
25  virtual double rnd_to_fct(double rnd) const {
26  size_t nbins = get_nbins();
27  if (nbins == 0)
28  return 0;
29  Trandom residual_rnd;
30  size_t ibin = m_HistoContents.get_bin(rnd, residual_rnd);
31 
32  Trandom frac = m_HistoContents.get_fraction(ibin);
33 
34  Trandom dfrac;
35  auto l = m_HistoBorders.GetBinLength(ibin);
36  Trandom dfracprev;
37  auto lprev = l;
38  if (ibin > 0) {
39  Trandom fracprev = m_HistoContents.get_fraction(ibin - 1);
40  dfrac = frac - fracprev;
41  if (ibin > 1)
42  dfracprev = fracprev - m_HistoContents.get_fraction(ibin - 2);
43  else
44  dfracprev = fracprev;
45  lprev = m_HistoBorders.GetBinLength(ibin - 1);
46  } else {
47  dfrac = frac;
48  dfracprev = dfrac;
49  }
50 
51  Trandom dfracnext;
52  auto lnext = l;
53  if (ibin < nbins - 1) {
54  dfracnext = m_HistoContents.get_fraction(ibin + 1) - frac;
55  lnext = m_HistoBorders.GetBinLength(ibin + 1);
56  } else {
57  dfracnext = dfrac;
58  }
59 
60  Trandom m;
61  if (dfrac > 0) {
62  /*
63  //approximately readable version of the code below
64  //density in bin is dfracX/lX
65  Trandom mnext=dfracnext/lnext-dfrac/l; //change in density to next bin
66  mnext/=0.5*(l+lnext); //normalize change in density to distance between
67  bins Trandom mprev=dfrac/l-dfracprev/lprev; //change in density to
68  previous bin mprev/=0.5*(l+lprev); //normalize change in density to
69  distance between bins m=0.5*(mnext+mprev); //average the two m*=l; //m is
70  needed inside this bin, so multiply by size of this bin (matches
71  normalization to distance between bins above) m/=dfrac/l; //finally, m is
72  the slope in this bin, given that this bin was already selected. So
73  overall normalize to density inside this bin
74  */
75  Trandom mnext = dfracnext / lnext - dfrac / l;
76  mnext /= l + lnext;
77  Trandom mprev = dfrac / l - dfracprev / lprev;
78  mprev /= l + lprev;
79  m = (mnext + mprev) * l * l / dfrac;
80  } else
81  m = 0;
82 
83  // ATH_MSG_INFO( fx="<<m_HistoBorders.GetBinLowEdge(ibin)<<"
84  // frac="<<m_HistoContents.get_fraction(ibin)<<" dfracprev="<<dfracprev<<"
85  // dfrac="<<dfrac<<" dfracnext="<<dfracnext<<"
86  // dfracprev-dfrac="<<dfracprev-dfrac<<"
87  // dfracnext-dfrac="<<dfracnext-dfrac<<" m="<<m<<"
88  // residual_rnd="<<residual_rnd);
89  return m_HistoBorders.position_lin(ibin, m, residual_rnd);
90  }
91 
93  1) // TFCS1DFunctionTemplateInterpolationHistogram
94 };
95 
98  TFCS1DFunction_HistogramInt8BinEdges, uint8_t, float> {
99 public:
103 
105  1) // TFCS1DFunctionInt8Int8InterpolationHistogram
106 };
107 
110  TFCS1DFunction_HistogramInt8BinEdges, uint16_t, float> {
111 public:
115 
117  1) // TFCS1DFunctionInt8Int16InterpolationHistogram
118 };
119 
122  TFCS1DFunction_HistogramInt16BinEdges, uint16_t, float> {
123 public:
127 
129  1) // TFCS1DFunctionInt16Int16InterpolationHistogram
130 };
131 
134  TFCS1DFunction_HistogramInt16BinEdges, uint32_t, float> {
135 public:
139 
141  1) // TFCS1DFunctionInt16Int32InterpolationHistogram
142 };
143 
144 #if defined(__ROOTCLING__) && defined(__FastCaloSimStandAlone__)
145 #pragma link C++ class TFCS1DFunctionTemplateInterpolationHistogram < \
146  TFCS1DFunction_HistogramInt8BinEdges, \
147  uint8_t, float> + \
148  ;
149 #pragma link C++ class TFCS1DFunctionTemplateInterpolationHistogram < \
150  TFCS1DFunction_HistogramInt8BinEdges, \
151  uint16_t, float> + \
152  ;
153 #pragma link C++ class TFCS1DFunctionTemplateInterpolationHistogram < \
154  TFCS1DFunction_HistogramInt16BinEdges, \
155  uint16_t, float> + \
156  ;
157 #pragma link C++ class TFCS1DFunctionTemplateInterpolationHistogram < \
158  TFCS1DFunction_HistogramInt16BinEdges, \
159  uint32_t, float> + \
160  ;
161 
162 #pragma link C++ class TFCS1DFunctionInt8Int8InterpolationHistogram + ;
163 #pragma link C++ class TFCS1DFunctionInt8Int16InterpolationHistogram + ;
164 #pragma link C++ class TFCS1DFunctionInt16Int16InterpolationHistogram + ;
165 #pragma link C++ class TFCS1DFunctionInt16Int32InterpolationHistogram + ;
166 
167 #endif
168 
169 #endif
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
TFCS1DFunction_HistogramInt16BinEdges
Definition: TFCS1DFunctionTemplateHelpers.h:517
plotmaker.hist
hist
Definition: plotmaker.py:148
TFCS1DFunctionInt8Int8InterpolationHistogram
Definition: TFCS1DFunctionTemplateInterpolationHistogram.h:98
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
TFCS1DFunctionTemplateHistogram.h
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
TFCS1DFunctionInt16Int16InterpolationHistogram
Definition: TFCS1DFunctionTemplateInterpolationHistogram.h:122
TFCS1DFunctionTemplateInterpolationHistogram::TFCS1DFunctionTemplateInterpolationHistogram
TFCS1DFunctionTemplateInterpolationHistogram(TH1 *hist=nullptr)
Definition: TFCS1DFunctionTemplateInterpolationHistogram.h:14
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
TFCS1DFunctionInt8Int16InterpolationHistogram::TFCS1DFunctionInt8Int16InterpolationHistogram
TFCS1DFunctionInt8Int16InterpolationHistogram(TH1 *h=nullptr)
Definition: TFCS1DFunctionTemplateInterpolationHistogram.h:112
TFCS1DFunctionTemplateHistogram< Txvec, Ty, float >::get_nbins
size_t get_nbins() const
return number of bins
Definition: TFCS1DFunctionTemplateHistogram.h:40
TFCS1DFunctionTemplateHistogram< Txvec, Ty, float >::m_HistoBorders
Txvec m_HistoBorders
Definition: TFCS1DFunctionTemplateHistogram.h:139
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
TFCS1DFunctionInt16Int32InterpolationHistogram::TFCS1DFunctionInt16Int32InterpolationHistogram
TFCS1DFunctionInt16Int32InterpolationHistogram(TH1 *h=nullptr)
Definition: TFCS1DFunctionTemplateInterpolationHistogram.h:136
checkxAOD.frac
frac
Definition: Tools/PyUtils/bin/checkxAOD.py:257
TFCS1DFunction_HistogramContent::get_bin
size_t get_bin(Trandom drnd, Trandom &residual_rnd) const
Get the matching bin for a given random value in the range [0,1).
Definition: TFCS1DFunctionTemplateHelpers.h:208
TFCS1DFunction_HistogramInt8BinEdges
Definition: TFCS1DFunctionTemplateHelpers.h:507
TFCS1DFunctionTemplateHistogram< Txvec, Ty, float >::m_HistoContents
TFCS1DFunction_HistogramContent< Ty, float > m_HistoContents
Definition: TFCS1DFunctionTemplateHistogram.h:143
TFCS1DFunctionInt16Int32InterpolationHistogram
Definition: TFCS1DFunctionTemplateInterpolationHistogram.h:134
TFCS1DFunction_HistogramContent::get_fraction
Trandom get_fraction(size_t pos) const
Get the cumulative content at bin pos as fraction in the range [0,1].
Definition: TFCS1DFunctionTemplateHelpers.h:178
TFCS1DFunctionTemplateInterpolationHistogram
Definition: TFCS1DFunctionTemplateInterpolationHistogram.h:12
TFCS1DFunctionInt16Int16InterpolationHistogram::TFCS1DFunctionInt16Int16InterpolationHistogram
TFCS1DFunctionInt16Int16InterpolationHistogram(TH1 *h=nullptr)
Definition: TFCS1DFunctionTemplateInterpolationHistogram.h:124
TFCS1DFunctionTemplateInterpolationHistogram::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: TFCS1DFunctionTemplateInterpolationHistogram.h:25
h
TFCS1DFunctionInt8Int8InterpolationHistogram::TFCS1DFunctionInt8Int8InterpolationHistogram
TFCS1DFunctionInt8Int8InterpolationHistogram(TH1 *h=nullptr)
Definition: TFCS1DFunctionTemplateInterpolationHistogram.h:100
TFCS1DFunctionTemplateHistogram
Definition: TFCS1DFunctionTemplateHistogram.h:15
readCCLHist.float
float
Definition: readCCLHist.py:83
TFCS1DFunctionInt8Int16InterpolationHistogram
Definition: TFCS1DFunctionTemplateInterpolationHistogram.h:110