Erfc Class Reference

#include <Erfc.h>

Inheritance diagram for Erfc:

Inheritance graph
FunctionBase
[legend]
Collaboration diagram for Erfc:

Collaboration graph
FunctionBase
[legend]
List of all members.

Detailed Description

A function that can be used with a fitter.

The function represents the Complementary Error Function distribution Erfc

\[ Erfc(x) = \frac{2}{\sqrt(\pi)} \int^{+\inf}_x \exp(-t^2)dt \]

The algorithm is based on a Chebyshev fit as denoted in Numerical Recipes 2nd ed. on p. 214 (W.H.Press et al.).

The fractional error is always less than 1.2e-7.

This code also allows to fit a data set with the Erfc distribution: we define

\[ t = \frac{x - m}{s} \]

, with x the data set variable. m and s (mean and sigma) are fit parameters PAR(1) and PAR(2) respectively. In this way the Erfc becomes related to the cumulative distribution function of a Gaussian. As a result, the concrete implemented formula is

\[ Erfc(x) = PAR(3) * \int^{+\inf}_{t} \exp(-u^2)du \]

.

In other words, this implementation evaluates Erfc at the reduced value $t$ so that a fit is possible. PAR(3) is a normalization parameter.

Author:
Johann Cohen-Tanugi <johann.cohen@pi.infn.it>

Definition at line 44 of file Erfc.h.

Public Member Functions

virtual void addToComposite (FunctionBase *)
 Does nothing.
double calcErfc (double x) const
virtual FunctionBaseclone () const
 Creates a new function object by copying an existing one.
virtual int count ()
 Returns 0.
