14 #define SIMPLEFITS_H 1
22 #include <type_traits>
36 template <
typename T,
unsigned int D>
56 template <
unsigned int Power,
unsigned int N>
60 {
return sums.template SumN<N>(); }
64 template <
unsigned int Power>
73 static constexpr
unsigned int Degree = D;
109 {
return add(std::get<0>(value), std::get<1>(value), sy); }
121 add(std::get<0>(value), std::get<1>(value), std::get<2>(value));
134 template <
typename Iter>
151 template <
typename Iter,
typename Pred>
168 template <
typename Cont,
typename Pred>
182 template <
typename Cont>
214 typename VIter,
typename UIter,
215 typename VPred,
typename UPred =
identity
218 VIter begin_value, VIter end_value,
219 UIter begin_uncertainty,
220 VPred value_extractor,
221 UPred uncertainty_extractor = UPred()
239 template <
typename Iter>
253 template <
typename Cont>
266 int N()
const {
return s2.
N(); }
282 template <
typename V>
283 static constexpr
V sqr(
V const& v) {
return v*v; }
288 {
return (n == 0)?
s2.
Weights(): x.Sum(n); }
292 {
return (n == 0)? y.Weights():
xy.
Sum(n); }
296 template <
unsigned int N>
301 template <
unsigned int N>
313 template <
typename Stream>
322 {
return Data_t(1.)/std::sqrt(w); }
336 template <
typename T,
unsigned int D>
337 inline std::ostream&
operator<<
339 { stats.Print(out);
return out; }
343 template <
typename T,
unsigned int D>
376 template <
typename Iter>
380 template <
typename Iter,
typename Pred>
384 template <
typename Cont,
typename Pred>
388 template <
typename Cont>
394 typename VIter,
typename UIter,
395 typename VPred,
typename UPred =
identity
398 VIter begin_value, VIter end_value,
399 UIter begin_uncertainty,
400 VPred value_extractor,
401 UPred uncertainty_extractor = UPred()
405 begin_value, end_value, begin_uncertainty,
406 value_extractor, uncertainty_extractor);
410 template <
typename Iter>
414 template <
typename Cont>
435 template <
typename Stream>
440 template <
typename V>
457 template <
typename T,
unsigned int N>
489 virtual bool isValid()
const = 0;
550 virtual int NDF()
const = 0;
636 template <
typename T,
unsigned int D>
672 virtual bool isValid()
const override;
848 template <
typename T>
952 template <
typename T>
1017 template <
typename T>
1051 {
return add(std::get<0>(value), std::get<1>(value), sy); }
1056 add(std::get<0>(value), std::get<1>(value), std::get<2>(value));
1060 template <
typename Iter>
1064 template <
typename Iter,
typename Pred>
1067 template <
typename Cont,
typename Pred>
1071 template <
typename Cont>
1077 typename VIter,
typename UIter,
1078 typename VPred,
typename UPred =
identity
1081 VIter begin_value, VIter end_value,
1082 UIter begin_uncertainty,
1083 VPred value_extractor,
1084 UPred uncertainty_extractor = UPred()
1088 template <
typename Iter>
1091 template <
typename Cont>
1104 template <
typename Stream>
1248 struct Value_t:
public std::tuple<Data_t, Data_t> {
1273 {
return { std::log(value), error /
std::abs(value) }; }
1285 return { v, v * value.
error() };
1300 return { std::get<0>(meas), value.
value(), value.
error() };
1308 return { std::get<0>(meas), value.
value(), value.
error() };
1314 template <
typename VPred,
typename UPred =
void>
1322 template <
typename Elem>
1338 template <
typename Pred>
1363 template <
typename Pred>
1366 template <
typename VPred,
typename UPred>
1368 {
return { vpred, upred }; }
1426 {
throw std::logic_error(
"Method " +
method +
"() not implemented"); }
1444 template <
typename T,
unsigned int D>
1448 Data_t w = UncertaintyToWeight(sy);
1449 if (!std::isnormal(w))
return false;
1457 y2.add(
sqr(y_value), w);
1458 xy.add(x_value, yw);
1464 template <
typename T,
unsigned int D>
1465 template <
typename Iter,
typename Pred>
1470 (begin, end, [
this, extractor](
auto item) { this->add(extractor(item)); });
1474 template <
typename T,
unsigned int D>
1475 template <
typename VIter,
typename UIter,
typename VPred,
typename UPred>
1478 VIter begin_value, VIter end_value,
1479 UIter begin_uncertainty,
1480 VPred value_extractor,
1481 UPred uncertainty_extractor
1484 while (begin_value != end_value) {
1486 (value_extractor(*begin_value), uncertainty_extractor(*begin_uncertainty))
1490 ++begin_uncertainty;
1496 template <
typename T,
unsigned int D>
1497 template <
typename Iter>
1499 (Iter begin, Iter end)
1501 unsigned int old_n =
N();
1502 std::for_each(begin, end, [
this](
auto p) { this->add(
p); });
1508 template <
typename T,
unsigned int D>
1518 template <
typename T,
unsigned int D>
template <
typename Stream>
1521 out <<
"Sums 1/s^2=" << s2.Weights()
1522 <<
"\n x/s^2=" << x.template SumN<1>();
1523 for (
unsigned int degree = 2; degree <= x.Power; ++degree)
1524 out <<
"\n x^" << degree <<
"/s^2=" << x.Sum(degree);
1526 <<
"\n y/s^2=" << y.Weights()
1527 <<
"\n y^2/s^2=" << y2.Sum();
1529 out <<
"\n xy/s^2=" << xy.template SumN<1>();
1530 for (
unsigned int degree = 2; degree <= xy.Power; ++degree)
1531 out <<
"\n x^" << degree <<
"y/s^2=" << xy.Sum(degree);
1539 template <
typename T,
unsigned int D>
1542 && std::isnormal(Determinant(MakeMatrixX()));
1546 template <
typename T,
unsigned int D>
1550 return Param(n, MakeMatrixX());
1554 template <
typename T,
unsigned int D>
1558 if (n > Degree)
return Data_t(0);
1559 return std::sqrt(FitParameterCovariance()[n * (NParams + 1)]);
1563 template <
typename T,
unsigned int D>
1569 for (
unsigned int iParam = 0; iParam < NParams; ++iParam)
1570 fit_params[iParam] =
Param(iParam, Xmat);
1575 template <
typename T,
unsigned int D>
1579 return FitParameterErrors(FitParameterCovariance());
1583 template <
typename T,
unsigned int D>
1588 Data_t det = Determinant(Xmat);
1589 if (!std::isnormal(det)) {
1590 throw std::range_error
1591 (
"SimplePolyFitterBase::FitParameterCovariance(): determinant 0 while fitting");
1593 return InvertMatrix(Xmat, det);
1597 template <
typename T,
unsigned int D>
1603 Xmat = MakeMatrixX();
1604 det = Determinant(Xmat);
1605 if (!std::isnormal(det)) {
1610 Smat = InvertMatrix(Xmat, det);
1611 params = FitParameters(Smat, det);
1616 template <
typename T,
unsigned int D>
1622 if (!this->FillResults(params, Xmat, det, Smat))
return false;
1623 paramerrors = ExtractParameterErrors(Smat);
1628 template <
typename T,
unsigned int D>
1636 return FillResults(params, paramerrors, Xmat, det, Smat);
1640 template <
typename T,
unsigned int D>
1645 unsigned int iParam = NParams - 1;
1646 Data_t v = params[iParam];
1647 while (iParam > 0) v = v * x + params[--iParam];
1653 template <
typename T,
unsigned int D>
1658 for (
unsigned int i = 0; i < NParams; ++i) {
1659 for (
unsigned int j = i; j < NParams; ++j) {
1660 Xmat[j * NParams + i] = Xmat[i * NParams + j] = Base_t::XN(i+j);
1667 template <
typename T,
unsigned int D>
1672 for (
unsigned int i = 0; i < NParams; ++i) Ymat[i] = Base_t::XNY(i);
1677 template <
typename T,
unsigned int D>
1683 for (
unsigned int iParam = 0; iParam < NParams; ++iParam)
1684 fit_params[iParam] =
Param(iParam, Xmat);
1689 template <
typename T,
unsigned int D>
1694 return MatrixProduct(Smat, MakeMatrixY());
1698 template <
typename T,
unsigned int D>
1702 if (n > Degree)
return Data_t(0);
1704 Data_t detXmat = Determinant(Xmat);
1705 if (!std::isnormal(detXmat)) {
1706 throw std::range_error
1707 (
"SimplePolyFitterBase::Param(): Determinant 0 while fitting");
1709 return Param(n, Xmat, detXmat);
1713 template <
typename T,
unsigned int D>
1719 for (
unsigned int iParam = 0; iParam <= Degree; ++iParam)
1720 fit_errors[iParam] = std::sqrt(Smat[iParam * (NParams + 1)]);
1725 template <
typename T,
unsigned int D>
1729 if (n > Degree)
return Data_t(0);
1733 for (
unsigned int i = 0; i < NParams; ++i)
1734 XYmat[i * NParams + n] = Base_t::XNY(i);
1736 return Determinant(XYmat) / detXmat;
1740 template <
typename T,
unsigned int D>
1745 throw std::logic_error
1746 (
"SimplePolyFitterBase::ChiSquare() not implemented for generic fit");
1755 template <
typename T>
1759 const Data_t b = fit_params[0];
1760 const Data_t a = fit_params[1];
1761 return Y2() +
sqr(a) * X2() +
sqr(b) *
I()
1762 +
Data_t(2) * (a * b * X2() - a * XY() - b * Y());
1770 template <
typename T>
1774 return Y2() -
Data_t(2) * (a[0]*Y() + a[1]*XY() + a[2]*X2Y())
1775 +
sqr(a[0])*
I() +
Data_t(2) * a[0] * ( a[1]*
X() + a[2]*X2() )
1776 +
sqr(a[1])*X2() +
Data_t(2) * a[1] * ( a[2]*X3() )
1788 template <
typename T>
1792 if (y <=
Data_t(0))
return false;
1794 return fitter.add(x, value.
value(), value.
error());
1798 template <
typename T>
1799 template <
typename Iter,
typename Pred>
1801 (Iter begin, Iter end, Pred extractor)
1803 return fitter.add_without_uncertainty(begin, end, Encoder(extractor));
1807 template <
typename T>
1809 typename VIter,
typename UIter,
1810 typename VPred,
typename UPred
1813 VIter begin_value, VIter end_value,
1814 UIter begin_uncertainty,
1815 VPred value_extractor,
1816 UPred uncertainty_extractor
1819 return add_with_uncertainty(
1820 begin_value, end_value, begin_uncertainty,
1821 Encoder(value_extractor, uncertainty_extractor)
1826 template <
typename T>
1827 template <
typename Iter>
1829 (Iter begin, Iter end)
1831 unsigned int old_n =
N();
1832 std::for_each(begin, end, [
this](
auto p) { this->add(
p); });
1840 template <
typename T>
1842 return ConvertParameters(fitter.FitParameters());
1846 template <
typename T>
1849 if (!FillResults(qpars, qparerrors)) {
1850 throw std::runtime_error
1851 (
"GaussianFit::FitParameterErrors() yielded invalid results");
1857 template <
typename T>
1865 if (!FillResults(params, Xmat, det, Smat)) {
1866 throw std::runtime_error
1867 (
"GaussianFit::FitParameterCovariance() yielded invalid results");
1873 template <
typename T>
1881 if (!fitter.FillResults(qpars, Xmat, det, qparerrmat))
return false;
1882 ConvertParametersAndErrors(qpars, qparerrmat, params, paramerrors);
1883 return isValid(params, qpars);
1887 template <
typename T>
1893 if (!fitter.FillResults(qpars, Xmat, det, qparerrmat))
return false;
1894 ConvertParametersAndErrorMatrix(qpars, qparerrmat, params, Smat);
1895 return isValid(params, qpars);
1899 template <
typename T>
1904 if (!FillResults(params, Xmat, det, Smat))
return false;
1905 paramerrors = fitter.ExtractParameterErrors(Smat);
1910 template <
typename T>
1914 Data_t z = (x - params[1]) / params[2];
1919 template <
typename T>
1926 Data_t sigma2 = -0.5 / qpars[2];
1927 params[2] = std::sqrt(sigma2);
1929 params[1] = sigma2 * qpars[1];
1931 params[0] =
std::exp(qpars[0] - 0.25 *
sqr(qpars[1])/qpars[2]);
1937 template <
typename T>
1943 params = ConvertParameters(qpars);
1948 Data_t const& sigma = params[2];
1951 paramvariances[2] = qparerrmat[3 * 2 + 2] /
sqr(
cube(sigma));
1954 paramvariances[1] =
sqr(mu * (
1955 + qparerrmat[3 * 1 + 1] /
sqr(a[1])
1956 - 2.*qparerrmat[3 * 2 + 1] / (a[1]*a[2])
1957 + qparerrmat[3 * 2 + 2] /
sqr(a[2])
1961 paramvariances[0] =
sqr(A * (
1962 + qparerrmat[3 * 0 + 0]
1963 + 2.*qparerrmat[3 * 0 + 1] * mu
1964 +( qparerrmat[3 * 1 + 1]
1965 + 2.*qparerrmat[3 * 0 + 2]) *
sqr(mu)
1966 + 2.*qparerrmat[3 * 1 + 2] *
cube(mu)
1967 + qparerrmat[3 * 2 + 2] *
sqr(
sqr(mu))
1973 template <
typename T>
1979 ConvertParametersAndVariances(qpars, qparerrmat, params, paramerrors);
1981 for (
Data_t& paramerror: paramerrors) paramerror = std::sqrt(paramerror);
1985 template <
typename T>
1992 ConvertParametersAndVariances(qpars, qparerrmat, params, paramvariances);
1998 Data_t const& sigma = params[2];
2001 Smat[3 * 2 + 2] = paramvariances[2];
2004 Smat[3 * 1 + 1] = paramvariances[1];
2007 Smat[3 * 0 + 0] = paramvariances[0];
2010 Smat[3 * 1 + 2] = Smat[3 * 2 + 1]
2011 = (qparerrmat[3 * 1 + 2] + 2 * mu * qparerrmat[3 * 2 + 2]) / sigma;
2015 const Data_t dA_dak_cov_aka2 = A * (
2016 qparerrmat[3 * 0 + 2]
2017 + qparerrmat[3 * 1 + 2] * mu
2018 + qparerrmat[3 * 2 + 2] *
sqr(mu)
2021 Smat[3 * 0 + 2] = Smat[3 * 2 + 0]
2022 = dA_dak_cov_aka2 /
cube(sigma);
2025 const Data_t dA_dak_cov_aka1 = A * (
2026 qparerrmat[3 * 0 + 1]
2027 + qparerrmat[3 * 1 + 1] * mu
2028 + qparerrmat[3 * 2 + 1] *
sqr(mu)
2032 Smat[3 * 0 + 1] = Smat[3 * 1 + 0] = mu *
2033 (dA_dak_cov_aka1 / a[1] - dA_dak_cov_aka2 / a[2]);
2038 template <
typename T>
2042 return (qpars[2] <
Data_t(0)) && (params[0] >=
Data_t(0));
2049 #endif // SIMPLEFITS_H
static constexpr Data_t cube(Data_t v)
Returns the cube of the specified data value.
Weight_t Weights() const
Returns the sum of the weights.
void add_without_uncertainty(Iter begin, Iter end)
Adds measurements from a sequence, with no uncertainty.
see a below echo or echo I(indirect symbol).'echo" If the symbol is local (non-external)
process_name opflash particleana ie ie ie z
static constexpr unsigned int NParams
Number of parameters in the fit.
static constexpr unsigned int NParams
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
bool add(MeasurementAndUncertainty_t value)
virtual Data_t ChiSquare() const override
Returns the of the fit.
static constexpr unsigned int Degree
Degree of the fit.
int N() const
Returns the number of entries added.
Data_t InterceptError() const
Returns the error on intercept of the fit.
unsigned int add_with_uncertainty(Iter begin, Iter end)
unsigned int add_with_uncertainty(VIter begin_value, VIter end_value, UIter begin_uncertainty, VPred value_extractor, UPred uncertainty_extractor=UPred())
Adds measurements with uncertainties from a sequence.
void add_without_uncertainty(Iter begin, Iter end)
bool add(Data_t x, Data_t y, Data_t sy=Data_t(1.0))
typename Base_t::Data_t Data_t
type of the data
unsigned int add_with_uncertainty(VIter begin_value, VIter end_value, UIter begin_uncertainty, VPred value_extractor, UPred uncertainty_extractor=UPred())
virtual FitParameters_t FitParameterErrors() const =0
Computes and returns all the parameter errors of the fit result.
virtual FitMatrix_t InvertMatrix(FitMatrix_t const &mat, Data_t det) const
Computes the inverse of a matrix (using provided determinant)
virtual Data_t FitParameterError(unsigned int n) const override
Returns the error on parameter n of the fit result.
Data_t XN(unsigned int n) const
Returns the weighted sum of x^n.
virtual FitMatrix_t FitParameterCovariance() const =0
Computes and returns all the covariance matrix of the fit result.
static Data_t Determinant(Matrix_t const &mat)
Computes the determinant of a matrix.
constexpr Data_t error() const
Data_t operator()(Data_t x) const
Evaluates the fitted function; alias of Evaluate()
virtual Data_t FitParameterError(unsigned int n) const
Returns the error on parameter n of the fit result.
void add_without_uncertainty(Cont cont)
static void ThrowNotImplemented(std::string method)
Data_t XN(unsigned int n) const
Returns the weighted sum of x^n.
bool FillResults(FitParameters_t ¶ms, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const override
Fills the specified parameters.
static constexpr unsigned int NParams
Number of parameters in the fit.
Data_t XN() const
Returns the weighted sum of x^N.
typename Collector_t::Data_t Data_t
type of the data
Weight_t AverageWeight() const
Returns the arithmetic average of the weights.
unsigned int add_with_uncertainty(Cont cont)
std::array< Data_t, sqr(NParams)> FitMatrix_t
unsigned int add_with_uncertainty(VIter begin_value, VIter end_value, UIter begin_uncertainty, VPred value_extractor, UPred uncertainty_extractor=UPred())
static Data_t UncertaintyToWeight(Data_t s)
Transforms an uncertainty into a weight ( )
< type of value and error
virtual FitParameters_t FitParameters() const =0
Computes and returns all the parameters of the fit result.
static constexpr Data_t sqr(Data_t v)
Returns the square of the specified data value.
WeightTracker< Data_t > y
accumulator for y
static void ConvertParametersAndVariances(FitParameters_t const &qpars, FitMatrix_t const &qparerrmat, FitParameters_t ¶ms, FitParameters_t ¶mvariances)
Converts the specified quadratic fit parameters and errors.
virtual Data_t ChiSquare() const override
Returns the of the original fit.
virtual Data_t FitParameter(unsigned int n) const override
Returns the parameter n of the fit result.
virtual Data_t Param(unsigned int n, FitMatrix_t const &Xmat) const
Computes a single fit parameter using the given information.
bool add(Measurement_t value, Data_t sy=Data_t(1.0))
virtual FitParameters_t FitParameterErrors() const override
Computes and returns all the parameter errors of the fit result.
static Value_t EncodeValue(Data_t value, Data_t error)
Converts a value and error into a proper input for the quadratic fit.
Class providing data collection for the simple polynomial fitters.
typename Fitter_t::FitMatrix_t FitMatrix_t
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker see the discussion of warn common echo in *Note Linker such as a global int variable echo as opposed to a large global array echo echo I echo The symbol is an indirect reference to another symbol This echo is a GNU extension to the a out object file format which is echo rarely used echo echo N echo The symbol is a debugging symbol echo echo R echo The symbol is in a read only data section echo echo S echo The symbol is in an uninitialized data section for small echo objects echo echo T echo The symbol is in the the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo W echo The symbol is a weak symbol that has not been specifically echo tagged as a weak object symbol When a weak defined symbol echo is linked with a normal defined the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo echo The symbol is a stabs symbol in an a out object file In echo this the next values printed are the stabs other echo the stabs desc and the stab type Stabs symbols are echo used to hold debugging information For more echo see *Note or object file format specific echo echo For Mac OS X
static constexpr V sqr(V const &v)
Returns the square of the specified value.
virtual FitParameters_t FitParameterErrors() const override
Computes and returns all the parameter errors of the fit result.
std::tuple< Data_t, Data_t > Base_t
Classes gathering simple statistics.
std::array< Data_t, sqr(NParams)> FitMatrix_t
static Matrix_t InvertSymmetricMatrix(Matrix_t const &mat, Data_t det)
DataTracker< 1, Data_t > y2
accumulator for y2
int N() const
Returns the number of (valid) points added.
virtual bool FillResults(FitParameters_t ¶ms, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const override
Fills the specified parameters.
Value_t(Data_t v, Data_t e)
bool add(MeasurementAndUncertainty_t value)
Adds one entry with specified x, y and uncertainty.
Performs a linear regression of data.
Data_t I() const
Aliases.
static Measurement_t EncodeValue(Measurement_t const &meas)
Converts a value and error into a proper input for the quadratic fit.
Weight_t Sum(unsigned int n) const
Returns the sum of the values to the power n (1 <= n <= 2, no check)
Data_t XNY(unsigned int n) const
Returns the weighted sum of x^n y.
virtual FitMatrix_t MakeMatrixX() const
Fills and returns the matrix of x^n sum coefficients ( { x^(i+j) } )
typename Collector_t::MeasurementAndUncertainty_t MeasurementAndUncertainty_t
type of measurement with uncertainty
Data_t XNY() const
Returns the weighted sum of x^N y.
typename Base_t::Data_t Data_t
type of the data
Classes with hard-coded (hence "fast") matrix math.
Data_t Slope() const
Returns the slope of the fit.
void add_without_uncertainty(Cont cont)
static Value_t DecodeValue(Value_t const &value)
Converts a value from the quadratic fit into a proper value.
virtual FitMatrix_t InvertMatrix(FitMatrix_t const &mat) const
Computes the inverse of a matrix.
unsigned int add_with_uncertainty(Cont cont)
Adds measurements with uncertainties from a container.
static FitParameters_t ConvertParameters(FitParameters_t const &qpars)
Converts the specified quadratic fit parameters into Gaussian.
Provides "fast" matrix operations.
constexpr Data_t value() const
WeightTracker< Data_t > s2
accumulator for uncertainty
Data_t InterceptSlopeCovariance() const
Returns the covariance between intercept and slope of the fit.
Data_t Intercept() const
Returns the intercept of the fit.
DataTracker< Degree *2, Data_t > x
accumulator for variable x^k
auto end(FixedBins< T, C > const &) noexcept
A unary functor returning its own argument (any type)
std::array< Data_t, NParams > FitParameters_t
type of set of fit parameters
void add_without_uncertainty(Cont cont, Pred extractor)
void add_without_uncertainty(Cont cont, Pred extractor)
static void ConvertParametersAndErrors(FitParameters_t const &qpars, FitMatrix_t const &qparerrmat, FitParameters_t ¶ms, FitParameters_t ¶merrors)
Converts the specified quadratic fit parameters and errors.
typename Interface_t::FitParameters_t FitParameters_t
type of set of fit parameters
static Data_t WeightToUncertainty(Data_t w)
Transforms a weight back to an uncertainty ( )
int N() const
Returns the number of entries added.
void add_without_uncertainty(Cont cont, Pred extractor)
Adds all measurements from a container, with no uncertainty.
void PrintStats(Stream &out) const
Prints the collected statistics into a stream.
void clear()
Clears all the statistics.
void add_without_uncertainty(Iter begin, Iter end)
"Fast" Gaussian fit
virtual FitParameters_t MatrixProduct(FitMatrix_t const &mat, FitParameters_t const &vec) const
Computes the product of a FitMatrix_t and a FitParameters_t.
Class tracking sums of variables up to a specified power.
virtual ~SimpleFitterInterface()=default
Virtual destructor: compiler's default.
Data_t SlopeError() const
Returns the error in slope of the fit.
bool add(Measurement_t value, Data_t sy=Data_t(1.0))
std::array< Data_t, NParams > FitParameters_t
type of set of fit parameters
Data_t AverageUncertainty() const
Value_t(MeasurementAndUncertainty_t meas)
Data_t AverageUncertainty() const
Returns an average of the uncertainties.
static Value_t EncodeValue(Value_t const &value)
Converts a value and error into a proper input for the quadratic fit.
Data_t XNY(unsigned int n) const
Returns the weighted sum of x^n y.
Performs a second-degree fit of data.
typename Interface_t::FitMatrix_t FitMatrix_t
type of matrix for covariance (a std::array)
typename MatrixOps::Matrix_t FitMatrix_t
type of matrix for covariance (a std::array)
auto begin(FixedBins< T, C > const &) noexcept
void Print(Stream &out) const
Prints the statistics into a stream.
static Vector_t MatrixVectorProduct(Matrix_t const &mat, Vector_t const &vec)
Returns the product of a square matrix times a column vector.
virtual bool isValid() const override
Returns if the fit has valid results.
Fitter_t fitter
the actual fitter and data holder
static constexpr V sqr(V const &v)
Returns the square of the specified value.
std::tuple< Data_t, Data_t > Measurement_t
type of measurement without uncertainty
static FitParameters_t ExtractParameterErrors(FitMatrix_t const &Smat)
Extracts parameter errors from diagonal of the covarriance matrix.
virtual Data_t Evaluate(Data_t x) const override
Evaluates the fitted function at the specified point.
virtual Fitter_t const & Fitter() const
Returns the internal fitter (mostly for debugging)
DataTracker< Degree, Data_t > xy
accumulator for variable xy
virtual int NDF() const override
Returns the degrees of freedom in the determination of the fit.
Data_t I() const
Aliases.
Base class providing virtual fitting interface for polynomial fitters.
bool add(MeasurementAndUncertainty_t value)
Base class providing data collection for the simple polynomial fitters.
typename Fitter_t::Measurement_t Measurement_t
type of measurement without uncertainty
then echo File list $list not found else cat $list while read file do echo $file sed s
Simple fitter abstract interface.
virtual FitMatrix_t FitParameterCovariance() const override
Computes and returns all the covariance matrix of the fit result.
typename Fitter_t::MeasurementAndUncertainty_t MeasurementAndUncertainty_t
type of measurement with uncertainty
bool add(Measurement_t value, Data_t sy=Data_t(1.0))
Adds one entry with specified x, y and uncertainty.
virtual bool isValid() const =0
Returns if the fit has valid results.
virtual FitParameters_t MakeMatrixY() const
Fills and returns the matrix (vector) of x^n y sum coefficients.
void clear()
Clears all the statistics.
process_name largeant stream1 can override from command line with o or output physics producers generator N
static EncodeExtractor< VPred, UPred > Encoder(VPred &vpred, UPred &upred)
virtual Data_t ChiSquare() const override
Returns the of the fit.
static constexpr unsigned int Degree
Degree of the fit.
virtual Data_t Determinant(FitMatrix_t const &mat) const
Computes the determinant of a matrix.
void add_without_uncertainty(Cont cont)
Adds all measurements from a container, with no uncertainty.
void clear()
Clears all the input statistics.
virtual FitParameters_t FitParameters() const override
Computes and returns all the parameters of the fit result.
virtual Data_t ChiSquare() const =0
Returns the of the fit.
static constexpr unsigned int Degree
Degree of the fit.
unsigned int add_with_uncertainty(Cont cont)
virtual Data_t Evaluate(Data_t x) const override
Evaluates the fitted function at the specified point.
static constexpr unsigned int NParams
Number of parameters in the fit.
virtual FitMatrix_t FitParameterCovariance() const override
Computes and returns all the covariance matrix of the fit result.
void add_without_uncertainty(Iter begin, Iter end, Pred extractor)
static void ConvertParametersAndErrorMatrix(FitParameters_t const &qpars, FitMatrix_t const &qparerrmat, FitParameters_t ¶ms, FitMatrix_t &Smat)
Converts the specified quadratic fit parameters and errors.
virtual bool FillResults(FitParameters_t ¶ms, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const =0
Fills the specified parameters.
virtual int NDF() const =0
Returns the degrees of freedom in the determination of the fit.
typename Base_t::Matrix_t Matrix_t
typename Collector_t::Measurement_t Measurement_t
type of measurement without uncertainty
virtual bool isValid() const override
Returns if the fit has valid results.
std::array< Data_t, NParams > FitParameters_t
type of set of fit parameters
typename Fitter_t::FitParameters_t FitParameters_t
static Data_t DecodeValue(Data_t value)
Converts a value from the quadratic fit into a proper value.
static Data_t EncodeValue(Data_t value)
virtual int NDF() const override
Returns the degrees of freedom in the determination of the fit.
virtual Data_t FitParameter(unsigned int n) const
Returns the parameter n of the fit result.
bool add(Data_t x, Data_t y, Data_t sy=Data_t(1.0))
static EncodeExtractor< Pred > Encoder(Pred &pred)
Collector_t stats
statistics collected from fit data input
bool add(Data_t x, Data_t y, Data_t sy=Data_t(1.0))
Adds one entry with specified x, y and uncertainty.
virtual Data_t Evaluate(Data_t x) const =0
Evaluates the fitted function at the specified point.
void PrintStats(Stream &out) const
Prints the collected statistics into a stream.
Data_t Y2() const
Returns the weighted sum of y^2.
std::tuple< Data_t, Data_t, Data_t > MeasurementAndUncertainty_t
type of measurement with uncertainty
virtual FitParameters_t FitParameters() const override
Computes and returns all the parameters of the fit result.
virtual Data_t ChiSquare() const override
Returns the of the fit.