Mantid
Loading...
Searching...
No Matches
MuoniumDecouplingCurve.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2021 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
12
13#include <cmath>
14
16
17using namespace CurveFitting;
18
19using namespace Kernel;
20
21using namespace API;
22
23DECLARE_FUNCTION(MuoniumDecouplingCurve)
24
26 declareParameter("RepolarisingAsymmetry", 0.2, "coefficient for the repolarising asymmetry");
27 declareParameter("DecouplingField", 500.0, "coefficient for magnetic field rescaling");
28 declareParameter("BackgroundAsymmetry", 0.0, "coefficient for the background asymmetry");
29}
30
31void MuoniumDecouplingCurve::function1D(double *out, const double *xValues, const size_t nData) const {
32 const double RepolAS = getParameter("RepolarisingAsymmetry");
33 const double DecoupField = getParameter("DecouplingField");
34 const double BG = getParameter("BackgroundAsymmetry");
35
36 for (size_t i = 0; i < nData; i++) {
37 out[i] = RepolAS * (0.5 + pow(xValues[i] / DecoupField, 2)) / (1 + pow(xValues[i] / DecoupField, 2)) + BG;
38 }
39}
40
41void MuoniumDecouplingCurve::functionDeriv1D(Jacobian *out, const double *xValues, const size_t nData) {
42 const double RepolAS = getParameter("RepolarisingAsymmetry");
43 const double DecoupField = getParameter("DecouplingField");
44 const double DecoupFieldSq = pow(DecoupField, 2);
45
46 for (size_t i = 0; i < nData; i++) {
47 double diffRepolAS = (0.5 * DecoupFieldSq + pow(xValues[i], 2)) / (DecoupFieldSq + pow(xValues[i], 2));
48 double diffDecoupField =
49 -(RepolAS * DecoupField * pow(xValues[i], 2)) / pow((DecoupFieldSq + pow(xValues[i], 2)), 2);
50 out->set(i, 0, diffRepolAS);
51 out->set(i, 1, diffDecoupField);
52 out->set(i, 2, 1);
53 }
54}
55
56} // 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 Muonium-style decoupling curve function interface to IFunction.
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.