16using namespace CurveFitting;
18using namespace Kernel;
76 const double invPI = 1.0 / M_PI;
77 for (
size_t i = 0; i < nData; i++) {
78 double diff = (xValues[i] - peakCentre);
79 out[i] = amplitude * invPI * halfGamma / (diff * diff + (halfGamma * halfGamma));
87 const double halfGamma = 0.5 * gamma;
89 const double invPI = 1.0 / M_PI;
90 for (
size_t i = 0; i < nData; i++) {
91 double diff = xValues[i] - peakCentre;
92 const double invDen1 = 1.0 / (gamma * gamma + 4.0 * diff * diff);
93 const double dfda = 2.0 * invPI * gamma * invDen1;
96 double invDen2 = 1 / (diff * diff + halfGamma * halfGamma);
97 const double dfdxo = amplitude * invPI * gamma * diff * invDen2 * invDen2;
98 out->
set(i, 1, dfdxo);
100 const double dfdg = -2.0 * amplitude * invPI * (gamma * gamma - 4.0 * diff * diff) * invDen1 * invDen1;
101 out->
set(i, 2, dfdg);
117 const double halfGamma = 0.5 * gamma;
119 auto cumulFun = [halfGamma, peakCentre](
double x) {
return atan((
x - peakCentre) / halfGamma) / M_PI; };
120 double cLeft = cumulFun(
left);
121 for (
size_t i = 0; i < nBins; ++i) {
122 double cRight = cumulFun(
right[i]);
123 out[i] = amplitude * (cRight - cLeft);
138 const double g2 = g * g;
140 auto cumulFun = [g, c](
double x) {
return atan((
x - c) / g * 2) / M_PI; };
141 auto denom = [g2, c](
double x) {
return (g2 + 4 * pow(c -
x, 2)) * M_PI; };
144 double denomLeft = denom(
left);
145 double cLeft = cumulFun(
left);
146 for (
size_t i = 0; i < nBins; ++i) {
147 double xr =
right[i];
148 double denomRight = denom(xr);
149 double cRight = cumulFun(xr);
150 jacobian->
set(i, 0, cRight - cLeft);
151 jacobian->
set(i, 1, -2.0 * (g / denomRight - g / denomLeft) * amplitude);
152 jacobian->
set(i, 2, -2.0 * ((xr - c) / denomRight - (xl - c) / denomLeft) * amplitude);
153 denomLeft = denomRight;
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
void unfixParameter(const std::string &name)
Free a parameter.
void fixParameter(const std::string &name, bool isDefault=false)
Fix a parameter.
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.
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 lorentzian peak shape function interface to IPeakFunction.
void functionDerivLocal(API::Jacobian *out, const double *xValues, const size_t nData) override
Derivative evaluation method. Default is to calculate numerically.
void setHeight(const double h) override
Sets the parameters such that height == h.
void functionLocal(double *out, const double *xValues, const size_t nData) const override
Function evaluation method to be implemented in the inherited classes.
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 histogram1D(double *out, double left, const double *right, const size_t nBins) const override
Calculate histogram data.
void unfixIntensity() override
Free the intensity parameter.
void histogramDerivative1D(API::Jacobian *jacobian, double left, const double *right, const size_t nBins) const override
Devivatives of the histogram.
double height() const override
Returns the height of the function.
bool m_amplitudeEqualHeight
When Amplitude is set via setHeight() and fwhm() == 0 height is made equal to Amplitude.
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 init() override
overwrite IFunction base class method, which declare function parameters
void unfixCentre() override
Free the centre parameter.
void setFwhm(const double w) override
Sets the parameters such that FWHM = w.