22 #include "canvas/Utilities/Exception.h"
27 inline T
sqr(T v) {
return v*v; }
38 (
funcs.begin(),
funcs.end(), std::default_delete<TF1>());
46 if (nFunc >=
funcs.size())
funcs.resize(nFunc + 1,
nullptr);
49 TF1*& pFunc =
funcs[nFunc];
58 {
return static_cast<TF1*
>(
Get(nFunc)->Clone()); }
67 if (nFunc == 0)
return new TF1(func_name.c_str(),
"0");
69 std::ostringstream sstr;
71 for (
size_t iGaus = 1; iGaus < nFunc; ++iGaus)
72 sstr <<
" + gaus(" << (iGaus*3) <<
")";
75 return new TF1(func_name.c_str(), sstr.str().c_str());
81 std::ostringstream sstr;
82 sstr <<
name <<
"_" << nFunc;
91 (Double_t
const*
x, Double_t
const* params)
93 return params[0] *
std::exp(-0.5*
sqr((x[0] - params[1])/params[2]));
98 throw art::Exception(art::errors::LogicError)
99 <<
"CompiledGausFitCacheBaseStruct: compiled functions can't be cloned";
106 throw art::Exception(art::errors::LogicError)
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 "
109 << MaxGaussians() <<
" addends available\n";
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.
virtual TF1 * GetClone(size_t nGaus)
Throws an exception (ROOT does not support cloning compiled functions)
virtual ~GausFitCache()
Destructor.
void CannotCreateFunction(size_t nGaus) const
Throws an error asserting compiled functions can't be cretead run-time.
virtual TF1 * Get(size_t nFunc)
Returns a function sum of nFunc base functions.
virtual std::string FunctionName(size_t nFunc) const
Returns a name for the function with nFunc base functions.
Provide caches for TF1 functions to be used with ROOT fitters.
std::string name
name of the cache
virtual TF1 * GetClone(size_t nGaus)