Mantid
Loading...
Searching...
No Matches
FlatBackground.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
11using namespace Mantid::Kernel;
12
13using namespace Mantid::API;
14
16
17using namespace CurveFitting;
18DECLARE_FUNCTION(FlatBackground)
19
20
21std::string FlatBackground::name() const { return "FlatBackground"; }
22
24void FlatBackground::init() { declareParameter("A0", 0.0, "coefficient for linear term"); }
25
32void FlatBackground::function1D(double *out, const double *xValues, const size_t nData) const {
33 UNUSED_ARG(xValues);
34
35 const double a0 = getParameter("A0");
36
37 for (size_t i = 0; i < nData; i++) {
38 out[i] = a0;
39 }
40}
41
48void FlatBackground::functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) {
49 UNUSED_ARG(xValues);
50
51 for (size_t i = 0; i < nData; i++) {
52 out->set(i, 0, 1);
53 }
54}
55
63void FlatBackground::histogram1D(double *out, double left, const double *right, const size_t nBins) const {
64
65 const double a0 = getParameter("A0");
66
67 double cLeft = a0 * left;
68 for (size_t i = 0; i < nBins; ++i) {
69 double cRight = a0 * right[i];
70 out[i] = cRight - cLeft;
71 cLeft = cRight;
72 }
73}
74
81void FlatBackground::histogramDerivative1D(Jacobian *jacobian, double left, const double *right,
82 const size_t nBins) const {
83
84 double xl = left;
85 for (size_t i = 0; i < nBins; ++i) {
86 double xr = right[i];
87 jacobian->set(i, 0, xr - xl);
88 xl = xr;
89 }
90}
91
92} // namespace Mantid::CurveFitting::Functions
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
double left
Definition: LineProfile.cpp:80
double right
Definition: LineProfile.cpp:81
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
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.
void declareParameter(const std::string &name, double initValue=0, const std::string &description="") override
Declare a new parameter.
double getParameter(size_t i) const override
Get i-th parameter.
FlatBackground : TODO: DESCRIPTION.
void histogram1D(double *out, double left, const double *right, const size_t nBins) const override
Calculate histogram data.
void init() override
The only parameter is the constant for the flat background.
void histogramDerivative1D(API::Jacobian *jacobian, double left, const double *right, const size_t nBins) const override
Devivatives of the histogram.
void function1D(double *out, const double *xValues, const size_t nData) const override
Evaluate the function at the supplied points.
void functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) override
Evaluate the Jacobian at the supplied points.
STL namespace.