15using namespace CurveFitting;
17using namespace Kernel;
24 declareParameter(
"A0", 0.0,
"coefficient for constant term");
25 declareParameter(
"A1", 0.0,
"coefficient for linear term");
32 for (
size_t i = 0; i < nData; i++) {
33 out[i] = a0 + a1 * xValues[i];
38 for (
size_t i = 0; i < nData; i++) {
40 out->
set(i, 1, xValues[i]);
50 if (
X.size() !=
Y.size()) {
51 throw std::runtime_error(
"Background fit: different array sizes");
67 for (
size_t i = 0; i <
n; i++) {
75 x_mean /=
static_cast<double>(
n);
76 y_mean /=
static_cast<double>(
n);
77 x2_mean /=
static_cast<double>(
n);
78 xy_mean /=
static_cast<double>(
n);
80 double a1 = (xy_mean - x_mean * y_mean) / (x2_mean - x_mean * x_mean);
81 double a0 = y_mean - a1 * x_mean;
99 auto cumulFun = [a0, a1](
double x) {
return (a0 + 0.5 * a1 *
x) *
x; };
101 double cLeft = cumulFun(
left);
102 for (
size_t i = 0; i < nBins; ++i) {
103 double cRight = cumulFun(
right[i]);
104 out[i] = cRight - cLeft;
116 const size_t nBins)
const {
119 for (
size_t i = 0; i < nBins; ++i) {
120 double xr =
right[i];
121 jacobian->
set(i, 0, xr - xl);
122 jacobian->
set(i, 1, 0.5 * (xr * xr - xl * xl));
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
Represents the Jacobian in IFitFunction::functionDeriv.
virtual void set(size_t iY, size_t iP, double value)=0
Set a value to a Jacobian matrix element.
void setParameter(size_t, const double &value, bool explicitlySet=true) override
Set i-th parameter.
double getParameter(size_t i) const override
Get i-th parameter.
Provide linear function interface to IFunction.
void function1D(double *out, const double *xValues, const size_t nData) const override
Function you want to fit to.
void histogram1D(double *out, double left, const double *right, const size_t nBins) const override
Calculate histogram data.
void functionDeriv1D(API::Jacobian *out, const double *xValues, const size_t nData) override
Derivatives of function with respect to active parameters.
void fit(const std::vector< double > &X, const std::vector< double > &Y) override
Do linear fit to the data in X and Y.
void histogramDerivative1D(API::Jacobian *jacobian, double left, const double *right, const size_t nBins) const override
Devivatives of the histogram.