Mantid
Loading...
Searching...
No Matches
ExpDecayMuon.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(ExpDecayMuon)
23
24void ExpDecayMuon::init() {
25 declareParameter("A", 0.2, "Amplitude at time 0");
26 declareParameter("Lambda", 0.2, "Decay rate");
27}
28
29void ExpDecayMuon::function1D(double *out, const double *xValues, const size_t nData) const {
30 const double gA0 = getParameter("A");
31 const double gs = getParameter("Lambda");
32
33 for (size_t i = 0; i < nData; i++) {
34 out[i] = gA0 * exp(-gs * (xValues[i]));
35 }
36}
37
38void ExpDecayMuon::functionDeriv1D(Jacobian *out, const double *xValues, const size_t nData) {
39 const double gA0 = getParameter("A");
40 const double gs = getParameter("Lambda");
41
42 for (size_t i = 0; i < nData; i++) {
43 double x = xValues[i];
44 double e = exp(-gs * x);
45 out->set(i, 0, e); // derivative w.r.t. A (gA0)
46 out->set(i, 1, -gA0 * x * e); // derivative w.r.t Lambda (gs)
47 }
48}
49
50} // namespace Mantid::CurveFitting::Functions
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
Represents the Jacobian in IFitFunction::functionDeriv.
Definition: Jacobian.h:22
virtual void set(size_t iY, size_t iP, double value)=0
Set a value to a Jacobian matrix element.
double getParameter(size_t i) const override
Get i-th parameter.
Provide exponential decay function: h*exp(-lambda.x)
Definition: ExpDecayMuon.h:26
void functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) override
Derivatives of function with respect to active parameters.
void function1D(double *out, const double *xValues, const size_t nData) const override
Function you want to fit to.