LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
hit::CompiledTruncatedGausFitCache< MaxGaus, CutOff > Class Template Reference

A set of TF1 linear sum of truncated Gaussians. More...

#include "GausFitCache.h"

Inheritance diagram for hit::CompiledTruncatedGausFitCache< MaxGaus, CutOff >:
hit::details::CompiledGausFitCacheBaseStruct hit::GausFitCache

Public Types

template<unsigned int NGaus, unsigned int CutOff>
using NGaussTruncClass = FuncSum< NGaus, gaus_trunc< CutOff >, 3U >
 Class around sum of NGaus Gaussian functions truncated at CutOff sigmas. More...
 

Public Member Functions

 CompiledTruncatedGausFitCache (std::string new_name="CompiledTruncatedGausFitCache")
 Constructor: initializes all the functions. More...
 
virtual unsigned int MaxGaussians () const
 Returns the maximum number of Gaussians in a function that we support. More...
 
constexpr unsigned int StoredMaxGaussians () const
 Returns the maximum number of Gaussians in a function that we support. More...
 
virtual TF1 * GetClone (size_t nGaus)
 Throws an exception (ROOT does not support cloning compiled functions) More...
 
template<>
Double_t ngaus (Double_t const *x, Double_t const *params)
 
std::string GetName () const
 Return the name of this cache. More...
 
virtual TF1 * Get (size_t nFunc)
 Returns a function sum of nFunc base functions. More...
 
virtual std::string FunctionName (size_t nFunc) const
 Returns a name for the function with nFunc base functions. More...
 

Static Public Member Functions

static Double_t gaus (Double_t const *x, Double_t const *params)
 Single Gaussian function. More...
 
template<unsigned int CutOff>
static Double_t gaus_trunc (Double_t const *x, Double_t const *params)
 
template<unsigned int NGaus>
static Double_t ngaus (Double_t const *x, Double_t const *params)
 
template<unsigned int NGaus, unsigned int CutOff>
static Double_t ngaus_trunc (Double_t const *x, Double_t const *params)
 Sum of NGaus Gaussian functions truncated at CutOff sigmas. More...
 

Protected Member Functions

virtual TF1 * CreateFunction (size_t nGaus) const
 Throws an error, since this class can't create functions run-time. More...
 
template<unsigned int NGaus>
void InitializeCompiledGausFitVector ()
 Returns a vector initialized with multigaussians. More...
 
template<>
void InitializeCompiledGausFitVector ()
 
template<unsigned int NGaus>
void AppendFunction ()
 Adds one function. More...
 
void CannotCreateFunction (size_t nGaus) const
 Throws an error asserting compiled functions can't be cretead run-time. More...
 

Protected Attributes

std::string name
 name of the cache More...
 
std::vector< TF1 * > funcs
 

Private Types

template<unsigned int NGaus>
using CutOffNGaussianClass = NGaussTruncClass< NGaus, CutOff >
 

Detailed Description

template<unsigned int MaxGaus = 10, unsigned int CutOff = 5>
class hit::CompiledTruncatedGausFitCache< MaxGaus, CutOff >

A set of TF1 linear sum of truncated Gaussians.


Template Parameters
MaxGausthe maximum number of Gaussians in the stored functions
CutOffnumber of sigmas beyond which the function evaluates as 0

This class stores a predefined number MaxGaus of TF1 from pre-compiled functions. Each function is the linear sum of truncated Gaussians, at most MaxGaus of them,

Definition at line 314 of file GausFitCache.h.

Member Typedef Documentation

template<unsigned int MaxGaus = 10, unsigned int CutOff = 5>
template<unsigned int NGaus>
using hit::CompiledTruncatedGausFitCache< MaxGaus, CutOff >::CutOffNGaussianClass = NGaussTruncClass<NGaus, CutOff>
private

Definition at line 318 of file GausFitCache.h.

template<unsigned int NGaus, unsigned int CutOff>
using hit::details::CompiledGausFitCacheBaseStruct::NGaussTruncClass = FuncSum<NGaus, gaus_trunc<CutOff>, 3U>
inherited

Class around sum of NGaus Gaussian functions truncated at CutOff sigmas.

Definition at line 221 of file GausFitCache.h.

Constructor & Destructor Documentation

template<unsigned int MaxGaus = 10, unsigned int CutOff = 5>
hit::CompiledTruncatedGausFitCache< MaxGaus, CutOff >::CompiledTruncatedGausFitCache ( std::string  new_name = "CompiledTruncatedGausFitCache< MaxGaus, CutOff >")
inline

Constructor: initializes all the functions.

Definition at line 324 of file GausFitCache.h.

References trkf::fill().

324  :
325  details::CompiledGausFitCacheBaseStruct(new_name)
326  {
328  }
static void fill(CompiledGausFitCacheBaseStruct &cache)
Definition: GausFitCache.h:429

