Mantid
Loading...
Searching...
No Matches
Abragam.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 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
12#include <cmath>
13
15
16using namespace CurveFitting;
17
18using namespace Kernel;
19
20using namespace API;
21
22DECLARE_FUNCTION(Abragam)
23
24void Abragam::init() {
25 declareParameter("A", 0.2, "Amplitude");
26 declareParameter("Omega", 0.5, "Angular Frequency of oscillation");
27 declareParameter("Phi", 0, "Phase of oscillation at 0 (in Radians)");
28 declareParameter("Sigma", 1, "Decay rate?");
29 declareParameter("Tau", 1, "?");
30}
31
32void Abragam::function1D(double *out, const double *xValues, const size_t nData) const {
33 const double A = getParameter("A");
34 const double w = getParameter("Omega");
35 const double phi = getParameter("Phi");
36 const double sig = getParameter("Sigma");
37 const double t = getParameter("Tau");
38
39 for (size_t i = 0; i < nData; i++) {
40 double A1 = A * cos(w * xValues[i] + phi);
41 double A2 = -(sig * sig * t * t) * (expm1(-xValues[i] / t) + (xValues[i] / t));
42 double A3 = exp(A2);
43
44 out[i] = A1 * A3;
45 }
46}
47
49 calNumericalDeriv(domain, jacobian);
50}
51
52void Abragam::setActiveParameter(size_t i, double value) {
53 size_t j = i;
54
55 if (parameterName(j) == "Sigma")
56 setParameter(j, fabs(value), false); // Make sigma positive
57 else if (parameterName(j) == "Phi") {
58 // Put angle in range of (-180 to 180] degrees
59 double a = fmod(value, 2 * M_PI);
60 if (a <= -M_PI)
61 a += 2 * M_PI;
62 if (a > M_PI)
63 a -= 2 * M_PI;
64 setParameter(j, a, false);
65 } else
66 setParameter(j, value, false);
67}
68
69} // namespace Mantid::CurveFitting::Functions
double value
The value of the point.
Definition: FitMW.cpp:51
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
#define fabs(x)
Definition: Matrix.cpp:22
Base class that represents the domain of a function.
void calNumericalDeriv(const FunctionDomain &domain, Jacobian &jacobian)
Calculate numerical derivatives.
Definition: IFunction.cpp:1031
Represents the Jacobian in IFitFunction::functionDeriv.
Definition: Jacobian.h:22
void setParameter(size_t, const double &value, bool explicitlySet=true) override
Set i-th parameter.
std::string parameterName(size_t i) const override
Returns the name of parameter i.
double getParameter(size_t i) const override
Get i-th parameter.
Provide Abragam fitting function for muon scientists.
Definition: Abragam.h:29
void function1D(double *out, const double *xValues, const size_t nData) const override
Function you want to fit to.
Definition: Abragam.cpp:32
void functionDeriv(const API::FunctionDomain &domain, API::Jacobian &jacobian) override
Derivatives of function with respect to active parameters.
Definition: Abragam.cpp:48
void setActiveParameter(size_t i, double value) override
Set new value of i-th active parameter.
Definition: Abragam.cpp:52