12 #ifndef GAUSFITCACHE_H 13 #define GAUSFITCACHE_H 1 20 #include "RtypesCore.h" 67 virtual TF1*
Get(
size_t nFunc);
96 template <
unsigned int NArg,
typename FirstArg,
typename... Args>
102 template <
unsigned int NArg,
typename... Args>
121 template <
unsigned int NFunc,
122 Double_t Func(Double_t
const*, Double_t
const*),
123 unsigned int NFuncParams>
125 static Double_t eval(Double_t
const*, Double_t
const*);
126 static constexpr
unsigned int NParams = NFunc * NFuncParams;
130 template <Double_t Func(Double_t const*, Double_t const*),
unsigned int NFuncParams>
132 static Double_t eval(Double_t
const*, Double_t
const*);
133 static constexpr
unsigned int NParams = 0;
173 virtual TF1*
GetClone(
size_t nGaus);
186 static Double_t gaus(Double_t
const*
x, Double_t
const* params);
188 template <
unsigned int CutOff>
189 static Double_t gaus_trunc(Double_t
const* x, Double_t
const* params);
191 template <
unsigned int NGaus>
192 static Double_t
ngaus(Double_t
const* x, Double_t
const* params)
194 return gaus(x, params) + ngaus<NGaus - 1>(
x, params + 3);
198 template <
unsigned int NGaus,
unsigned int CutOff>
199 static Double_t
ngaus_trunc(Double_t
const* x, Double_t
const* params)
205 template <
unsigned int NGaus,
unsigned int CutOff>
227 template <
unsigned int NFunc,
template <
unsigned int>
class Func>
233 template <
template <
unsigned int>
class Func>
239 template <
unsigned int NGaus>
240 void InitializeCompiledGausFitVector();
243 template <
unsigned int NGaus>
244 void AppendFunction();
247 void CannotCreateFunction [[noreturn]] (
size_t nGaus)
const;
260 template <
unsigned int MaxGaus = 10>
265 :
details::CompiledGausFitCacheBaseStruct(new_name)
267 InitializeCompiledGausFitVector<MaxGaus>();
270 virtual unsigned int MaxGaussians()
const {
return StoredMaxGaussians(); }
277 virtual TF1*
CreateFunction [[noreturn]] (
size_t nGaus)
const { CannotCreateFunction(nGaus); }
290 template <
unsigned int MaxGaus = 10,
unsigned int CutOff = 5>
292 template <
unsigned int NGaus>
298 :
details::CompiledGausFitCacheBaseStruct(new_name)
303 virtual unsigned int MaxGaussians()
const {
return StoredMaxGaussians(); }
310 virtual TF1*
CreateFunction [[noreturn]] (
size_t nGaus)
const { CannotCreateFunction(nGaus); }
321 template <
unsigned int NFunc,
322 Double_t Func(Double_t
const*, Double_t
const*),
323 unsigned int NFuncParams>
324 constexpr
unsigned int FuncSum<NFunc, Func, NFuncParams>::NParams;
326 template <
unsigned int NFunc,
327 Double_t Func(Double_t
const*, Double_t
const*),
328 unsigned int NFuncParams>
331 return Func(x, params + NFuncParams * (NFunc - 1))
336 template <Double_t Func(Double_t const*, Double_t const*),
unsigned int NFuncParams>
344 template <
unsigned int NGaus>
345 void CompiledGausFitCacheBaseStruct::InitializeCompiledGausFitVector()
347 if (NGaus > 0) InitializeCompiledGausFitVector<NGaus - 1>();
348 AppendFunction<NGaus>();
352 inline void CompiledGausFitCacheBaseStruct::InitializeCompiledGausFitVector<0>()
357 template <
unsigned int NGaus>
358 void CompiledGausFitCacheBaseStruct::AppendFunction()
361 funcs.push_back(
new TF1(
FunctionName(NGaus).c_str(), &ngaus<NGaus>, 0., 1., 3 * NGaus));
364 template <
unsigned int CutOff>
365 Double_t CompiledGausFitCacheBaseStruct::gaus_trunc(Double_t
const*
x, Double_t
const* params)
367 const Double_t
z = (x[0] - params[1]) / params[2];
368 return ((z > -((Double_t)CutOff)) && (z < (Double_t)CutOff)) ?
369 params[0] * std::exp(-0.5 *
sqr(z)) :
374 inline Double_t CompiledGausFitCacheBaseStruct::ngaus<0>(Double_t
const* ,
382 template <
unsigned int NFunc,
template <
unsigned int>
class Func>
389 cache.
funcs.push_back(
new TF1(
390 cache.
FunctionName(NFunc).c_str(), Func<NFunc>::eval, 0., 1., Func<NFunc>::NParams));
393 template <
template <
unsigned int>
class Func>
397 cache.
funcs.push_back(
new TF1(cache.
FunctionName(0).c_str(), Func<0U>::eval, 0., 1., 0));
408 #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.
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.
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
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)
typename TemplateArgumentHelper< NArg-1, Args... >::type type
constexpr unsigned int StoredMaxGaussians() const
Returns the maximum number of Gaussians in a function that we support.
CompiledTruncatedGausFitCache(std::string new_name="CompiledTruncatedGausFitCache")
Constructor: initializes all the functions.
virtual std::string FunctionName(size_t nFunc) const
Returns a name for the function with nFunc base functions.
typename TemplateArgumentHelper< NArg, Args... >::type type
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)