ATLAS Offline Software
Loading...
Searching...
No Matches
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
10template <typename Txvec, typename Ty, typename Trandom = float>
12 : public TFCS1DFunctionTemplateHistogram<Txvec, Ty, Trandom> {
13public:
15 : TFCS1DFunctionTemplateHistogram<Txvec, Ty, Trandom>(hist){};
16
18 using TFCS1DFunctionTemplateHistogram<Txvec, Ty, Trandom>::get_nbins;
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> {
99public:
103
105 1) // TFCS1DFunctionInt8Int8InterpolationHistogram
106};
107
110 TFCS1DFunction_HistogramInt8BinEdges, uint16_t, float> {
111public:
115
117 1) // TFCS1DFunctionInt8Int16InterpolationHistogram
118};
119
122 TFCS1DFunction_HistogramInt16BinEdges, uint16_t, float> {
123public:
127
129 1) // TFCS1DFunctionInt16Int16InterpolationHistogram
130};
131
134 TFCS1DFunction_HistogramInt16BinEdges, uint32_t, float> {
135public:
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
static TRandom * rnd
Header file for AthHistogramAlgorithm.
TFCS1DFunction_HistogramContent< Ty, float > m_HistoContents
TFCS1DFunctionTemplateHistogram(TH1 *hist=nullptr, bool doprint=true)
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...
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...