LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
hit::details::CompiledGausFitCacheBaseStruct Class Reference

#include "GausFitCache.h"

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

Classes

struct  InitializeFuncSumVector
 A helper class initializing the function vector. More...
 
struct  InitializeFuncSumVector< 0U, Func >
 

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

virtual TF1 * GetClone (size_t nGaus)
 Throws an exception (ROOT does not support cloning compiled functions) More...
 
virtual unsigned int MaxGaussians () const
 Returns the maximum number of Gaussians in a function that we support. More...
 
template<>
Double_t ngaus (Double_t const *, Double_t const *)
 
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

template<unsigned int NGaus>
void InitializeCompiledGausFitVector ()
 Returns a vector initialized with multigaussians. More...
 
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...
 
template<>
void InitializeCompiledGausFitVector ()
 
virtual TF1 * CreateFunction (size_t nFunc) const
 Creates a new sum function. More...
 

Protected Attributes

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

Detailed Description

Definition at line 136 of file GausFitCache.h.

Member Typedef Documentation

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

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

Definition at line 206 of file GausFitCache.h.

Member Function Documentation

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

Adds one function.

Definition at line 358 of file GausFitCache.h.

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

359  {
360  // create a function in the ficticious range [ 0, 1 ]:
361  funcs.push_back(new TF1(FunctionName(NGaus).c_str(), &ngaus<NGaus>, 0., 1., 3 * NGaus));
362  } // CompiledGausFitCacheBaseStruct::AppendFunction()
std::vector< TF1 * > funcs
Definition: GausFitCache.h:80
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
protected

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

Definition at line 104 of file GausFitCache.cxx.

References art::errors::LogicError, and hit::GausFitCache::name.

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

Creates a new sum function.

Reimplemented in hit::CompiledTruncatedGausFitCache< MaxGaus, CutOff >, hit::CompiledGausFitCache< MaxGaus >, and reco_tool::BaselinedGausFitCache.

Definition at line 65 of file GausFitCache.cxx.

References hit::GausFitCache::FunctionName().

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

66  {
67 
68  std::string func_name = FunctionName(nFunc);
69 
70  // no gaussian, no nothing
71  if (nFunc == 0) return new TF1(func_name.c_str(), "0");
72 
73  std::ostringstream sstr;
74  sstr << "gaus(0)";
75  for (size_t iGaus = 1; iGaus < nFunc; ++iGaus)
76  sstr << " + gaus(" << (iGaus * 3) << ")";
77 
78  // create and return the function
79  return new TF1(func_name.c_str(), sstr.str().c_str());
80  } // GausFitCache::CreateFunction()
virtual std::string FunctionName(size_t nFunc) const
Returns a name for the function with nFunc base functions.
std::string hit::GausFitCache::FunctionName ( size_t  nFunc) const
virtualinherited

Returns a name for the function with nFunc base functions.

Definition at line 83 of file GausFitCache.cxx.

References hit::GausFitCache::name.

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

84  {
85  std::ostringstream sstr;
86  sstr << name << "_" << nFunc;
87  return sstr.str();
88  } // GausFitCache::FunctionName()
std::string name
name of the cache
Definition: GausFitCache.h:77
Double_t hit::details::CompiledGausFitCacheBaseStruct::gaus ( Double_t const *  x,
Double_t const *  params 
)
static

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 93 of file GausFitCache.cxx.

References sqr().

94  {
95  return params[0] * std::exp(-0.5 * sqr((x[0] - params[1]) / params[2]));
96  } // 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 
)
static

Definition at line 365 of file GausFitCache.h.

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

366  {
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)) :
370  0.;
371  } // CompiledGausFitCacheBaseStruct::gaus_trunc()
Float_t x
Definition: compare.C:6
Double_t z
Definition: plot.C:276
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 44 of file GausFitCache.cxx.

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

Referenced by reco_tool::PeakFitterGaussian::findPeakParameters(), hit::GausFitCache::GetClone(), and hit::GausFitCache::GetName().

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

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

Reimplemented from hit::GausFitCache.

Definition at line 98 of file GausFitCache.cxx.

References art::errors::LogicError.

99  {
101  << "CompiledGausFitCacheBaseStruct: compiled functions can't be cloned";
102  } // 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 54 of file GausFitCache.h.

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

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

Returns a vector initialized with multigaussians.

Definition at line 345 of file GausFitCache.h.

346  {
347  if (NGaus > 0) InitializeCompiledGausFitVector<NGaus - 1>();
348  AppendFunction<NGaus>();
349  } // CompiledGausFitCacheBaseStruct::InitializeCompiledGausFitVector()
void InitializeCompiledGausFitVector()
Returns a vector initialized with multigaussians.
Definition: GausFitCache.h:345
template<>
void hit::details::CompiledGausFitCacheBaseStruct::InitializeCompiledGausFitVector ( )
inlineprotected

Definition at line 352 of file GausFitCache.h.

353  {
354  AppendFunction<0>();
355  }
virtual unsigned int hit::details::CompiledGausFitCacheBaseStruct::MaxGaussians ( ) const
inlinevirtual

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

Reimplemented in hit::CompiledTruncatedGausFitCache< MaxGaus, CutOff >, and hit::CompiledGausFitCache< MaxGaus >.

Definition at line 176 of file GausFitCache.h.

References hit::GausFitCache::funcs, and x.

176 { return funcs.size() - 1; }
std::vector< TF1 * > funcs
Definition: GausFitCache.h:80
template<unsigned int NGaus>
static Double_t hit::details::CompiledGausFitCacheBaseStruct::ngaus ( Double_t const *  x,
Double_t const *  params 
)
inlinestatic

Definition at line 192 of file GausFitCache.h.

References x.

193  {
194  return gaus(x, params) + ngaus<NGaus - 1>(x, params + 3);
195  }
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:192
template<>
Double_t hit::details::CompiledGausFitCacheBaseStruct::ngaus ( Double_t const *  ,
Double_t const *   
)
inline

Definition at line 374 of file GausFitCache.h.

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

Sum of NGaus Gaussian functions truncated at CutOff sigmas.

Definition at line 199 of file GausFitCache.h.

200  {
201  return FuncSum<NGaus, gaus_trunc<CutOff>, 3U>::eval(x, params);
202  }
Float_t x
Definition: compare.C:6

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 77 of file GausFitCache.h.

Referenced by CannotCreateFunction(), hit::GausFitCache::FunctionName(), and hit::GausFitCache::GetName().


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