Member Function Documentation

template<unsigned int NGaus>
void hit::details::CompiledGausFitCacheBaseStruct::AppendFunction ( )
protectedinherited

Adds one function.

Definition at line 400 of file GausFitCache.h.

References hit::GausFitCache::funcs, and hit::GausFitCache::FunctionName().

400  {
401  // create a function in the ficticious range [ 0, 1 ]:
402  funcs.push_back
403  (new TF1(FunctionName(NGaus).c_str(), &ngaus<NGaus>, 0., 1., 3*NGaus));
404  } // CompiledGausFitCacheBaseStruct::AppendFunction()
std::vector< TF1 * > funcs
Definition: GausFitCache.h:86
virtual std::string FunctionName(size_t nFunc) const
Returns a name for the function with nFunc base functions.
void hit::details::CompiledGausFitCacheBaseStruct::CannotCreateFunction ( size_t  nGaus) const
protectedinherited

Throws an error asserting compiled functions can't be cretead run-time.

Definition at line 102 of file GausFitCache.cxx.

References art::errors::LogicError.

103  {
105  << name << " function cache can't create functions at run-time; " << nFunc
106  << "-addend function was requested, but we have only functions with up to "
107  << MaxGaussians() << " addends available\n";
108  } // CompiledGausFitCache<>::CannotCreateFunction()
virtual unsigned int MaxGaussians() const
Returns the maximum number of Gaussians in a function that we support.
Definition: GausFitCache.h:192
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string name
name of the cache
Definition: GausFitCache.h:83
template<unsigned int MaxGaus = 10, unsigned int CutOff = 5>
virtual TF1* hit::CompiledTruncatedGausFitCache< MaxGaus, CutOff >::CreateFunction ( size_t  nGaus) const
inlineprotectedvirtual

Throws an error, since this class can't create functions run-time.

Reimplemented from hit::GausFitCache.

Definition at line 339 of file GausFitCache.h.

340  { CannotCreateFunction(nGaus); }
void CannotCreateFunction(size_t nGaus) const
Throws an error asserting compiled functions can&#39;t be cretead run-time.
std::string hit::GausFitCache::FunctionName ( size_t  nFunc) const
virtualinherited

Returns a name for the function with nFunc base functions.

Definition at line 78 of file GausFitCache.cxx.

Referenced by hit::details::CompiledGausFitCacheBaseStruct::AppendFunction(), hit::details::CompiledGausFitCacheBaseStruct::InitializeFuncSumVector< NFunc, Func >::fill(), hit::details::CompiledGausFitCacheBaseStruct::InitializeFuncSumVector< 0U, Func >::fill(), and hit::GausFitCache::GetName().

78  {
79  std::ostringstream sstr;
80  sstr << name << "_" << nFunc;
81  return sstr.str();
82  } // GausFitCache::FunctionName()
std::string name
name of the cache
Definition: GausFitCache.h:83
Double_t hit::details::CompiledGausFitCacheBaseStruct::gaus ( Double_t const *  x,
Double_t const *  params 
)
staticinherited

Single Gaussian function.

Parameters
xvector; [0] variable value
paramsvector: [0] coefficient of the exponent [1] mean [2] sigma
Returns
the Gaussian evaluated at *x

This function is equivalent to ROOT's "gaus".

Definition at line 89 of file GausFitCache.cxx.

References geo::sqr().

90  {
91  return params[0] * std::exp(-0.5*sqr((x[0] - params[1])/params[2]));
92  } // details::CompiledGausFitCacheBaseStruct::gaus()
Float_t x
Definition: compare.C:6
template<unsigned int CutOff>
Double_t hit::details::CompiledGausFitCacheBaseStruct::gaus_trunc ( Double_t const *  x,
Double_t const *  params 
)
staticinherited

Definition at line 409 of file GausFitCache.h.

References hit::details::sqr(), and z.

410  {
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.;
414  } // CompiledGausFitCacheBaseStruct::gaus_trunc()
Float_t x
Definition: compare.C:6
Double_t z
Definition: plot.C:279
TF1 * hit::GausFitCache::Get ( size_t  nFunc)
virtualinherited

Returns a function sum of nFunc base functions.

Parameters
nGausthe number of base functions in the function
Returns
a pointer to a TF1 with the required characteristics

The returned function must not be deleted at any time!

This implementation returns a function sum of nFunc Gaussians. The parameters are sorted by Gaussian: first normalization (not the area, but the coefficient), first mean, first sigma, second normalization etc.

Definition at line 41 of file GausFitCache.cxx.

Referenced by hit::GausFitCache::GetName().

