19using namespace CurveFitting;
25const size_t NLORENTZIANS = 4;
27const double COEFFA[NLORENTZIANS] = {-1.2150, -1.3509, -1.2150, -1.3509};
28const double COEFFB[NLORENTZIANS] = {1.2359, 0.3786, -1.2359, -0.3786};
29const double COEFFC[NLORENTZIANS] = {-0.3085, 0.5906, -0.3085, 0.5906};
30const double COEFFD[NLORENTZIANS] = {0.0210, -1.1858, -0.0210, 1.1858};
32const char *LORENTZ_AMP =
"LorentzAmp";
33const char *LORENTZ_POS =
"LorentzPos";
34const char *LORENTZ_FWHM =
"LorentzFWHM";
35const char *GAUSSIAN_FWHM =
"GaussianFWHM";
37const double SQRTLN2 = std::sqrt(M_LN2);
38const double SQRTPI = std::sqrt(M_PI);
48 declareParameter(LORENTZ_FWHM, 0.0,
"Value of the full-width half-maximum for the Lorentzian");
49 declareParameter(GAUSSIAN_FWHM, 0.0,
"Value of the full-width half-maximum for the Gaussian");
88 const double rtln2oGammaG = SQRTLN2 / gamma_G;
89 const double prefactor = (a_L * SQRTPI * gamma_L * SQRTLN2 / gamma_G);
91 for (
size_t i = 0; i < nData; ++i) {
92 const double xoffset = xValues[i] - lorentzPos;
94 const double X = xoffset * 2.0 * rtln2oGammaG;
95 const double Y = gamma_L * rtln2oGammaG;
97 double fx(0.0), dFdx(0.0), dFdy(0.0);
98 for (
size_t j = 0; j < NLORENTZIANS; ++j) {
99 const double ymA(
Y - COEFFA[j]);
100 const double xmB(
X - COEFFB[j]);
101 const double alpha = COEFFC[j] * ymA + COEFFD[j] * xmB;
102 const double beta = ymA * ymA + xmB * xmB;
103 const double ratioab = alpha / beta;
105 dFdx += (COEFFD[j] / beta) - 2.0 * (
X - COEFFB[j]) * ratioab / beta;
106 dFdy += (COEFFC[j] / beta) - 2.0 * (
Y - COEFFA[j]) * ratioab / beta;
108 if (functionValues) {
109 functionValues[i] = prefactor * fx;
112 derivatives->
set(i, 0, prefactor * fx / a_L);
113 derivatives->
set(i, 1, -prefactor * dFdx * 2.0 * rtln2oGammaG);
114 derivatives->
set(i, 2, prefactor * (fx / gamma_L + dFdy * rtln2oGammaG));
115 derivatives->
set(i, 3, -prefactor * (fx + (rtln2oGammaG) * (2.0 * xoffset * dFdx + gamma_L * dFdy)) / gamma_G);
159 if (lorentzFwhm == 0.0) {
160 lorentzFwhm = std::numeric_limits<double>::epsilon();
164 if (lorentzAmp == 0.0) {
165 lorentzAmp = std::numeric_limits<double>::epsilon();
169 if (gaussFwhm == 0.0) {
170 setParameter(GAUSSIAN_FWHM, std::numeric_limits<double>::epsilon());
182 if (lorentzFwhm == 0.0) {
183 lorentzFwhm = std::numeric_limits<double>::epsilon();
186 if (gaussFwhm == 0.0) {
187 gaussFwhm = std::numeric_limits<double>::epsilon();
189 auto ratio = lorentzFwhm / (lorentzFwhm + gaussFwhm);
210 if (lorentzFWHM == 0.0) {
211 lorentzFWHM = std::numeric_limits<double>::epsilon();
215 if (gaussFwhm == 0.0) {
216 setParameter(GAUSSIAN_FWHM, std::numeric_limits<double>::epsilon());
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.
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.
void setHeight(const double value) override
Set the height of the peak.
double height() const override
Return value of height of peak.
void functionLocal(double *out, const double *xValues, const size_t nData) const override
Fill out with function values at given x points.
double intensity() const override
Returns the integral intensity of the peak.
double fwhm() const override
Return value of FWHM of peak.
void functionDerivLocal(API::Jacobian *out, const double *xValues, const size_t nData) override
Derivatives of function with respect to active parameters.
void setIntensity(const double value) override
Sets the integral intensity of the peak.
void setCentre(const double value) override
Set the centre of the peak.
void setFwhm(const double value) override
Set the FWHM of the peak.
void declareParameters() override
Declare parameters.
double centre() const override
Return value of centre of peak.
void calculateFunctionAndDerivative(const double *xValues, const size_t nData, double *functionValues, API::Jacobian *derivatives) const
Calculate both function & derivative together.