#include <CGaussianFit.h> class CGaussianFit : public CFit { public: CGaussianFit(std::string name, int id = 0); virtual void Perform(); virtual double operator()(double x); virtual CFit::FitParameterList GetParameters(); virtual std::string Type() const; virtual std::string makeTclFitScript(); virtual CFit* clone(); }; #include <CLinearFit.h> class CLinearFit : public CFit { public: CLinearFit (); //!< Constructor. virtual void Perform () ; virtual double operator() (double x) ; virtual CFit::FitParameterList GetParameters () ; virtual std::string Type() const; virtual CFit* clone(); };
SpecTcl provides two simple fit functions. The programming manual describes how to add additional fit types to the fit subsystem. The fit functions provided are classes that implement a Gaussian fit on a constant background and a linear fit.
The linear fit class is mostly provided as an example while the gaussian fit has some actual usefulness.
The fit classes SpecTcl predefines use the GSL (GNU Scientific Library) to perform their fits. It is easy enough to extend SpecTcl's fitting subsystem with fits performed by Root.
CGaussianFit
METHODS
CGaussianFit(std::string name, int id = 0);
The constructor initializes the base class
CNamedObject
providing a name
and an ID. This is not strictly speaking needed for
the SpecTcl fitting system, but was used in another
application of this class not relevant to current
SpecTcls.
virtual void Perform();
Performs the fit using the available points. At least 5 points must have been accepted to support performing the gaussian fit.
virtual double operator()(double x);
Returns the value of the fitted function at the point
x
.
virtual CFit::FitParameterList GetParameters();
Returns the fit parameters. The fit performed is of the form:
In this equation, the parameters returned are: baseline for b. height for h. centroid for x0. sigma for σ.
In addition the parameter chisquare contains the chi square of the fit.
This method throws an exception if the fit is not in the Performed state.
virtual const std::string Type();
Returns the string gaussian
virtual std::string makeTclFitScript();
Throws an exception if the fit is not Performed. Returns a string that defines a tcl proc named fitline. The proc accepts a single double parameter and returns the fit value at the point passed in.
Linear fit is intended just to be a sample. It performs a fit to the function:
y = mx + b
Where the fit parameters are the slope, m
and Y axis intercept; b
. The important
methods for this class are:
virtual void Perform();
Performs the fit. If at least two points have not been accepted; an exception is thrown. If the fit has two points and they are on a vertical line, an exception is thrown since the slope is not defined.
The Gnu Scientific Library function
gsl_fit_linear
is used
to perform the fit. If successful, the state of the
fit is set to CFit::Performed.
virtual double operator()(double x);
If the fit is not in the CFit::Performed
state an exception is thrown. Otherwise, the value
of the fit function at x
is
returned.
virtual CFit::FitParameterList GetParameters();
If the fit is not CFit::Performed an exception is thrown. If it has been, the fit parameters are returned. The fit parameters are named slope and offset with obvious meanings and the fit provides the required chisquare "parameter".
virtual const std::string Type();
Returns the text linear