5#ifndef ISF_FASTCALOSIMEVENT_TFCS1DFunctionTemplateHelpers_h
6#define ISF_FASTCALOSIMEVENT_TFCS1DFunctionTemplateHelpers_h
49 static constexpr uint16_t
MaxValue = UINT16_MAX;
66 static constexpr uint32_t
MaxValue = UINT32_MAX;
98 T *new_cont =
nullptr;
100 new_cont =
new T[
count];
102 size_t ncopy =
count;
146 b.ReadFastArray(m_content, m_size);
150 b.WriteFastArray(m_content, m_size);
156template <
typename T,
typename Trandom =
float>
164 :
m_array(nbins >= 1 ? nbins - 1 : 0){};
208 size_t get_bin(Trandom drnd, Trandom &residual_rnd)
const {
212 drnd = std::nextafter((Trandom)1.0, (Trandom)0.0);
222 basecont = *(it - 1);
228 T dcont = fullcont - basecont;
230 residual_rnd = ((Trandom)(
rnd - basecont)) / dcont;
231 if (residual_rnd > 1)
232 residual_rnd = std::nextafter((Trandom)1.0, (Trandom)0.0);
239 return std::distance(
m_array.begin(), it);
253template <
typename T,
typename Trandom =
float>
302 inline T
position(
size_t pos,
const Trandom &drnd)
const {
309 inline T
position_lin(
size_t pos, Trandom m,
const Trandom &drnd)
const {
316 ? (0.5 * std::sqrt(m * (m + 8 * drnd - 4) + 4) - 1) / m + 0.5
325 inline T
position_exp(
size_t pos, Trandom beta,
const Trandom &drnd)
const {
329 if (fabs(beta) < 1.0e-8)
330 return (1 -
z) * pos1 +
z * pos2;
336 z = 1 / beta * log(1.0 + drnd * (exp(beta * deltax) - 1.0)) / deltax;
340 return (1 -
z) * pos1 +
z * pos2;
375template <
typename T,
typename T
int,
typename Trandom =
float>
384 :
m_array(nbins >= 1 ? nbins - 1 : 0){};
447 inline T
position(
size_t pos,
const Trandom &drnd)
const {
450 return (1 - drnd) * pos1 + drnd * pos2;
460 inline T
position_lin(
size_t pos, Trandom m,
const Trandom &drnd)
const {
467 ? (0.5 * std::sqrt(m * (m + 8 * drnd - 4) + 4) - 1) / m + 0.5
471 return (1 -
x) * pos1 +
x * pos2;
478 inline T
position_exp(
size_t pos, Trandom beta,
const Trandom &drnd)
const {
482 if (fabs(beta) < 1.0e-8)
483 return (1 -
z) * pos1 +
z * pos2;
489 z = 1 / beta * log(1.0 + drnd * (exp(beta * deltax) - 1.0)) / deltax;
493 return (1 -
z) * pos1 +
z * pos2;
538#if defined(__ROOTCLING__) && defined(__FastCaloSimStandAlone__)
539#pragma link C++ class TFCS1DFunction_Numeric < uint8_t, float> + ;
540#pragma link C++ class TFCS1DFunction_Numeric < uint16_t, float> + ;
541#pragma link C++ class TFCS1DFunction_Numeric < uint32_t, float> + ;
542#pragma link C++ class TFCS1DFunction_Numeric < float, float> + ;
543#pragma link C++ class TFCS1DFunction_Numeric < double, float> + ;
544#pragma link C++ class TFCS1DFunction_Numeric < double, double> + ;
546#pragma link C++ class TFCS1DFunction_Array < float> - ;
547#pragma link C++ class TFCS1DFunction_Array < double> - ;
548#pragma link C++ class TFCS1DFunction_Array < uint8_t> - ;
549#pragma link C++ class TFCS1DFunction_Array < uint16_t> - ;
550#pragma link C++ class TFCS1DFunction_Array < uint32_t> - ;
552#pragma link C++ class TFCS1DFunction_HistogramContent < float, float> + ;
553#pragma link C++ class TFCS1DFunction_HistogramContent < double, float> + ;
554#pragma link C++ class TFCS1DFunction_HistogramContent < double, double> + ;
555#pragma link C++ class TFCS1DFunction_HistogramContent < uint8_t, float> + ;
556#pragma link C++ class TFCS1DFunction_HistogramContent < uint16_t, float> + ;
557#pragma link C++ class TFCS1DFunction_HistogramContent < uint32_t, float> + ;
559#pragma link C++ class TFCS1DFunction_HistogramBinEdges < float, float> + ;
560#pragma link C++ class TFCS1DFunction_HistogramBinEdges < double, float> + ;
561#pragma link C++ class TFCS1DFunction_HistogramBinEdges < double, double> + ;
563#pragma link C++ class TFCS1DFunction_HistogramCompactBinEdges < float, \
566#pragma link C++ class TFCS1DFunction_HistogramCompactBinEdges < float, \
569#pragma link C++ class TFCS1DFunction_HistogramCompactBinEdges < float, \
573#pragma link C++ class TFCS1DFunction_HistogramInt8BinEdges + ;
574#pragma link C++ class TFCS1DFunction_HistogramInt16BinEdges + ;
575#pragma link C++ class TFCS1DFunction_HistogramInt32BinEdges + ;
576#pragma link C++ class TFCS1DFunction_HistogramFloatBinEdges + ;
577#pragma link C++ class TFCS1DFunction_HistogramDoubleBinEdges + ;
uint32_t TFCS1DFunction_size_t
void resize(size_t count)
resize to given count, copying old content
TFCS1DFunction_Array(size_t count)
const T & operator[](size_t pos) const
TFCS1DFunction_size_t size_t
std::size_t MemorySizeArray() const
T * begin()
begin() iterators
std::size_t MemorySize() const
T * data()
Direct data pointer.
T & operator[](size_t pos)
Direct access operators.
void SetBinLowEdge(size_t pos, const T &value)
set position of lower edge of bins
T position_lin(size_t pos, Trandom m, const Trandom &drnd) const
return linearly interpolated position for bin pos, such that histograming the position gives a linear...
TFCS1DFunction_HistogramBinEdges(size_t nbins=0)
const T & GetBinLowEdge(size_t pos) const
get position of lower edge of bins
std::size_t MemorySize() const
std::size_t MemorySizeArray() const
T position_exp(size_t pos, Trandom beta, const Trandom &drnd) const
return exponetially interpolated position for bin pos, such that histograming the position gives a li...
void SetMinMax(const T &valuemin, const T &valuemax)
set minimum and maximum
size_t get_nbins() const
return number of bins
TFCS1DFunction_Array< T > m_array
void SetMax(const T &value)
set and get maximum
T position(size_t pos, const Trandom &drnd) const
return linear interpolated position for bin pos.
const T GetBinLength(size_t pos) const
get the length of a bin
void SetMin(const T &value)
set and get minimum
void set_nbins(size_t nbins)
set number of bins
TFCS1DFunction_size_t size_t
~TFCS1DFunction_HistogramBinEdges()
const T Length() const
Get length of interval of all bins.
void SetBinLowEdge(size_t pos, const T &value)
set position of lower edge of bins.
void SetMinMax(const T &valuemin, const T &valuemax)
set minimum and maximum
T position_exp(size_t pos, Trandom beta, const Trandom &drnd) const
return exponentially interpolated position for bin pos, such that histograming the position gives a l...
void set_nbins(size_t nbins)
set number of bins
TFCS1DFunction_size_t size_t
T position(size_t pos, const Trandom &drnd) const
return linear interpolated position for bin pos.
~TFCS1DFunction_HistogramCompactBinEdges()
const T GetBinLowEdge(size_t pos) const
get position of lower edge of bins.
const T GetBinLength(size_t pos) const
get the length of a bin
T position_lin(size_t pos, Trandom m, const Trandom &drnd) const
return interpolated position for bin pos, such that histograming the position gives a linear slope m,...
Tint internal_storage_type
std::size_t MemorySizeArray() const
void SetMin(const T &value)
set and get minimum
TFCS1DFunction_Array< Tint > m_array
std::size_t MemorySize() const
size_t get_nbins() const
return number of bins
TFCS1DFunction_HistogramCompactBinEdges(size_t nbins=0)
const T Length() const
Get length of interval of all bins.
void SetMax(const T &value)
set and get maximum
TFCS1DFunction_HistogramContent(size_t nbins=0)
Trandom get_binfraction(size_t pos) const
Get the content at bin pos as fraction in the range [0,1].
size_t get_bin(Trandom drnd, Trandom &residual_rnd) const
Get the matching bin for a given random value in the range [0,1).
Trandom get_fraction(size_t pos) const
Get the cumulative content at bin pos as fraction in the range [0,1].
void set_nbins(size_t nbins)
set number of bins.
void set_fraction(size_t pos, Trandom value)
Set the content of bin pos to a given value, where value is in the range [0,1].
std::size_t MemorySizeArray() const
TFCS1DFunction_Array< T > m_array
std::size_t MemorySize() const
size_t get_nbins() const
return number of bins.
TFCS1DFunction_size_t size_t
TFCS1DFunction_HistogramDoubleBinEdges(size_t nbins=0)
TFCS1DFunction_HistogramFloatBinEdges(size_t nbins=0)
TFCS1DFunction_HistogramInt16BinEdges(size_t nbins=0)
TFCS1DFunction_HistogramInt32BinEdges(size_t nbins=0)
TFCS1DFunction_HistogramInt8BinEdges(size_t nbins=0)
static uint16_t MaxCeilOnlyForInt(const Tfloat value)
static Tfloat ToNormalizedRange(const uint16_t value)
static uint16_t ExpandToMaxRange(const Tfloat value)
static constexpr uint16_t MaxValue
static constexpr Tfloat MaxValueFloat
static constexpr uint32_t MaxValue
static uint32_t MaxCeilOnlyForInt(const Tfloat value)
static constexpr Tfloat MaxValueFloat
static uint32_t ExpandToMaxRange(const Tfloat value)
static Tfloat ToNormalizedRange(const uint32_t value)
static constexpr uint8_t MaxValue
static Tfloat ToNormalizedRange(const uint8_t value)
static uint8_t ExpandToMaxRange(const Tfloat value)
static constexpr Tfloat MaxValueFloat
static uint8_t MaxCeilOnlyForInt(const Tfloat value)
Converter functions that does nothing for floats.
static Tfloat ToNormalizedRange(const T value)
static T ExpandToMaxRange(const Tfloat value)
static constexpr T MaxValue
static T MaxCeilOnlyForInt(const Tfloat value)
static constexpr Tfloat MaxValueFloat
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string