virtual unsigned int dimensions () const
 Returns the number of dimensions of the data coordinate.
 Erfc (double mean, double sigma, double norm)
 This constructor takes the values of the parameters as an argument.
 Erfc ()
 The default constructor.
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)
 returns Erfc computed at the reduced variable $x = \frac{value-mean}{sigma}$ double Erfc::operator () (double value) const { double result = 1; // The return value
virtual double integrate (double lower_limit, double upper_limit) const
virtual bool isComposite () const
 Returns false.
const std::string & name () const
 Returns the name of the function.
virtual double operator() (const std::vector< double > &v) const
 The function call operator for multi-dimension coordinate variable.
virtual double operator() (double x) const
 The function call operator.
virtual const std::vector<
std::string > & 
parmNames () const
 Returns a reference to a vector of parameter names.
virtual void removeFromComposite (FunctionBase *)
 Does nothing.
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.
virtual void setParameters (const std::vector< double > &incr)
 Sets the parameter values.
void setParmNames (const std::vector< std::string > &names)
 Sets the names of the parameters.
virtual int size () const
 Returns the number of parameters.

Protected Member Functions

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.
double derivByRed (double value) const
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.

Private Types

enum  { MEAN, SIGMA, NORM }

Private Member Functions

double calcRed (double value) const
 compute the reduced variable: $x = \frac{value-mean}{sigma}$


Member Enumeration Documentation

anonymous enum [private]

Enumerator:
MEAN 
SIGMA 
NORM 

Definition at line 47 of file Erfc.h.


Constructor & Destructor Documentation

Erfc (  ) 

The default constructor.

Definition at line 33 of file Erfc.cxx.

References Erfc::initialize().

Referenced by Erfc::clone().

Erfc ( double  mean,
double  sigma,
double  norm 
)

This constructor takes the values of the parameters as an argument.

Definition at line 38 of file Erfc.cxx.

References Erfc::initialize(), FunctionBase::m_parms, Erfc::MEAN, Erfc::NORM, and Erfc::SIGMA.


Member Function Documentation

void addToComposite ( FunctionBase  )  [virtual, inherited]

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.

double calcErfc ( double  x  )  const

Definition at line 131 of file Erfc.cxx.

double calcRed ( double  value  )  const [inline, private]

compute the reduced variable: $x = \frac{value-mean}{sigma}$

Definition at line 77 of file Erfc.h.

References FunctionBase::m_parms.

Referenced by Erfc::derivByParm().

FunctionBase * clone (  )  const [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.

Note:
There's an implementation here to satisfy the SIP interface.

Reimplemented from FunctionBase.

Definition at line 58 of file Erfc.cxx.

References Erfc::Erfc().

int count (  )  [virtual, inherited]

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.

double derivByParm ( int  i,
double  x 
) const [protected, virtual]

Returns the function's derivative at the coordinate value x with respect to the i-th parameter.

Derived classes must implement this function.

Todo:
Provide a numeric method for doing this calculation that will be the default. Derived classes should provide more efficient analytic method if available.
Bug:
Make this function pure when problem compiling python/FunctionWrap under Windows is solved.

Reimplemented from FunctionBase.

Definition at line 88 of file Erfc.cxx.

References Erfc::calcRed(), Erfc::derivByRed(), FunctionBase::m_parms, Erfc::MEAN, Erfc::NORM, Erfc::operator()(), and Erfc::SIGMA.

double derivByRed ( double  value  )  const [protected]

Definition at line 118 of file Erfc.cxx.

Referenced by Erfc::derivByParm().

unsigned int dimensions (  )  const [virtual, inherited]

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.

Referenced by FunctionWrap::dimensions().

const vector< double > & getParameters (  )  const [virtual, inherited]

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 FunctionProjectorXML::createElement(), FuncParmRep::drawProjectedValues(), hippodraw::Python::export_FunctionBase(), FunctionRep::parameters(), FunctionProjector::saveParameters(), and FunctionProjector::setParameters().

bool hasDerivatives (  )  const [virtual, inherited]

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 LogNormal, LogParabola, Novosibirsk, and FunctionWrap.

Definition at line 126 of file FunctionBase.cxx.

void initialize (  )  [protected, virtual]

Initializes the function and parameter names.

Reimplemented from FunctionBase.

Definition at line 47 of file Erfc.cxx.

References FunctionBase::m_name, FunctionBase::m_parm_names, and FunctionBase::resize().

Referenced by Erfc::Erfc().

void initialParameters ( const FunctionHelper helper  )  [virtual]

returns Erfc computed at the reduced variable $x = \frac{value-mean}{sigma}$ double Erfc::operator () (double value) const { double result = 1; // The return value

double x = calcRed(value); //reduced variable

result = calcErfc(x); //this method is a copy of ROOT method in TMath.cxx

result *= m_parms[NORM];

return result; }

/* virtual

Reimplemented from FunctionBase.

Definition at line 80 of file Erfc.cxx.

References FunctionBase::m_parms, FunctionHelper::maxValue(), Erfc::MEAN, FunctionHelper::meanCoord(), Erfc::NORM, and Erfc::SIGMA.

double integrate ( double  lower_limit,
double  upper_limit 
) const [virtual, inherited]

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()().

bool isComposite (  )  const [virtual, inherited]

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.

Referenced by FunctionRep::isComposite(), FunctionController::restoreParameters(), and FunctionController::saveParameters().

const string & name (  )  const [inherited]

Returns the name of the function.

Definition at line 81 of file FunctionBase.cxx.

References FunctionBase::m_name.

Referenced by FunctionProjectorXML::createElement(), FunctionController::createNTuple(), hippodraw::Python::export_FunctionBase(), FunctionController::functionNames(), FunctionProjector::getTitle(), FunctionProjector::getYLabel(), and LinearSumFunction::parmNames().

double operator() ( const std::vector< double > &  v  )  const [virtual, inherited]

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 double operator() ( double  x  )  const [virtual]

The function call operator.

Reimplemented from FunctionBase.

Referenced by Erfc::derivByParm().

const vector< string > & parmNames (  )  const [virtual, inherited]

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.

Referenced by FuncParmRep::drawProjectedValues(), hippodraw::Python::export_FunctionBase(), and FunctionRep::parmNames().

void removeFromComposite ( FunctionBase  )  [virtual, inherited]

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.

void resize (  )  [protected, virtual, inherited]

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 Quadratic2::initialize(), Quadratic::initialize(), PowerLaw::initialize(), Novosibirsk::initialize(), LogParabola::initialize(), LogNormal::initialize(), Linear::initialize(), Landau::initialize(), Gaussian::initialize(), FunctionWrap::initialize(), Exponential::initialize(), Erfc::initialize(), ConstantF::initialize(), Chi2Dist::initialize(), BrokenPowerLaw::initialize(), FunctionWrap::setParmNames(), and FunctionBase::setParmNames().

void setName ( const char *   )  [protected, inherited]

Sets the name of the function.

Definition at line 66 of file FunctionBase.cxx.

References FunctionBase::m_name.

Referenced by FunctionWrap::setName().

vector< double >::const_iterator setParameters ( std::vector< double >::const_iterator  it  )  [virtual, inherited]

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 setParameters ( const std::vector< double > &  incr  )  [virtual, inherited]

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 hippodraw::Python::export_FunctionBase(), FunctionProjector::restoreParameters(), FunctionProjectorXML::setAttributes(), and FunctionProjector::setParameters().

void setParmNames ( const std::vector< std::string > &  names  )  [inherited]

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().

int size (  )  const [virtual, inherited]

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(), LogParabola::initialParameters(), Gaussian::initialParameters(), FunctionWrap::operator()(), FunctionBase::resize(), FunctionProjectorXML::setAttributes(), and FunctionBase::setParameters().


Member Data Documentation

std::string m_name [protected, inherited]

The name of the function.

Definition at line 103 of file FunctionBase.h.

Referenced by FunctionBase::FunctionBase(), Quadratic2::initialize(), Quadratic::initialize(), PowerLaw::initialize(), Novosibirsk::initialize(), LogParabola::initialize(), LogNormal::initialize(), LinearSumFunction::initialize(), Linear::initialize(), Landau::initialize(), Gaussian::initialize(), Exponential::initialize(), Erfc::initialize(), ConstantF::initialize(), Chi2Dist::initialize(), BrokenPowerLaw::initialize(), FunctionBase::name(), and FunctionBase::setName().

std::vector<std::string> m_parm_names [protected, inherited]

The names of the function parameters.

Definition at line 106 of file FunctionBase.h.

Referenced by Quadratic2::initialize(), Quadratic::initialize(), PowerLaw::initialize(), Novosibirsk::initialize(), LogParabola::initialize(), LogNormal::initialize(), Linear::initialize(), Landau::initialize(), Gaussian::initialize(), Exponential::initialize(), Erfc::initialize(), ConstantF::initialize(), Chi2Dist::initialize(), BrokenPowerLaw::initialize(), LinearSumFunction::parmNames(), FunctionBase::parmNames(), FunctionBase::resize(), FunctionWrap::setParmNames(), FunctionBase::setParmNames(), and FunctionBase::size().

std::vector< double > m_parms [protected, inherited]

The parameter values.

Definition at line 109 of file FunctionBase.h.

Referenced by BrokenPowerLaw::BrokenPowerLaw(), Erfc::calcRed(), Chi2Dist::Chi2Dist(), ConstantF::ConstantF(), Gaussian::derivByMean(), Landau::derivByNorm(), Gaussian::derivByNorm(), Quadratic2::derivByParm(), PowerLaw::derivByParm(), LogParabola::derivByParm(), Exponential::derivByParm(), Erfc::derivByParm(), Chi2Dist::derivByParm(), BrokenPowerLaw::derivByParm(), Landau::derivByPeak(), Landau::derivBySigma(), Gaussian::derivBySigma(), Erfc::Erfc(), Exponential::Exponential(), Gaussian::Gaussian(), LinearSumFunction::getParameters(), FunctionBase::getParameters(), Quadratic2::initialParameters(), Quadratic::initialParameters(), PowerLaw::initialParameters(), Novosibirsk::initialParameters(), LogParabola::initialParameters(), LogNormal::initialParameters(), Linear::initialParameters(), Landau::initialParameters(), Gaussian::initialParameters(), Exponential::initialParameters(), Erfc::initialParameters(), ConstantF::initialParameters(), Chi2Dist::initialParameters(), BrokenPowerLaw::initialParameters(), Landau::Landau(), Linear::Linear(), LogNormal::LogNormal(), LogParabola::LogParabola(), Novosibirsk::Novosibirsk(), Quadratic2::operator()(), Quadratic::operator()(), PowerLaw::operator()(), Novosibirsk::operator()(), LogParabola::operator()(), LogNormal::operator()(), Linear::operator()(), Landau::operator()(), Gaussian::operator()(), Exponential::operator()(), ConstantF::operator()(), Chi2Dist::operator()(), BrokenPowerLaw::operator()(), PowerLaw::PowerLaw(), Quadratic::Quadratic(), Quadratic2::Quadratic2(), FunctionBase::resize(), and FunctionBase::setParameters().


The documentation for this class was generated from the following files:
Generated for HippoDraw Class Library by doxygen