Mantid
Loading...
Searching...
No Matches
GramCharlier.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
10
11#include <boost/math/special_functions/hermite.hpp>
12
14
15DECLARE_FUNCTION(GramCharlier)
16
17
21void GramCharlier::init() {
22 // Default values are abitrary non-zero values that are "typical"
23 // --------------------------- !!!WARNING!!! -------------------------
24 // Do not reorder these parameters without altering the index access
25 // in function1D
26 // ----------------------------------------- -------------------------
27 declareParameter("A", 0.01, "Amplitude");
28 declareParameter("X0", 0.2, "Position of the centroid");
29 declareParameter("Sigma", 4, "Std. Deviation of distribution");
30 declareParameter("C4", -0.005, "Coefficient of 4th Hermite polynomial");
31 declareParameter("C6", -0.003, "Coefficient of 6th Hermite polynomial");
32 declareParameter("C8", -0.002, "Coefficient of 8th Hermite polynomial");
33 declareParameter("C10", -0.001, "Coefficient of 10th Hermite polynomial");
34 declareParameter("Afse", 0.01, "Ampliude of final-state effects term");
35}
36
44void GramCharlier::function1D(double *out, const double *x, const size_t n) const {
45 using boost::math::hermite;
46 using std::exp;
47 using std::pow;
48 using std::sqrt;
49 // formula
50 // f(x) = Aexp(-z^2)*(1/sqrt(2*Pi*Sigma^2))*(1 + (C4/2^4/(4/2)!)*H_4(z) +
51 // (C6/2^6/(6/2)!)*H_6(z) + (C8/2^8/(8/2)!)*H_8(z) +
52 // (C10/2^10/(10/2)!)*H_10(z)) +
53 // (Afse*Sigma*sqrt(2)/12)*(1/sqrt(2*Pi*Sigma^2))*exp(-z^2)*H_3(z))
54 //
55 // where z=((x-X0)/Sigma/sqrt(2))
56
57 // retrieve parameter values and scale coefficients once
58 const double amp(getParameter(0)), x0(getParameter(1)), sigma(getParameter(2)), c4(getParameter(3) / 32.0),
59 c6(getParameter(4) / 384.0), c8(getParameter(5) / 6144.0), c10(getParameter(6) / 122880.0),
60 ampFSE(getParameter(7));
61 const double root2Sigma = sqrt(2) * sigma;
62 const double norm = 1 / (root2Sigma * sqrt(M_PI));
63 const double prefactorFSE = root2Sigma / 12.0;
64
65 for (size_t i = 0; i < n; ++i) {
66 const double z = (x[i] - x0) / root2Sigma;
67 out[i] = amp * norm * exp(-z * z) *
68 (1 + c4 * hermite(4, z) + c6 * hermite(6, z) + c8 * hermite(8, z) + c10 * hermite(10, z)) +
69 ampFSE * norm * prefactorFSE * exp(-z * z) * hermite(3, z);
70 }
71}
72
73} // namespace Mantid::CurveFitting::Functions
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
double sigma
Definition: GetAllEi.cpp:156
double getParameter(size_t i) const override
Get i-th parameter.
Implements a Gram-Charlier A series expansion.
Definition: GramCharlier.h:20
void function1D(double *out, const double *x, const size_t n) const override
GramCharlier::function1D Computes the value of the function.