Mantid
Loading...
Searching...
No Matches
Keren.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 +
10#include <cmath>
11
12namespace {
13constexpr double TWOPI = 2.0 * M_PI;
14}
15
17
19
20
23void Keren::init() {
24 declareParameter("A", 1.0, "Polarization at time zero");
25 declareParameter("Delta", 0.2, "Distribution width of local fields (MHz)");
26 declareParameter("Field", 50.0, "Longitudinal field (Gauss)");
27 declareParameter("Fluct", 0.2, "Hopping rate (inverse correlation time, MHz)");
28}
29
38void Keren::setActiveParameter(size_t i, double value) {
39 if (!isActive(i)) {
40 throw std::runtime_error("Attempt to use an inactive parameter");
41 }
42 if (parameterName(i) == "Field") {
43 // Value passed in is omega_L, return B
45 } else
46 setParameter(i, value, false);
47}
48
57double Keren::activeParameter(size_t i) const {
58 if (!isActive(i)) {
59 throw std::runtime_error("Attempt to use an inactive parameter");
60 }
61 if (parameterName(i) == "Field") {
62 // Fit to omega_L = 2 * pi * gamma_mu * B
64 } else
65 return getParameter(i);
66}
67
74void Keren::function1D(double *out, const double *xValues, const size_t nData) const {
75 // Get parameters
76 const double initial = getParameter("A");
77 const double delta = getParameter("Delta");
78 const double fluct = getParameter("Fluct");
79 const double larmor = getParameter("Field") * PhysicalConstants::MuonGyromagneticRatio * TWOPI;
80
81 for (size_t i = 0; i < nData; i++) {
82 out[i] = initial * polarization(delta, larmor, fluct, xValues[i]);
83 }
84}
85
96double Keren::polarization(const double delta, const double larmor, const double fluct, const double time) const {
97 return exp(-1.0 * relaxation(delta, larmor, fluct, time));
98}
99
109double Keren::relaxation(const double delta, const double larmor, const double fluct, const double time) const {
110 // Useful shortcuts
111 const double deltaSq = delta * delta;
112 const double omegaSq = larmor * larmor;
113 const double nuSq = fluct * fluct;
114 const double omegaT = larmor * time;
115 const double nuT = fluct * time;
116 const double expon = exp(-1.0 * nuT);
117
118 // 2*Delta^2 / (omega_L^2 + nu^2)^2
119 const double prefactor = (2.0 * deltaSq) / ((omegaSq + nuSq) * (omegaSq + nuSq));
120
121 const double term1 = (omegaSq + nuSq) * nuT;
122 const double term2 = omegaSq - nuSq;
123 const double term3 = 1.0 - expon * cos(omegaT);
124 const double term4 = 2.0 * fluct * larmor * expon * sin(omegaT);
125
126 return prefactor * (term1 + term2 * term3 - term4);
127}
128
129} // 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.
bool initial
Definition: LoadDialog.cpp:39
bool isActive(size_t i) const
Check if an active parameter i is actually active.
Definition: IFunction.cpp:160
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.
Keren : Keren fitting function for muon scientists.
Definition: Keren.h:22
void setActiveParameter(size_t i, double value) override
Set active parameter.
Definition: Keren.cpp:38
double activeParameter(size_t i) const override
Get active parameter.
Definition: Keren.cpp:57
double relaxation(const double delta, const double larmor, const double fluct, const double time) const
Relaxation form.
Definition: Keren.cpp:109
void function1D(double *out, const double *xValues, const size_t nData) const override
Evaluate the function at the given values.
Definition: Keren.cpp:74
double polarization(const double delta, const double larmor, const double fluct, const double time) const
Time-dependent muon polarization.
Definition: Keren.cpp:96
static constexpr double MuonGyromagneticRatio
Muon gyromagnetic ratio in MHz/G Taken from CalMuonDetectorPhases and DynamicKuboToyabe on 02/02/2016...