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 +
9
10using namespace Mantid::Kernel;
11
12using namespace Mantid::API;
13
15
16using namespace CurveFitting;
17DECLARE_FUNCTION(FlatBackground)
18
19
20std::string FlatBackground::name() const { return "FlatBackground"; }
21
23void FlatBackground::init() { declareParameter("A0", 0.0, "coefficient for linear term"); }
24
31void FlatBackground::function1D(double *out, const double *xValues, const size_t nData) const {
32 UNUSED_ARG(xValues);
33
34 const double a0 = getParameter("A0");
35
36 for (size_t i = 0; i < nData; i++) {
37 out[i] = a0;
38 }
39}
40
47void FlatBackground::functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) {
48 UNUSED_ARG(xValues);
49
50 for (size_t i = 0; i < nData; i++) {
51 out->set(i, 0, 1);
52 }
53}
54
62void FlatBackground::histogram1D(double *out, double left, const double *right, const size_t nBins) const {
63
64 const double a0 = getParameter("A0");
65
66 double cLeft = a0 * left;
67 for (size_t i = 0; i < nBins; ++i) {
68 double cRight = a0 * right[i];
69 out[i] = cRight - cLeft;
70 cLeft = cRight;
71 }
72}
73
80void FlatBackground::histogramDerivative1D(Jacobian *jacobian, double left, const double *right,
81 const size_t nBins) const {
82
83 double xl = left;
84 for (size_t i = 0; i < nBins; ++i) {
85 double xr = right[i];
86 jacobian->set(i, 0, xr - xl);
87 xl = xr;
88 }
89}
90
91} // namespace Mantid::CurveFitting::Functions
std::string name
Definition Run.cpp:60
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
double left
double right
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition System.h:48
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.