All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
hit::GausFitCache Class Reference

A set of TF1 linear sum of base functions (Gaussians) More...

#include <GausFitCache.h>

Inheritance diagram for hit::GausFitCache:
hit::details::CompiledGausFitCacheBaseStruct hit::ICARUShitFitCache hit::ICARUSlongHitFitCache reco_tool::BaselinedGausFitCache hit::CompiledGausFitCache< MaxGaus > hit::CompiledTruncatedGausFitCache< MaxGaus, CutOff >

Public Member Functions

 GausFitCache (std::string new_name="GausFitCache")
 Constructor; optionally set the name of the repository. More...
 
virtual ~GausFitCache ()
 Destructor. More...
 
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 TF1 * GetClone (size_t nGaus)
 
virtual std::string FunctionName (size_t nFunc) const
 Returns a name for the function with nFunc base functions. More...
 

Protected Member Functions

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

A set of TF1 linear sum of base functions (Gaussians)


This object holds and owns a number of functions that are linear sum of "base" functions. The original use is for Gaussian functions, and this class implements Gaussians as base functions. This class is used as a base class for other function caches that do not necessarily use Gaussian base functions.

The idea is that if you need a temporary function to perform a fit and extract the parameters, you can reuse the same function over and over rather than creating a new one each time.

The expected use for an algorithm is to have one of these caches as a data member and when the algorithm code needs a function it obtains it with:

TF1* pFunc = fitcache.Get(nGaussians);

Then pFunc is used for fitting but never destroyed.

Definition at line 46 of file GausFitCache.h.

Constructor & Destructor Documentation

hit::GausFitCache::GausFitCache ( std::string  new_name = "GausFitCache")
inline

Constructor; optionally set the name of the repository.

Definition at line 49 of file GausFitCache.h.

49 : name(new_name) {}
std::string name
name of the cache
Definition: GausFitCache.h:79
hit::GausFitCache::~GausFitCache ( )
virtual

Destructor.

Definition at line 36 of file GausFitCache.cxx.

36  {
37  std::for_each
38  (funcs.begin(), funcs.end(), std::default_delete<TF1>());
39  } // GausFitCache::~GausFitCache()
std::vector< TF1 * > funcs
Definition: GausFitCache.h:82

Member Function Documentation

TF1 * hit::GausFitCache::CreateFunction ( size_t  nFunc) const
protectedvirtual

Creates a new sum function.

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

Definition at line 62 of file GausFitCache.cxx.

62  {
63 
64  std::string func_name = FunctionName(nFunc);
65 
66  // no gaussian, no nothing
67  if (nFunc == 0) return new TF1(func_name.c_str(), "0");
68 
69  std::ostringstream sstr;
70  sstr << "gaus(0)";
71  for (size_t iGaus = 1; iGaus < nFunc; ++iGaus)
72  sstr << " + gaus(" << (iGaus*3) << ")";
73 
74  // create and return the function
75  return new TF1(func_name.c_str(), sstr.str().c_str());
76  } // 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
virtual

Returns a name for the function with nFunc base functions.

Definition at line 80 of file GausFitCache.cxx.

80  {
81  std::ostringstream sstr;
82  sstr << name << "_" << nFunc;
83  return sstr.str();
84  } // GausFitCache::FunctionName()
std::string name
name of the cache
Definition: GausFitCache.h:79
TF1 * hit::GausFitCache::Get ( size_t  nFunc)
virtual

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

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

Returns a new function sum of nFunc base functions (caller needs to set limits and parameters)

Reimplemented in hit::details::CompiledGausFitCacheBaseStruct.

Definition at line 57 of file GausFitCache.cxx.

58  { return static_cast<TF1*>(Get(nFunc)->Clone()); }
virtual TF1 * Get(size_t nFunc)
Returns a function sum of nFunc base functions.
std::string hit::GausFitCache::GetName ( ) const
inline

Return the name of this cache.

Definition at line 55 of file GausFitCache.h.

55 { return name; }
std::string name
name of the cache
Definition: GausFitCache.h:79

Member Data Documentation

std::vector<TF1*> hit::GausFitCache::funcs
protected

Definition at line 82 of file GausFitCache.h.

std::string hit::GausFitCache::name
protected

name of the cache

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

Definition at line 79 of file GausFitCache.h.


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