18using namespace CurveFitting;
19using namespace Kernel;
37 for (
size_t i = 0; i < nData; i++) {
38 double diff = xValues[i] - peakCentre;
39 out[i] =
height * exp(-0.5 * diff * diff * weight);
48 for (
size_t i = 0; i < nData; i++) {
49 double diff = xValues[i] - peakCentre;
50 double e = exp(-0.5 * diff * diff * weight);
52 out->
set(i, 1, diff *
height * e * weight);
54 -0.5 * diff * diff *
height * e);
60 throw std::runtime_error(
"Attempt to use an inactive parameter");
70 throw std::runtime_error(
"Attempt to use an inactive parameter");
85 if (std::isfinite(
height)) {
94 const double heightError =
getError(
"Height");
95 const double sigmaError =
getError(
"Sigma");
119 tie(
"Height", formula, isDefault);
135 const double sigma2 =
getParameter(
"Sigma") * sqrt(2.0);
137 auto cumulFun = [sigma2, peakCentre](
double x) {
return 0.5 * erf((
x - peakCentre) / sigma2); };
138 double cLeft = cumulFun(
left);
139 for (
size_t i = 0; i < nBins; ++i) {
140 double cRight = cumulFun(
right[i]);
141 out[i] = amplitude * (cRight - cLeft);
156 const double w = pow(1 / s, 2);
157 const double sw = sqrt(w);
159 auto cumulFun = [sw, c](
double x) {
return sqrt(M_PI / 2) / sw * erf(sw / sqrt(2.0) * (
x - c)); };
160 auto fun = [w, c](
double x) {
return exp(-w / 2 * pow(
x - c, 2)); };
163 double fLeft = fun(
left);
164 double cLeft = cumulFun(
left);
165 const double h_over_2w = h / (2 * w);
166 for (
size_t i = 0; i < nBins; ++i) {
167 double xr =
right[i];
168 double fRight = fun(xr);
169 double cRight = cumulFun(xr);
170 jacobian->
set(i, 0, cRight - cLeft);
171 jacobian->
set(i, 1, -h * (fRight - fLeft));
173 h_over_2w * ((xr - c) * fRight - (xl - c) * fLeft + cLeft - cRight));
double value
The value of the point.
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
bool isActive(size_t i) const
Check if an active parameter i is actually active.
void unfixParameter(const std::string &name)
Free a parameter.
virtual void tie(const std::string &parName, const std::string &expr, bool isDefault=false)
Tie a parameter to other parameters (or a constant)
void fixParameter(const std::string &name, bool isDefault=false)
Fix a parameter.
virtual void removeTie(const std::string &parName)
Removes the tie off a parameter.
An interface to a peak function, which extend the interface of IFunctionWithLocation by adding method...
void setParameter(const std::string &name, const double &value, bool explicitlySet=true) override
Override parent so that we may bust the cache when a parameter is set.
Represents the Jacobian in IFitFunction::functionDeriv.
virtual void set(size_t iY, size_t iP, double value)=0
Set a value to a Jacobian matrix element.
double getError(size_t i) const override
Get the fitting error for a parameter.
std::string parameterName(size_t i) const override
Returns the name of parameter i.
void declareParameter(const std::string &name, double initValue=0, const std::string &description="") override
Declare a new parameter.
double getParameter(size_t i) const override
Get i-th parameter.
Provide gaussian peak shape function interface to IPeakFunction.
void fixIntensity(bool isDefault=false) override
Fix a parameter or set up a tie such that value returned by intensity() is constant during fitting.
void setHeight(const double h) override
Sets the parameters such that height == h.
double centre() const override
overwrite IPeakFunction base class methods
void histogramDerivative1D(API::Jacobian *jacobian, double left, const double *right, const size_t nBins) const override
Devivatives of the histogram.
void setFwhm(const double w) override
Sets the parameters such that FWHM = w.
void setIntensity(const double i) override
Sets the integral intensity of the peak.
void setCentre(const double c) override
Sets the parameters such that centre == c.
double intensity() const override
Returns the integral intensity of the peak.
double fwhm() const override
Returns the peak FWHM.
void functionLocal(double *out, const double *xValues, const size_t nData) const override
Function evaluation method to be implemented in the inherited classes.
double activeParameter(size_t i) const override
Value of i-th active parameter.
double intensityError() const override
Error in the integrated intensity of the peak due to uncertainties in the values of the fit parameter...
void unfixIntensity() override
Free the intensity parameter.
void init() override
overwrite IFunction base class method, which declare function parameters
void unfixCentre() override
Free the centre parameter.
void histogram1D(double *out, double left, const double *right, const size_t nBins) const override
Calculate histogram data.
double height() const override
Returns the height of the function.
double m_intensityCache
Intensity cache to help recover form Sigma==0 situation.
void functionDerivLocal(API::Jacobian *out, const double *xValues, const size_t nData) override
Derivative evaluation method. Default is to calculate numerically.
void fixCentre(bool isDefault=false) override
Fix a parameter or set up a tie such that value returned by centre() is constant during fitting.
void setActiveParameter(size_t i, double value) override
Set new value of i-th active parameter.
std::string to_string(const wide_integer< Bits, Signed > &n)