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*);
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>
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>
257 template <
unsigned int NGaus>
276 template <
unsigned int MaxGaus = 10>
283 details::CompiledGausFitCacheBaseStruct(new_name)
284 { InitializeCompiledGausFitVector<MaxGaus>(); }
309 template <
unsigned int MaxGaus = 10,
unsigned int CutOff = 5>
313 template <
unsigned int NGaus>
320 (std::string new_name =
"CompiledTruncatedGausFitCache"):
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
362 (Double_t
const*
x, Double_t
const* params)
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>
385 AppendFunction<NGaus>();
391 CompiledGausFitCacheBaseStruct::InitializeCompiledGausFitVector<0>()
392 { AppendFunction<0>(); }
395 template <
unsigned int NGaus>
399 (
new TF1(
FunctionName(NGaus).c_str(), &ngaus<NGaus>, 0., 1., 3*NGaus));
403 template <
unsigned int CutOff>
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))?
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.
process_name opflash particleana ie ie ie z
constexpr unsigned int StoredMaxGaussians() const
Returns the maximum number of Gaussians in a function that we support.
std::vector< TF1 * > funcs
static Double_t gaus(Double_t const *x, Double_t const *params)
Single Gaussian function.
process_name opflash particleana ie x
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.
static void fill(CompiledGausFitCacheBaseStruct &cache)
CompiledGausFitCache(std::string new_name="CompiledGausFitCache")
Constructor: initializes all the functions.
virtual TF1 * CreateFunction(size_t nGaus) const
Throws an error, since this class can't create functions run-time.
virtual TF1 * GetClone(size_t nGaus)
Throws an exception (ROOT does not support cloning compiled 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.
void AppendFunction()
Adds one function.
Struct with member type corresponding to the NArg-th type from Args.
void CannotCreateFunction(size_t nGaus) const
Throws an error asserting compiled functions can't be cretead run-time.
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.
static Double_t ngaus(Double_t const *x, Double_t const *params)
static Double_t gaus_trunc(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.
virtual TF1 * CreateFunction(size_t nGaus) const
Throws an error, since this class can't create functions run-time.
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.
void InitializeCompiledGausFitVector()
Returns a vector initialized with multigaussians.
static Double_t eval(Double_t const *, Double_t const *)
static constexpr unsigned int NParams
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)