-
Notifications
You must be signed in to change notification settings - Fork 122
/
GausDecay.cpp
66 lines (53 loc) · 1.84 KB
/
GausDecay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidCurveFitting/Functions/GausDecay.h"
#include "MantidAPI/FunctionFactory.h"
#include <cmath>
namespace Mantid {
namespace CurveFitting {
namespace Functions {
using namespace CurveFitting;
using namespace Kernel;
using namespace API;
DECLARE_FUNCTION(GausDecay)
void GausDecay::init() {
declareParameter("A", 10.0, "Amplitude at time 0");
declareParameter("Sigma", 0.2, "Decay rate");
}
void GausDecay::function1D(double *out, const double *xValues,
const size_t nData) const {
const double A = getParameter("A");
const double G = getParameter("Sigma");
for (size_t i = 0; i < nData; i++) {
double x = xValues[i];
out[i] = A * exp(-G * G * x * x);
}
}
void GausDecay::functionDeriv1D(Jacobian *out, const double *xValues,
const size_t nData) {
const double A = getParameter("A");
const double G = getParameter("Sigma");
for (size_t i = 0; i < nData; i++) {
double x = xValues[i];
double g = exp(-G * G * x * x);
out->set(i, 0, g);
out->set(i, 1, -2 * G * x * x * A * g);
}
}
void GausDecay::setActiveParameter(size_t i, double value) {
size_t j = i;
if (parameterName(j) == "Sigma")
setParameter(j, fabs(value), false); // Make sigma positive
else
setParameter(j, value, false);
}
} // namespace Functions
} // namespace CurveFitting
} // namespace Mantid