A function that can be added to a DataRep and used in a fitter. More...
#include <FunctionBase.h>
Public Member Functions | |
virtual void | addToComposite (FunctionBase *) |
Does nothing. | |
virtual FunctionBase * | clone () const |
Creates a new function object by copying an existing one. | |
virtual int | count () |
Returns 0. | |
virtual double | derivByParm (int i, double x) const |
Returns the function's derivative at the coordinate value x with respect to the i-th parameter. | |
virtual unsigned int | dimensions () const |
Returns the number of dimensions of the data coordinate. | |
virtual const std::vector < double > & | getParameters () const |
Returns the values of the parameters as a vector. | |
virtual bool | hasDerivatives () const |
Returns true if function can calculate its partial derivatives. | |
virtual void | initialParameters (const FunctionHelper *helper) |
Sets the FunctionHelper so that the function can calculate a reasonable set of initial parameter values. | |
virtual double | integrate (double lower_limit, double upper_limit) const |
Returns the integral of the function from the lower limit to the higher limit. | |
virtual bool | isComposite () const |
Returns false . | |
const std::string & | name () const |
Returns the name of the function. | |
virtual double | operator() (double x) const |
The function call operator. | |
virtual double | operator() (const std::vector< double > &v) const |
The function call operator for multi-dimension coordinate variable. | |
virtual const std::vector < std::string > & | parmNames () const |
Returns a reference to a vector of parameter names. | |
virtual void | removeFromComposite (FunctionBase *) |
Does nothing. | |
virtual void | setParameters (const std::vector< double > &incr) |
Sets the parameter values. | |
virtual std::vector< double > ::const_iterator | setParameters (std::vector< double >::const_iterator it) |
Sets the parameter values to the value pointed to by the iterator. | |
void | setParmNames (const std::vector< std::string > &names) |
Sets the names of the parameters. | |
virtual int | size () const |
Returns the number of parameters. | |
virtual | ~FunctionBase () |
The virtual destructor. |
Protected Member Functions | |
FunctionBase () | |
The default constructor. | |
FunctionBase (const FunctionBase &) | |
The copy constructor. | |
virtual void | initialize () |
Initializes the function and parameter names. | |
virtual void | resize () |
Re-sizes the appropriate vectors maintained in this base class. | |
void | setName (const char *) |
Sets the name of the function. |
Protected Attributes | |
std::string | m_name |
The name of the function. | |
std::vector< std::string > | m_parm_names |
The names of the function parameters. | |
std::vector< double > | m_parms |
The parameter values. |
A function that can be added to a DataRep and used in a fitter.
This is the base class for functions that can be added to a DataRep and used by a fitter. The initial value of the functions parameters can be set by a call to the initialParameters() member function. This function takes as argument a FunctionHelper which maybe connected to the data set. The function can make calls to the FunctionHelper to get some summaries from the data set and make an estimate of parameter values so that the function will at least appear on the DataRep if not come close to fitting it. This function must be implemented in a derived class.
The value of the function at a given value of the one dimensional coordinate x
, or multi-dimensional coordinates as vector of doubles is obtained by a call to the overloaded member function operator()(). This function must be implemented in a derived class.
To support a user interface, the name of the function may be obtained by a call to the name() member function and the name of the function's parameters from the parmNames() member function. The values of the function's parameters can be obtained by a call to the getParameters() member function. The number of parameters can be obtained by the size member function.
Internally, setting and receiving the parameters described above is done by the functions that take an iterator as an argument. The iterator skips over fixed parameters in both setting and receiving functions. This architecture is used to support the derived class LinearSumFunction.
Derived classes need to implement a few pure virtual functions defined by this class.
Once there conditions are satisfied, the class maybe added to the FunctionFactory for use in applications.
Definition at line 90 of file FunctionBase.h.
|
protected |
The default constructor.
Should never be called.
. Sets the function name to "nil". Should be overriden by derived class. If function name is "nil", then that indicated error condition that default constructor was called directly.
Definition at line 30 of file FunctionBase.cxx.
References FunctionBase::m_name.
|
protected |
The copy constructor.
Definition at line 39 of file FunctionBase.cxx.
|
virtual |
The virtual destructor.
Definition at line 46 of file FunctionBase.cxx.
|
virtual |
Does nothing.
Derived classes that are a composite of functions should override this member function and add functions to the composite.
Reimplemented in LinearSumFunction.
Definition at line 166 of file FunctionBase.cxx.
|
virtual |
Creates a new function object by copying an existing one.
The implementation raises an assertion as this member function should be reimplemented in s derived class.
Reimplemented in FunctionWrap, Landau, Erfc, Gaussian, LogNormal, Novosibirsk, LogParabola, LinearSumFunction, ConstantF, Quadratic, BrokenPowerLaw, Chi2Dist, Quadratic2, Exponential, Linear, and PowerLaw.
Definition at line 52 of file FunctionBase.cxx.
Referenced by LinearSumFunction::LinearSumFunction().
|
virtual |
Returns 0.
Derived classes that are a composite of functions should override this member function to return the number of functions in the composite.
Reimplemented in LinearSumFunction.
Definition at line 174 of file FunctionBase.cxx.
|
virtual |
Returns the function's derivative at the coordinate value x
with respect to the i-th
parameter.
Derived classes must implement this function.
Reimplemented in LinearSumFunction, Erfc, FunctionWrap, Gaussian, ConstantF, Quadratic, BrokenPowerLaw, Chi2Dist, Quadratic2, Exponential, Linear, PowerLaw, LogNormal, Novosibirsk, and LogParabola.
Definition at line 190 of file FunctionBase.cxx.
|
virtual |
Returns the number of dimensions of the data coordinate.
This implementation in the base class returns 1
. Derived class should override this function if the data coordinate is multi-dimensional.
Reimplemented in FunctionWrap.
Definition at line 213 of file FunctionBase.cxx.
|
virtual |
Returns the values of the parameters as a vector.
The function is non-const because a derived class may need to create the vector.
Reimplemented in LinearSumFunction.
Definition at line 99 of file FunctionBase.cxx.
References FunctionBase::m_parms.
Referenced by FunctionProjector::saveParameters(), and FunctionProjector::setParameters().
|
virtual |
Returns true
if function can calculate its partial derivatives.
This base class implementation returns true
. Derived class that can not calculate its partial derivatives should return false
. This allows an application to not attempt to use a minimizer that requires derivatives to use this function.
Reimplemented in FunctionWrap, Landau, LogNormal, Novosibirsk, and LogParabola.
Definition at line 126 of file FunctionBase.cxx.
|
protectedvirtual |
Initializes the function and parameter names.
The derived classes should initialize their names and the vector of parameter names and then invoke the resize() member function.
Reimplemented in FunctionWrap, Landau, Erfc, Gaussian, LogNormal, Novosibirsk, LinearSumFunction, LogParabola, Chi2Dist, ConstantF, Quadratic, BrokenPowerLaw, Quadratic2, Exponential, Linear, and PowerLaw.
Definition at line 198 of file FunctionBase.cxx.
|
virtual |
Sets the FunctionHelper so that the function can calculate a reasonable set of initial parameter values.
Reimplemented in FunctionWrap, LinearSumFunction, Landau, Erfc, Gaussian, LogNormal, Novosibirsk, LogParabola, ConstantF, Quadratic, BrokenPowerLaw, Chi2Dist, Quadratic2, Exponential, Linear, and PowerLaw.
Definition at line 60 of file FunctionBase.cxx.
Referenced by FunctionProjector::initializeFunction().
|
virtual |
Returns the integral of the function from the lower limit to the higher limit.
As of now all the integration is done here numerically using the trapezoidal rule. Derived class may implement an analytical expression in place of this numerical method.
Definition at line 138 of file FunctionBase.cxx.
References FunctionBase::operator()().
|
virtual |
Returns false
.
Derived classes that are a composite of functions should override this member function and return true
.
Reimplemented in LinearSumFunction.
Definition at line 161 of file FunctionBase.cxx.
const string & name | ( | ) | const |
Returns the name of the function.
Definition at line 81 of file FunctionBase.cxx.
References FunctionBase::m_name.
Referenced by FunctionController::functionNames(), FunctionProjector::getTitle(), FunctionProjector::getYLabel(), LinearSumFunction::parmNames(), and FunctionBase::setName().
|
virtual |
The function call operator.
Reimplemented in FunctionWrap, LinearSumFunction, Landau, Erfc, Gaussian, LogNormal, Novosibirsk, LogParabola, ConstantF, Quadratic, BrokenPowerLaw, Chi2Dist, Quadratic2, Exponential, Linear, and PowerLaw.
Definition at line 205 of file FunctionBase.cxx.
Referenced by FunctionBase::integrate(), and FunctionBase::operator()().
|
virtual |
The function call operator for multi-dimension coordinate variable.
Returns the value of the function at coordinate represented by v. The implementation in this base class uses the first element of the vector and calls operator () ( double ).
Reimplemented in FunctionWrap.
Definition at line 181 of file FunctionBase.cxx.
References FunctionBase::operator()().
|
virtual |
Returns a reference to a vector of parameter names.
Reimplemented in LinearSumFunction.
Definition at line 86 of file FunctionBase.cxx.
References FunctionBase::m_parm_names.
|
virtual |
Does nothing.
Derived classes that are a composite of functions should override this member function and remove functions from the composite.
Reimplemented in LinearSumFunction.
Definition at line 170 of file FunctionBase.cxx.
|
protectedvirtual |
Re-sizes the appropriate vectors maintained in this base class.
Derived classes should call this member function after initializing the m_parm_names data member, as the new size is taken from that data member's size.
Definition at line 71 of file FunctionBase.cxx.
References FunctionBase::m_parm_names, FunctionBase::m_parms, and FunctionBase::size().
Referenced by LogNormal::initialize(), Novosibirsk::initialize(), FunctionWrap::initialize(), FunctionWrap::setParmNames(), and FunctionBase::setParmNames().
|
protected |
Sets the name of the function.
Definition at line 66 of file FunctionBase.cxx.
References FunctionBase::m_name, and FunctionBase::name().
|
virtual |
Sets the parameter values.
Derived classes should implement this function by invoking incrementValues ( vector< double >::const_iterator ) so that they correctly work with the LinearSumFunction class.
Definition at line 106 of file FunctionBase.cxx.
Referenced by FunctionProjector::restoreParameters(), and FunctionProjector::setParameters().
|
virtual |
Sets the parameter values to the value pointed to by the iterator.
Returns an iterator to a data element one past the last used data element.
Reimplemented in LinearSumFunction.
Definition at line 114 of file FunctionBase.cxx.
References FunctionBase::m_parms, and FunctionBase::size().
void setParmNames | ( | const std::vector< std::string > & | names | ) |
Sets the names of the parameters.
Reimplemented in FunctionWrap.
Definition at line 93 of file FunctionBase.cxx.
References FunctionBase::m_parm_names, and FunctionBase::resize().
|
virtual |
Returns the number of parameters.
Reimplemented in LinearSumFunction.
Definition at line 156 of file FunctionBase.cxx.
References FunctionBase::m_parm_names.
Referenced by Novosibirsk::initialParameters(), FunctionWrap::operator()(), FunctionBase::resize(), and FunctionBase::setParameters().
|
protected |
The name of the function.
Definition at line 103 of file FunctionBase.h.
Referenced by FunctionBase::FunctionBase(), LinearSumFunction::initialize(), Novosibirsk::initialize(), LogNormal::initialize(), FunctionBase::name(), and FunctionBase::setName().
|
protected |
The names of the function parameters.
Definition at line 106 of file FunctionBase.h.
Referenced by LogNormal::initialize(), Novosibirsk::initialize(), LinearSumFunction::parmNames(), FunctionBase::parmNames(), FunctionBase::resize(), FunctionWrap::setParmNames(), FunctionBase::setParmNames(), and FunctionBase::size().
|
protected |
The parameter values.
Definition at line 109 of file FunctionBase.h.
Referenced by Erfc::calcRed(), LinearSumFunction::getParameters(), FunctionBase::getParameters(), LogNormal::initialParameters(), Novosibirsk::initialParameters(), LogNormal::LogNormal(), Novosibirsk::Novosibirsk(), LogNormal::operator()(), Novosibirsk::operator()(), FunctionBase::resize(), and FunctionBase::setParameters().