12 #ifndef GAUSFITCACHE_H 13 #define GAUSFITCACHE_H 1 72 virtual TF1*
Get(
size_t nFunc);
98 inline T
sqr(T v) {
return v*v; }
102 template <
unsigned int NArg,
typename FirstArg,
typename... Args>
109 template <
unsigned int NArg,
typename... Args>
132 Double_t Func(Double_t
const*, Double_t
const*),
133 unsigned int NFuncParams
136 static Double_t eval(Double_t
const*, Double_t
const*);
137 static constexpr
unsigned int NParams = NFunc * NFuncParams;
142 Double_t Func(Double_t
const*, Double_t
const*),
143 unsigned int NFuncParams
146 static Double_t eval(Double_t
const*, Double_t
const*);
147 static constexpr
unsigned int NParams = 0;
189 virtual TF1*
GetClone(
size_t nGaus);
203 static Double_t gaus(Double_t
const*
x, Double_t
const* params);
205 template <
unsigned int CutOff>
206 static Double_t gaus_trunc(Double_t
const* x, Double_t
const* params);
209 template <
unsigned int NGaus>
210 static Double_t
ngaus(Double_t
const* x, Double_t
const* params)
211 {
return gaus(x, params) + ngaus<NGaus-1>(
x, params + 3); }
215 template <
unsigned int NGaus,
unsigned int CutOff>
216 static Double_t
ngaus_trunc(Double_t
const* x, Double_t
const* params)
220 template <
unsigned int NGaus,
unsigned int CutOff>
244 template <
unsigned int NFunc,
template <
unsigned int>
class Func>
250 template <
template <
unsigned int>
class Func>
257 template <
unsigned int NGaus>
258 void InitializeCompiledGausFitVector();
261 template <
unsigned int NGaus>
262 void AppendFunction();
265 void CannotCreateFunction [[noreturn]] (
size_t nGaus)
const;
280 template <
unsigned int MaxGaus = 10>
287 details::CompiledGausFitCacheBaseStruct(new_name)
288 { InitializeCompiledGausFitVector<MaxGaus>(); }
290 virtual unsigned int MaxGaussians()
const {
return StoredMaxGaussians(); }
299 { CannotCreateFunction(nGaus); }
313 template <
unsigned int MaxGaus = 10,
unsigned int CutOff = 5>
317 template <
unsigned int NGaus>
324 (std::string new_name =
"CompiledTruncatedGausFitCache"):
331 virtual unsigned int MaxGaussians()
const {
return StoredMaxGaussians(); }
340 { CannotCreateFunction(nGaus); }
355 Double_t Func(Double_t
const*, Double_t
const*),
356 unsigned int NFuncParams
358 constexpr
unsigned int FuncSum<NFunc, Func, NFuncParams>::NParams;
362 Double_t Func(Double_t
const*, Double_t
const*),
363 unsigned int NFuncParams
365 Double_t FuncSum<NFunc, Func, NFuncParams>::eval
366 (Double_t
const*
x, Double_t
const* params)
368 return Func(x, params + NFuncParams*(NFunc-1))
375 Double_t Func(Double_t
const*, Double_t
const*),
376 unsigned int NFuncParams
379 (Double_t
const*, Double_t
const*)
386 template <
unsigned int NGaus>
387 void CompiledGausFitCacheBaseStruct::InitializeCompiledGausFitVector() {
388 if (NGaus > 0) InitializeCompiledGausFitVector<NGaus-1>();
389 AppendFunction<NGaus>();
395 CompiledGausFitCacheBaseStruct::InitializeCompiledGausFitVector<0>()
396 { AppendFunction<0>(); }
399 template <
unsigned int NGaus>
400 void CompiledGausFitCacheBaseStruct::AppendFunction() {
403 (
new TF1(
FunctionName(NGaus).c_str(), &ngaus<NGaus>, 0., 1., 3*NGaus));
407 template <
unsigned int CutOff>
408 Double_t CompiledGausFitCacheBaseStruct::gaus_trunc
409 (Double_t
const* x, Double_t
const* params)
411 const Double_t
z = (x[0] - params[1])/params[2];
412 return ((z > -((Double_t) CutOff)) && (z < (Double_t) CutOff))?
413 params[0] * std::exp(-0.5*
sqr(z)): 0.;
418 inline Double_t CompiledGausFitCacheBaseStruct::ngaus<0>
419 (Double_t
const*
x, Double_t
const* params)
426 template <
unsigned int NFunc,
template <
unsigned int>
class Func>
434 cache.
funcs.push_back(
new TF1(
436 0., 1., Func<NFunc>::NParams
441 template <
template <
unsigned int>
class Func>
446 cache.
funcs.push_back
447 (
new TF1(cache.
FunctionName(0).c_str(), Func<0U>::eval, 0., 1., 0));
460 #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.
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)