41  {
42 
43  // expand the list if needed
44  if (nFunc >= funcs.size()) funcs.resize(nFunc + 1, nullptr);
45 
46  // get the pointer we need...
47  TF1*& pFunc = funcs[nFunc];
48 
49  if (!pFunc) pFunc = CreateFunction(nFunc);
50 
51  return pFunc;
52  } // GausFitCache::Get()
std::vector< TF1 * > funcs
Definition: GausFitCache.h:86
virtual TF1 * CreateFunction(size_t nFunc) const
Creates a new sum function.
TF1 * hit::details::CompiledGausFitCacheBaseStruct::GetClone ( size_t  nGaus)
virtualinherited

Throws an exception (ROOT does not support cloning compiled functions)

Reimplemented from hit::GausFitCache.

Definition at line 95 of file GausFitCache.cxx.

References art::errors::LogicError.

95  {
97  << "CompiledGausFitCacheBaseStruct: compiled functions can't be cloned";
98  } // CompiledGausFitCacheBaseStruct::GetClone()
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string hit::GausFitCache::GetName ( ) const
inlineinherited

Return the name of this cache.

Definition at line 59 of file GausFitCache.h.

References hit::GausFitCache::FunctionName(), hit::GausFitCache::Get(), hit::GausFitCache::GetClone(), and hit::GausFitCache::name.

59 { return name; }
std::string name
name of the cache
Definition: GausFitCache.h:83
template<unsigned int NGaus>
void hit::details::CompiledGausFitCacheBaseStruct::InitializeCompiledGausFitVector ( )
protectedinherited

Returns a vector initialized with multigaussians.

Definition at line 387 of file GausFitCache.h.

387  {
388  if (NGaus > 0) InitializeCompiledGausFitVector<NGaus-1>();
389  AppendFunction<NGaus>();
390  } // CompiledGausFitCacheBaseStruct::InitializeCompiledGausFitVector()
void InitializeCompiledGausFitVector()
Returns a vector initialized with multigaussians.
Definition: GausFitCache.h:387
template<>
void hit::details::CompiledGausFitCacheBaseStruct::InitializeCompiledGausFitVector ( )
inlineprotectedinherited

Definition at line 395 of file GausFitCache.h.

396  { AppendFunction<0>(); }
template<unsigned int MaxGaus = 10, unsigned int CutOff = 5>
virtual unsigned int hit::CompiledTruncatedGausFitCache< MaxGaus, CutOff >::MaxGaussians ( ) const
inlinevirtual

Returns the maximum number of Gaussians in a function that we support.

Reimplemented from hit::details::CompiledGausFitCacheBaseStruct.

Definition at line 331 of file GausFitCache.h.

331 { return StoredMaxGaussians(); }
constexpr unsigned int StoredMaxGaussians() const
Returns the maximum number of Gaussians in a function that we support.
Definition: GausFitCache.h:334
template<unsigned int NGaus>
static Double_t hit::details::CompiledGausFitCacheBaseStruct::ngaus ( Double_t const *  x,
Double_t const *  params 
)
inlinestaticinherited

Definition at line 210 of file GausFitCache.h.

References x.

211  { return gaus(x, params) + ngaus<NGaus-1>(x, params + 3); }
Float_t x
Definition: compare.C:6
static Double_t gaus(Double_t const *x, Double_t const *params)
Single Gaussian function.
static Double_t ngaus(Double_t const *x, Double_t const *params)
Definition: GausFitCache.h:210
template<>
Double_t hit::details::CompiledGausFitCacheBaseStruct::ngaus ( Double_t const *  x,
Double_t const *  params 
)
inlineinherited

Definition at line 419 of file GausFitCache.h.

References trkf::fill().

420  { return 0.; }
template<unsigned int NGaus, unsigned int CutOff>
static Double_t hit::details::CompiledGausFitCacheBaseStruct::ngaus_trunc ( Double_t const *  x,
Double_t const *  params 
)
inlinestaticinherited

Sum of NGaus Gaussian functions truncated at CutOff sigmas.

Definition at line 216 of file GausFitCache.h.

217  { return FuncSum<NGaus, gaus_trunc<CutOff>, 3U>::eval(x, params); }
Float_t x
Definition: compare.C:6
template<unsigned int MaxGaus = 10, unsigned int CutOff = 5>
constexpr unsigned int hit::CompiledTruncatedGausFitCache< MaxGaus, CutOff >::StoredMaxGaussians ( ) const
inline

Returns the maximum number of Gaussians in a function that we support.

Definition at line 334 of file GausFitCache.h.

334 { return MaxGaus; }

Member Data Documentation

std::string hit::GausFitCache::name
protectedinherited

name of the cache

Gaussian sum functions; n-th element is sum of n base functions

Definition at line 83 of file GausFitCache.h.

Referenced by hit::GausFitCache::GetName().


The documentation for this class was generated from the following file: