12 #ifndef GAUSFITCACHE_H 13 #define GAUSFITCACHE_H 1 21 #include "RtypesCore.h" 68 virtual TF1*
Get(
size_t nFunc);
94 inline T sqr(
T v) {
return v*v; }
98 template <
unsigned int NArg,
typename FirstArg,
typename... Args>
105 template <
unsigned int NArg,
typename... Args>
128 Double_t Func(Double_t
const*, Double_t
const*),
129 unsigned int NFuncParams
132 static Double_t eval(Double_t
const*, Double_t
const*);
133 static constexpr
unsigned int NParams = NFunc * NFuncParams;
138 Double_t Func(Double_t
const*, Double_t
const*),
139 unsigned int NFuncParams
142 static Double_t eval(Double_t
const*, Double_t
const*);
143 static constexpr
unsigned int NParams = 0;
185 virtual TF1*
GetClone(
size_t nGaus);
199 static Double_t
gaus(Double_t
const*
x, Double_t
const*
params);
201 template <
unsigned int CutOff>
202 static Double_t gaus_trunc(Double_t
const* x, Double_t
const* params);
205 template <
unsigned int NGaus>
206 static Double_t
ngaus(Double_t
const* x, Double_t
const* params)
207 {
return gaus(x, params) + ngaus<NGaus-1>(
x, params + 3); }
211 template <
unsigned int NGaus,
unsigned int CutOff>
212 static Double_t
ngaus_trunc(Double_t
const* x, Double_t
const* params)
216 template <
unsigned int NGaus,
unsigned int CutOff>
240 template <
unsigned int NFunc,
template <
unsigned int>
class Func>
246 template <
template <
unsigned int>
class Func>
253 template <
unsigned int NGaus>
254 void InitializeCompiledGausFitVector();
257 template <
unsigned int NGaus>
258 void AppendFunction();
261 void CannotCreateFunction [[noreturn]] (
size_t nGaus)
const;
276 template <
unsigned int MaxGaus = 10>
283 details::CompiledGausFitCacheBaseStruct(new_name)
284 { InitializeCompiledGausFitVector<MaxGaus>(); }
286 virtual unsigned int MaxGaussians()
const {
return StoredMaxGaussians(); }
295 { CannotCreateFunction(nGaus); }
309 template <
unsigned int MaxGaus = 10,
unsigned int CutOff = 5>
313 template <
unsigned int NGaus>
327 virtual unsigned int MaxGaussians()
const {
return StoredMaxGaussians(); }
336 { CannotCreateFunction(nGaus); }
351 Double_t Func(Double_t
const*, Double_t
const*),
352 unsigned int NFuncParams
354 constexpr
unsigned int FuncSum<NFunc, Func, NFuncParams>::NParams;
358 Double_t Func(Double_t
const*, Double_t
const*),
359 unsigned int NFuncParams
361 Double_t FuncSum<NFunc, Func, NFuncParams>::eval
364 return Func(x, params + NFuncParams*(NFunc-1))
371 Double_t Func(Double_t
const*, Double_t
const*),
372 unsigned int NFuncParams
375 (Double_t
const*, Double_t
const*)
382 template <
unsigned int NGaus>
383 void CompiledGausFitCacheBaseStruct::InitializeCompiledGausFitVector() {
384 if (NGaus > 0) InitializeCompiledGausFitVector<NGaus-1>();
385 AppendFunction<NGaus>();
391 CompiledGausFitCacheBaseStruct::InitializeCompiledGausFitVector<0>()
392 { AppendFunction<0>(); }
395 template <
unsigned int NGaus>
396 void CompiledGausFitCacheBaseStruct::AppendFunction() {
399 (
new TF1(
FunctionName(NGaus).c_str(), &ngaus<NGaus>, 0., 1., 3*NGaus));
403 template <
unsigned int CutOff>
404 Double_t CompiledGausFitCacheBaseStruct::gaus_trunc
405 (Double_t
const* x, Double_t
const* params)
407 const Double_t
z = (x[0] - params[1])/params[2];
408 return ((z > -((Double_t) CutOff)) && (z < (Double_t) CutOff))?
409 params[0] * std::exp(-0.5*
sqr(z)): 0.;
414 inline Double_t CompiledGausFitCacheBaseStruct::ngaus<0>
415 (Double_t
const*
x, Double_t
const* params)
422 template <
unsigned int NFunc,
template <
unsigned int>
class Func>
430 cache.
funcs.push_back(
new TF1(
432 0., 1., Func<NFunc>::NParams
437 template <
template <
unsigned int>
class Func>
442 cache.
funcs.push_back
443 (
new TF1(cache.
FunctionName(0).c_str(), Func<0U>::eval, 0., 1., 0));
456 #endif // GAUSFITCACHE_H virtual unsigned int MaxGaussians() const
Returns the maximum number of Gaussians in a function that we support.
constexpr unsigned int StoredMaxGaussians() const
Returns the maximum number of Gaussians in a function that we support.
std::vector< TF1 * > funcs
virtual TF1 * CreateFunction(size_t nFunc) const
Creates a new sum function.
static Double_t ngaus_trunc(Double_t const *x, Double_t const *params)
Sum of NGaus Gaussian functions truncated at CutOff sigmas.
CompiledGausFitCache(std::string new_name="CompiledGausFitCache")
Constructor: initializes all the functions.
A sum of NFunc base functions Func.
A set of TF1 linear sum of base functions (Gaussians)
virtual ~GausFitCache()
Destructor.
A set of TF1 linear sum of Gaussians.
A set of TF1 linear sum of truncated Gaussians.
T gaus(T x, T amplitude, T mean, T sigma)
Tests GausssianFit object with a known input.
A helper class initializing the function vector.
virtual unsigned int MaxGaussians() const
Returns the maximum number of Gaussians in a function that we support.
Struct with member type corresponding to the NArg-th type from Args.
virtual TF1 * Get(size_t nFunc)
Returns a function sum of nFunc base functions.
GausFitCache(std::string new_name="GausFitCache")
Constructor; optionally set the name of the repository.
Detector simulation of raw signals on wires.
static Double_t ngaus(Double_t const *x, Double_t const *params)
constexpr unsigned int StoredMaxGaussians() const
Returns the maximum number of Gaussians in a function that we support.
virtual std::string FunctionName(size_t nFunc) const
Returns a name for the function with nFunc base functions.
virtual unsigned int MaxGaussians() const
Returns the maximum number of Gaussians in a function that we support.
std::string GetName() const
Return the name of this cache.
Struct with member type corresponding to the NArg-th type from Args.
std::string name
name of the cache
virtual TF1 * GetClone(size_t nGaus)