LArSoft
v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
|
Class providing data collection for the simple polynomial fitters. More...
#include "SimpleFits.h"
Classes | |
struct | SumExtractor |
struct | SumExtractor< Power, 0U > |
Public Types | |
using | Data_t = T |
type of the data More... | |
using | Measurement_t = std::tuple< Data_t, Data_t > |
type of measurement without uncertainty More... | |
using | MeasurementAndUncertainty_t = std::tuple< Data_t, Data_t, Data_t > |
type of measurement with uncertainty More... | |
Public Member Functions | |
void | clear () |
Clears all the statistics. More... | |
template<typename Stream > | |
void | Print (Stream &out) const |
Prints the statistics into a stream. More... | |
Add elements | |
bool | add (Data_t x, Data_t y, Data_t sy=Data_t(1.0)) |
Adds one entry with specified x, y and uncertainty. More... | |
bool | add (Measurement_t value, Data_t sy=Data_t(1.0)) |
Adds one entry with specified x, y and uncertainty. More... | |
bool | add (MeasurementAndUncertainty_t value) |
Adds one entry with specified x, y and uncertainty. More... | |
template<typename Iter > | |
void | add_without_uncertainty (Iter begin, Iter end) |
Adds measurements from a sequence, with no uncertainty. More... | |
template<typename Iter , typename Pred > | |
void | add_without_uncertainty (Iter begin, Iter end, Pred extractor) |
Adds measurements from a sequence with no uncertainty. More... | |
template<typename Cont , typename Pred > | |
void | add_without_uncertainty (Cont cont, Pred extractor) |
Adds all measurements from a container, with no uncertainty. More... | |
template<typename Cont > | |
void | add_without_uncertainty (Cont cont) |
Adds all measurements from a container, with no uncertainty. More... | |
template<typename VIter , typename UIter , typename VPred , typename UPred = identity> | |
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. More... | |
template<typename Iter > | |
unsigned int | add_with_uncertainty (Iter begin, Iter end) |
Adds measurements with uncertainties from a sequence. More... | |
template<typename Cont > | |
unsigned int | add_with_uncertainty (Cont cont) |
Adds measurements with uncertainties from a container. More... | |
Static Public Member Functions | |
static Data_t | UncertaintyToWeight (Data_t s) |
Transforms an uncertainty into a weight ( ) More... | |
static Data_t | WeightToUncertainty (Data_t w) |
Transforms a weight back to an uncertainty ( ) More... | |
Static Public Attributes | |
static constexpr unsigned int | Degree = D |
Degree of the fit. More... | |
static constexpr unsigned int | NParams = Degree + 1 |
Protected Attributes | |
WeightTracker< Data_t > | s2 |
accumulator for uncertainty More... | |
DataTracker< Degree *2, Data_t > | x |
accumulator for variable x^k More... | |
WeightTracker< Data_t > | y |
accumulator for y More... | |
DataTracker< 1, Data_t > | y2 |
accumulator for y2 More... | |
DataTracker< Degree, Data_t > | xy |
accumulator for variable xy More... | |
Statistic retrieval | |
int | N () const |
Returns the number of entries added. More... | |
Data_t | AverageUncertainty () const |
Returns an average of the uncertainties. More... | |
Data_t | XN (unsigned int n) const |
Returns the weighted sum of x^n. More... | |
Data_t | XNY (unsigned int n) const |
Returns the weighted sum of x^n y. More... | |
template<unsigned int N> | |
Data_t | XN () const |
Returns the weighted sum of x^N. More... | |
template<unsigned int N> | |
Data_t | XNY () const |
Returns the weighted sum of x^N y. More... | |
Data_t | Y2 () const |
Returns the weighted sum of y^2. More... | |
template<typename V > | |
static constexpr V | sqr (V const &v) |
Returns the square of the specified value. More... | |
Class providing data collection for the simple polynomial fitters.
Definition at line 36 of file SimpleFits.h.
using lar::util::details::FitDataCollector< T, D >::Data_t = T |
type of the data
Definition at line 77 of file SimpleFits.h.
using lar::util::details::FitDataCollector< T, D >::Measurement_t = std::tuple<Data_t, Data_t> |
type of measurement without uncertainty
Definition at line 80 of file SimpleFits.h.
using lar::util::details::FitDataCollector< T, D >::MeasurementAndUncertainty_t = std::tuple<Data_t, Data_t, Data_t> |
type of measurement with uncertainty
Definition at line 83 of file SimpleFits.h.
bool lar::util::details::FitDataCollector< T, D >::add | ( | Data_t | x, |
Data_t | y, | ||
Data_t | sy = Data_t(1.0) |
||
) |
Adds one entry with specified x, y and uncertainty.
x | value of x |
y | value of y |
sy | value of uncertainty on y (1 by default) |
If the uncertainty is exactly 0, the entry is ignored and not added.
Definition at line 1412 of file SimpleFits.h.
References lar::util::details::WeightTracker< W >::add(), lar::util::details::DataTracker< PWR, T, W >::add(), lar::util::details::FitDataCollector< T, D >::s2, lar::util::details::FitDataCollector< T, D >::sqr(), lar::util::details::FitDataCollector< T, D >::UncertaintyToWeight(), w, lar::util::details::FitDataCollector< T, D >::xy, and lar::util::details::FitDataCollector< T, D >::y2.
Referenced by lar::util::details::FitDataCollector< T, D >::add(), lar::util::GaussianFit< T >::add(), lar::util::details::FitDataCollector< T, D >::add_with_uncertainty(), lar::util::GaussianFit< T >::add_with_uncertainty(), and lar::util::details::FitDataCollector< T, D >::add_without_uncertainty().
|
inline |
Adds one entry with specified x, y and uncertainty.
value | the ( x ; y ) pair |
sy | value of uncertainty on y (1 by default) |
If the uncertainty is exactly 0, the entry is ignored and not added.
Definition at line 109 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::add().
|
inline |
Adds one entry with specified x, y and uncertainty.
value | ( x ; y ; sy ), sy being the uncertainty on y |
If the uncertainty is exactly 0, the entry is ignored and not added.
Definition at line 121 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::add().
unsigned int lar::util::details::FitDataCollector< T, D >::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.
VIter | forward iterator to the elements to be added |
UIter | forward iterator to the uncertainties |
VPred | predicate to extract the measurement from iterator value |
UPred | predicate to extract the uncertainty from iterator value |
begin_value | iterator to the first measurement to be added |
end_value | iterator after the last measurement to be added |
begin_uncertainty | iterator to the uncertainty of first measurement |
value_extractor | predicate extracting the measurement to be inserted |
uncertainty_extractor | predicate extracting the uncertainty |
Each element is added with the uncertainty pointed by the matching element in the list pointed by begin_weight: the measurement of *(begin_value)
will have uncertainty *(begin_uncertainty)
, the next measurement *(begin_value + 1)
will have uncertainty *(begin_uncertainty + 1)
, etc.
The predicates are required to react to a call like with:
Measurement_t VPred::operator() (typename VIter::value_type); Data_t UPred::operator() (typename UIter::value_type);
Points with zero or infinite uncertainty are ignored and not added.
Definition at line 1442 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::add(), and n.
Referenced by lar::util::details::FitDataCollector< T, D >::add_with_uncertainty(), lar::util::GaussianFit< T >::add_with_uncertainty(), lar::util::details::FitDataCollector< T, D >::add_without_uncertainty(), and lar::util::GaussianFit< T >::add_without_uncertainty().
unsigned int lar::util::details::FitDataCollector< T, D >::add_with_uncertainty | ( | Iter | begin, |
Iter | end | ||
) |
Adds measurements with uncertainties from a sequence.
Iter | forward iterator to MeasurementAndUncertainty_t to be added |
begin | iterator pointing to the first measurement to be added |
end | iterator pointing after the last measurement to be added |
The value pointed by the iterator must be a MeasurementAndUncertainty_t or something with elements convertible to its own (Data_t triplet). For more complicate structures, use the version with two predicates (using the uncertainty iterator the same as the measurement iterator).
Points with zero or infinite uncertainty are ignored and not added.
Definition at line 1461 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::add(), and lar::util::details::FitDataCollector< T, D >::N().
|
inline |
Adds measurements with uncertainties from a container.
Cont | type of container of MeasurementAndUncertainty_t elements |
cont | container of MeasurementAndUncertainty_t to be added |
The values in the container must be tuples with each element convertible to Data_t.
Points with zero or infinite uncertainty are ignored and not added.
Definition at line 255 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::add_with_uncertainty(), util::begin(), lar::util::details::FitDataCollector< T, D >::clear(), and util::end().
|
inline |
Adds measurements from a sequence, with no uncertainty.
Iter | forward iterator to the pairs to be added |
begin | iterator pointing to the first element to be added |
end | iterator pointing after the last element to be added |
The value pointed by the iterator must be a tuple with types compatible with Measurement_t.
Definition at line 136 of file SimpleFits.h.
References util::begin(), and util::end().
Referenced by lar::util::details::FitDataCollector< T, D >::add_without_uncertainty(), and lar::util::GaussianFit< T >::add_without_uncertainty().
void lar::util::details::FitDataCollector< T, D >::add_without_uncertainty | ( | Iter | begin, |
Iter | end, | ||
Pred | extractor | ||
) |
Adds measurements from a sequence with no uncertainty.
Iter | forward iterator to the elements to be added |
Pred | a predicate to extract the element from iterator value |
begin | iterator pointing to the first element to be added |
end | iterator pointing after the last element to be added |
extractor | the predicate extracting the value to be inserted |
The predicate is required to react to a call like with:
Measurement_t Pred::operator() (typename Iter::value_type);
Definition at line 1433 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::add().
|
inline |
Adds all measurements from a container, with no uncertainty.
Cont | type of container of the elements to be added |
Pred | a predicate to extract the element from iterator value |
cont | container of the elements to be added |
extractor | the predicate extracting the value to be inserted |
The predicate is required to react to a call like with:
Measurement_t Pred::operator() (typename Cont::value_type);
The container must support the range-based for loop syntax, that is is must have std::begin<Cont>() and std::end<Cont>() defined.
Definition at line 172 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::add_without_uncertainty(), util::begin(), and util::end().
|
inline |
Adds all measurements from a container, with no uncertainty.
Cont | type of container of the elements to be added |
cont | container of the elements to be added |
The container must support the range-based for loop syntax, that is is must have std::begin<Cont>() and std::end<Cont>() defined. The value in the container must be convertible to the Measurement_t type.
Definition at line 188 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::add_with_uncertainty(), lar::util::details::FitDataCollector< T, D >::add_without_uncertainty(), util::begin(), and util::end().
|
inline |
Returns an average of the uncertainties.
std::range_error | if no entry was added |
The average is the square root of the harmonic average of the variances (that is, the errors squared):
Definition at line 280 of file SimpleFits.h.
References lar::util::details::WeightTracker< W >::AverageWeight(), lar::util::details::FitDataCollector< T, D >::s2, and lar::util::details::FitDataCollector< T, D >::WeightToUncertainty().
|
inline |
Clears all the statistics.
Definition at line 1469 of file SimpleFits.h.
References lar::util::details::WeightTracker< W >::clear(), lar::util::details::DataTracker< PWR, T, W >::clear(), lar::util::details::FitDataCollector< T, D >::s2, lar::util::details::FitDataCollector< T, D >::xy, and lar::util::details::FitDataCollector< T, D >::y2.
Referenced by lar::util::details::FitDataCollector< T, D >::add_with_uncertainty().
|
inline |
Returns the number of entries added.
Definition at line 269 of file SimpleFits.h.
References lar::util::details::WeightTracker< W >::N(), and lar::util::details::FitDataCollector< T, D >::s2.
Referenced by lar::util::details::FitDataCollector< T, D >::add_with_uncertainty(), and lar::util::GaussianFit< T >::add_with_uncertainty().
void lar::util::details::FitDataCollector< T, D >::Print | ( | Stream & | out | ) | const |
Prints the statistics into a stream.
Definition at line 1480 of file SimpleFits.h.
References lar::util::details::DataTracker< PWR, T, W >::Power, lar::util::details::FitDataCollector< T, D >::s2, lar::util::details::DataTracker< PWR, T, W >::Sum(), lar::util::details::WeightTracker< W >::Weights(), lar::util::details::FitDataCollector< T, D >::xy, and lar::util::details::FitDataCollector< T, D >::y2.
Referenced by lar::util::details::FitDataCollector< T, D >::Y2().
|
inlinestatic |
Returns the square of the specified value.
Definition at line 284 of file SimpleFits.h.
Referenced by lar::util::details::FitDataCollector< T, D >::add(), lar::util::LinearFit< T >::ChiSquare(), lar::util::QuadraticFit< T >::ChiSquare(), lar::util::GaussianFit< T >::ConvertParameters(), lar::util::GaussianFit< T >::ConvertParametersAndErrorMatrix(), lar::util::GaussianFit< T >::ConvertParametersAndVariances(), lar::util::GaussianFit< T >::Evaluate(), and lar::util::details::FitDataCollector< T, D >::UncertaintyToWeight().
|
inlinestatic |
Transforms an uncertainty into a weight ( )
Definition at line 319 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::sqr().
Referenced by lar::util::details::FitDataCollector< T, D >::add().
|
inlinestatic |
Transforms a weight back to an uncertainty ( )
Definition at line 322 of file SimpleFits.h.
Referenced by lar::util::details::FitDataCollector< T, D >::AverageUncertainty().
|
inline |
Returns the weighted sum of x^n.
Definition at line 290 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::s2, and lar::util::details::WeightTracker< W >::Weights().
Referenced by lar::util::details::SimplePolyFitterDataBase< T, D >::XN().
|
inline |
Returns the weighted sum of x^N.
Definition at line 297 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::s2, and lar::util::details::FitDataCollector< T, D >::x.
|
inline |
Returns the weighted sum of x^n y.
Definition at line 293 of file SimpleFits.h.
References lar::util::details::DataTracker< PWR, T, W >::Sum(), and lar::util::details::FitDataCollector< T, D >::xy.
Referenced by lar::util::details::SimplePolyFitterDataBase< T, D >::XNY().
|
inline |
Returns the weighted sum of x^N y.
Definition at line 304 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::xy, and lar::util::details::FitDataCollector< T, D >::y.
|
inline |
Returns the weighted sum of y^2.
Definition at line 310 of file SimpleFits.h.
References lar::util::details::FitDataCollector< T, D >::Print(), and lar::util::details::FitDataCollector< T, D >::y2.
Referenced by lar::util::LinearFit< T >::ChiSquare(), and lar::util::QuadraticFit< T >::ChiSquare().
|
static |
Degree of the fit.
Definition at line 74 of file SimpleFits.h.
Referenced by lar::util::details::SimplePolyFitterBase< T, D >::ExtractParameterErrors().
|
static |
Definition at line 75 of file SimpleFits.h.
Referenced by lar::util::details::SimplePolyFitterBase< T, D >::FitParameters(), lar::util::details::SimplePolyFitterBase< T, D >::MakeMatrixX(), lar::util::details::SimplePolyFitterBase< T, D >::MakeMatrixY(), lar::util::details::SimplePolyFitterBase< T, 2U >::NDF(), and lar::util::details::SimplePolyFitterBase< T, D >::Param().
|
protected |
accumulator for uncertainty
Definition at line 325 of file SimpleFits.h.
Referenced by lar::util::details::FitDataCollector< T, D >::add(), lar::util::details::FitDataCollector< T, D >::AverageUncertainty(), lar::util::details::FitDataCollector< T, D >::clear(), lar::util::details::FitDataCollector< T, D >::N(), lar::util::details::FitDataCollector< T, D >::Print(), and lar::util::details::FitDataCollector< T, D >::XN().
|
protected |
accumulator for variable x^k
Definition at line 326 of file SimpleFits.h.
Referenced by lar::util::details::FitDataCollector< T, D >::XN().
|
protected |
accumulator for variable xy
Definition at line 329 of file SimpleFits.h.
Referenced by lar::util::details::FitDataCollector< T, D >::add(), lar::util::details::FitDataCollector< T, D >::clear(), lar::util::details::FitDataCollector< T, D >::Print(), and lar::util::details::FitDataCollector< T, D >::XNY().
|
protected |
accumulator for y
Definition at line 327 of file SimpleFits.h.
Referenced by lar::util::details::FitDataCollector< T, D >::XNY().
|
protected |
accumulator for y2
Definition at line 328 of file SimpleFits.h.
Referenced by lar::util::details::FitDataCollector< T, D >::add(), lar::util::details::FitDataCollector< T, D >::clear(), lar::util::details::FitDataCollector< T, D >::Print(), and lar::util::details::FitDataCollector< T, D >::Y2().