LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
lar::util::StatCollector2D< T, W > Class Template Reference

Collects statistics on two homogeneous quantities (weighted) More...

#include "StatCollector.h"

Inheritance diagram for lar::util::StatCollector2D< T, W >:
lar::util::details::WeightTracker< W >

Public Types

using Base_t = details::WeightTracker< W >
 
using This_t = StatCollector2D< T, W >
 this type More...
 
using Data_t = T
 type of the data More...
 
using Weight_t = typename Base_t::Weight_t
 type of the weight More...
 
using Pair_t = std::tuple< Data_t, Data_t >
 
using WeightedPair_t = std::tuple< Data_t, Data_t, Weight_t >
 

Public Member Functions

template<typename Iter >
void add_unweighted (Iter begin, Iter end)
 Adds entries from a sequence with weight 1. More...
 
template<typename Iter , typename Pred >
void add_unweighted (Iter begin, Iter end, Pred extractor)
 Adds entries from a sequence with weight 1. More...
 
template<typename Cont , typename Pred >
void add_unweighted (Cont cont, Pred extractor)
 Adds all entries from a container, with weight 1. More...
 
template<typename Cont >
void add_unweighted (Cont cont)
 Adds all entries from a container, with weight 1. More...
 
template<typename VIter , typename WIter , typename VPred , typename WPred = identity>
void add_weighted (VIter begin_value, VIter end_value, WIter begin_weight, VPred value_extractor, WPred weight_extractor=WPred())
 Adds entries from a sequence with individually specified weights. More...
 
template<typename Iter >
void add_weighted (Iter begin, Iter end)
 Adds entries from a sequence with individually specified weights. More...
 
template<typename Cont >
void add_weighted (Cont cont)
 Adds entries from a sequence with individually specified weights. More...
 
void clear ()
 Clears all the statistics. More...
 
void add (Weight_t weight)
 Adds the specified weight to the statistics. More...
 
Add elements
void add (Data_t x, Data_t y, Weight_t weight=Weight_t(1.0))
 Adds one entry with specified values and weight. More...
 
void add (Pair_t value, Weight_t weight=Weight_t(1.0))
 Adds one entry with specified values and weight. More...
 
void add (WeightedPair_t value)
 Adds one entry with specified values and weight. More...
 
Statistic retrieval
int N () const
 Returns the number of entries added. More...
 
Weight_t Weights () const
 Returns the sum of the weights. More...
 
Weight_t SumX () const
 Returns the weighted sum of the x values. More...
 
Weight_t SumY () const
 Returns the weighted sum of the y values. More...
 
Weight_t SumSqX () const
 Returns the weighted sum of the square of the x values. More...
 
Weight_t SumSqY () const
 Returns the weighted sum of the square of the y values. More...
 
Weight_t SumXY () const
 Returns the weighted sum of the product of x and y values. More...
 
Weight_t AverageX () const
 Returns the x value average. More...
 
Weight_t AverageY () const
 Returns the y value average. More...
 
Weight_t VarianceX () const
 Returns the variance of the x values. More...
 
Weight_t VarianceY () const
 Returns the variance of the y values. More...
 
Weight_t Covariance () const
 Returns the covariance of the (x, y) pair. More...
 
Weight_t RMSx () const
 Returns the standard deviation of the x sample. More...
 
Weight_t RMSy () const
 Returns the standard deviation of the y sample. More...
 
Weight_t LinearCorrelation () const
 Returns the linear correlation. More...
 
Weight_t AverageWeight () const
 Returns the arithmetic average of the weights. More...
 

Static Public Member Functions

template<typename V >
static constexpr V sqr (V const &v)
 Returns the square of the specified value. More...
 

Protected Types

using Variable_t = details::DataTracker2< Data_t, Weight_t >
 

Protected Attributes

Variable_t x
 accumulator for variable x More...
 
Variable_t y
 accumulator for variable y More...
 
Weight_t sum_xy = Weight_t(0)
 weighted sum of xy More...
 
int n = 0
 number of added entries More...
 
Weight_t w = Weight_t(0)
 total weight More...
 

Detailed Description

template<typename T, typename W = T>
class lar::util::StatCollector2D< T, W >

Collects statistics on two homogeneous quantities (weighted)


Template Parameters
Ttype of the quantities
Wtype of the weight (as T by default)

This is a convenience class, as easy to use as:

stat.add(3.0, 4.0, 2.0);
stat.add(4.0, 3.0, 2.0);
stat.add(5.0, 5.0, 1.0);
std::cout << "Statistics from " << stat.N() << " entries: "
<< stat.AverageX() << ", " << stat.AverageY() << std::endl;

or also

std::vector<std::pair<double, double>> values({
{ 3.0, 4.0, 2.0 },
{ 4.0, 3.0, 2.0 },
{ 5.0, 5.0, 1.0 },
});
stat.add_weighted(values.begin(), values.end());
std::cout << "Statistics from " << stat.N() << " entries: "
<< stat.AverageX() << ", " << stat.AverageY() << std::endl;

that should both print: "Statistics from 3 entries: 3.8, 3.8".

Other functions are available allowing addition of weighted and unweighted data from collections. For additional examples, see the unit test StatCollector_test.cc .

Definition at line 477 of file StatCollector.h.

Member Typedef Documentation

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::Base_t = details::WeightTracker<W>

Definition at line 479 of file StatCollector.h.

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::Data_t = T

type of the data

Definition at line 484 of file StatCollector.h.

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::Pair_t = std::tuple<Data_t, Data_t>

Definition at line 487 of file StatCollector.h.

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::This_t = StatCollector2D<T, W>

this type

Definition at line 483 of file StatCollector.h.

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::Variable_t = details::DataTracker2<Data_t, Weight_t>
protected

Definition at line 733 of file StatCollector.h.

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::Weight_t = typename Base_t::Weight_t

type of the weight

Definition at line 485 of file StatCollector.h.

template<typename T, typename W = T>
using lar::util::StatCollector2D< T, W >::WeightedPair_t = std::tuple<Data_t, Data_t, Weight_t>

Definition at line 488 of file StatCollector.h.

Member Function Documentation

template<typename W>
void lar::util::details::WeightTracker< W >::add ( Weight_t  weight)
inlineinherited

Adds the specified weight to the statistics.

Definition at line 49 of file StatCollector.h.

Referenced by lar::util::details::FitDataCollector< T, D >::add().

50  {
51  ++n;
52  w += weight;
53  }
int n
number of added entries
Definition: StatCollector.h:83
double weight
Definition: plottest35.C:25
template<typename T , typename W >
void lar::util::StatCollector2D< T, W >::add ( Data_t  x,
Data_t  y,
Weight_t  weight = Weight_t(1.0) 
)

Adds one entry with specified values and weight.

Definition at line 923 of file StatCollector.h.

References x, and y.

926 {
928  x.add(x_value, weight);
929  y.add(y_value, weight);
930  sum_xy += weight * x_value * y_value;
931 } // StatCollector2D<T, W>::add()
void add(Data_t v, Weight_t w)
Adds the specified weight to the statistics.
Weight_t sum_xy
weighted sum of xy
Variable_t x
accumulator for variable x
void add(Weight_t weight)
Adds the specified weight to the statistics.
Definition: StatCollector.h:49
Variable_t y
accumulator for variable y
double weight
Definition: plottest35.C:25
template<typename T, typename W = T>
void lar::util::StatCollector2D< T, W >::add ( Pair_t  value,
Weight_t  weight = Weight_t(1.0) 
)
inline

Adds one entry with specified values and weight.

Definition at line 499 of file StatCollector.h.

References weight.

500  {
501  add(std::get<0>(value), std::get<1>(value), weight);
502  }
void add(Data_t x, Data_t y, Weight_t weight=Weight_t(1.0))
Adds one entry with specified values and weight.
double value
Definition: spectrum.C:18
double weight
Definition: plottest35.C:25
template<typename T, typename W = T>
void lar::util::StatCollector2D< T, W >::add ( WeightedPair_t  value)
inline

Adds one entry with specified values and weight.

Definition at line 504 of file StatCollector.h.

505  {
506  add(std::get<0>(value), std::get<1>(value), std::get<2>(value));
507  }
void add(Data_t x, Data_t y, Weight_t weight=Weight_t(1.0))
Adds one entry with specified values and weight.
double value
Definition: spectrum.C:18
template<typename T, typename W = T>
template<typename Iter >
void lar::util::StatCollector2D< T, W >::add_unweighted ( Iter  begin,
Iter  end 
)
inline

Adds entries from a sequence with weight 1.

Template Parameters
Iterforward iterator to the pairs to be added
Parameters
beginiterator pointing to the first element to be added
enditerator pointing after the last element to be added

The value pointed by the iterator must be a tuple with types compatible with Pair_t.

Definition at line 520 of file StatCollector.h.

References util::begin(), and util::end().

521  {
522  add_unweighted(begin, end, identity());
523  }
void add_unweighted(Iter begin, Iter end)
Adds entries from a sequence with weight 1.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
template<typename T , typename W >
template<typename Iter , typename Pred >
void lar::util::StatCollector2D< T, W >::add_unweighted ( Iter  begin,
Iter  end,
Pred  extractor 
)

Adds entries from a sequence with weight 1.

Template Parameters
Iterforward iterator to the elements to be added
Preda predicate to extract the element from iterator value
Parameters
beginiterator pointing to the first element to be added
enditerator pointing after the last element to be added
extractorthe predicate extracting the value to be inserted

The predicate is required to react to a call like with:

Pair_t Pred::operator() (typename Iter::value_type);

Definition at line 935 of file StatCollector.h.

936 {
937  std::for_each(begin, end, [this, extractor](auto item) { this->add(extractor(item)); });
938 } // StatCollector2D<T, W>::add_unweighted(Iter, Iter, Pred)
void add(Data_t x, Data_t y, Weight_t weight=Weight_t(1.0))
Adds one entry with specified values and weight.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
template<typename T, typename W = T>
template<typename Cont , typename Pred >
void lar::util::StatCollector2D< T, W >::add_unweighted ( Cont  cont,
Pred  extractor 
)
inline

Adds all entries from a container, with weight 1.

Template Parameters
Conttype of container of the elements to be added
Preda predicate to extract the element from iterator value
Parameters
contcontainer of the elements to be added
extractorthe predicate extracting the value to be inserted

The predicate is required to react to a call like with:

Pair_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 556 of file StatCollector.h.

References util::begin(), and util::end().

557  {
558  add_unweighted(std::begin(cont), std::end(cont), extractor);
559  }
void add_unweighted(Iter begin, Iter end)
Adds entries from a sequence with weight 1.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
template<typename T, typename W = T>
template<typename Cont >
void lar::util::StatCollector2D< T, W >::add_unweighted ( Cont  cont)
inline

Adds all entries from a container, with weight 1.

Template Parameters
Conttype of container of the elements to be added
Parameters
contcontainer 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 Data_t type.

Definition at line 571 of file StatCollector.h.

References util::begin(), and util::end().

572  {
573  add_unweighted(std::begin(cont), std::end(cont));
574  }
void add_unweighted(Iter begin, Iter end)
Adds entries from a sequence with weight 1.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
template<typename T , typename W >
template<typename VIter , typename WIter , typename VPred , typename WPred >
void lar::util::StatCollector2D< T, W >::add_weighted ( VIter  begin_value,
VIter  end_value,
WIter  begin_weight,
VPred  value_extractor,
WPred  weight_extractor = WPred() 
)

Adds entries from a sequence with individually specified weights.

Template Parameters
VIterforward iterator to the elements to be added
WIterforward iterator to the weights
VPreda predicate to extract the element from iterator value
WPreda predicate to extract the weight from iterator value
Parameters
begin_valueiterator pointing to the first element to be added
end_valueiterator pointing after the last element to be added
begin_weightiterator pointing to the weight of first element
value_extractorpredicate extracting the value to be inserted
weight_extractorpredicate extracting the weight to be inserted

Each element is added with the weight pointed by the matching element in the list pointed by begin_weight: the element *(begin_value) will have weight *(begin_weight), the next element *(begin_value + 1) will have weight *(begin_weight + 1), etc.

The predicates are required to react to a call like with:

Pair_t VPred::operator() (typename VIter::value_type);
Weight_t WPred::operator() (typename WIter::value_type);

Definition at line 942 of file StatCollector.h.

948 {
949  while (begin_value != end_value) {
950  add(value_extractor(*begin_value), weight_extractor(*begin_weight));
951  ++begin_value;
952  ++begin_weight;
953  } // while
954 } // StatCollector2D<T, W>::add_weighted(VIter, VIter, WIter, VPred, WPred)
void add(Data_t x, Data_t y, Weight_t weight=Weight_t(1.0))
Adds one entry with specified values and weight.
template<typename T , typename W >
template<typename Iter >
void lar::util::StatCollector2D< T, W >::add_weighted ( Iter  begin,
Iter  end 
)

Adds entries from a sequence with individually specified weights.

Template Parameters
Iterforward iterator to WeightedPair_t elements to be added
Parameters
beginiterator pointing to the first element to be added
enditerator pointing after the last element to be added

The value pointed by the iterator must be a WeightedPair_t or something with elements convertible to its own (Data_t, Data_t and Weight_t). For more complicate structures, use the version with two predicates (using the weight iterator the same as the value iterator).

Definition at line 958 of file StatCollector.h.

959 {
960 
961  std::for_each(begin, end, [this](auto p) { this->add(p); });
962 
963 } // StatCollector2D<T, W>::add_weighted(Iter, Iter)
void add(Data_t x, Data_t y, Weight_t weight=Weight_t(1.0))
Adds one entry with specified values and weight.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
template<typename T, typename W = T>
template<typename Cont >
void lar::util::StatCollector2D< T, W >::add_weighted ( Cont  cont)
inline

Adds entries from a sequence with individually specified weights.

Template Parameters
Conttype of container of WeightedPair_t elements to be added
Parameters
contcontainer of (x, y, weight) pairs to be added

The values in the container must be tuples with first and second element convertible to the Data_t and the third element convertible to Weight_t.

Definition at line 630 of file StatCollector.h.

References util::begin(), clear(), and util::end().

631  {
632  add_weighted(std::begin(cont), std::end(cont));
633  }
void add_weighted(VIter begin_value, VIter end_value, WIter begin_weight, VPred value_extractor, WPred weight_extractor=WPred())
Adds entries from a sequence with individually specified weights.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::AverageWeight ( ) const
inline

Returns the arithmetic average of the weights.

Returns
the weight average
Exceptions
std::range_errorif no entry was added

Definition at line 728 of file StatCollector.h.

728 { return Base_t::AverageWeight(); }
Weight_t AverageWeight() const
Returns the arithmetic average of the weights.
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::AverageX ( ) const

Returns the x value average.

Returns
the x value average
Exceptions
std::range_errorif the total weight is 0 (usually: no data)

Definition at line 975 of file StatCollector.h.

977 {
978  if (Weights() == Weight_t(0))
979  throw std::range_error("StatCollector2D<>::AverageX(): divide by 0");
980  return SumX() / Weights();
981 } // StatCollector2D<T, W>::AverageX()
Weight_t SumX() const
Returns the weighted sum of the x values.
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t Weights() const
Returns the sum of the weights.
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::AverageY ( ) const

Returns the y value average.

Returns
the y value average
Exceptions
std::range_errorif the total weight is 0 (usually: no data)

Definition at line 1002 of file StatCollector.h.

1004 {
1005  if (Weights() == Weight_t(0))
1006  throw std::range_error("StatCollector2D<>::AverageY(): divide by 0");
1007  return SumY() / Weights();
1008 } // StatCollector2D<T, W>::AverageY()
Weight_t SumY() const
Returns the weighted sum of the y values.
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t Weights() const
Returns the sum of the weights.
template<typename T , typename W >
void lar::util::StatCollector2D< T, W >::clear ( )
inline

Clears all the statistics.

Definition at line 966 of file StatCollector.h.

References clear(), x, and y.

967 {
968  Base_t::clear();
969  x.clear();
970  y.clear();
971  sum_xy = Weight_t(0);
972 } // StatCollector<T, W>::clear()
Weight_t sum_xy
weighted sum of xy
Variable_t x
accumulator for variable x
Variable_t y
accumulator for variable y
void clear()
Resets the count.
Definition: StatCollector.h:56
void clear()
Resets the count.
typename Base_t::Weight_t Weight_t
type of the weight
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::Covariance ( ) const

Returns the covariance of the (x, y) pair.

Returns
the square of the RMS of the y values
Exceptions
std::range_errorif the total weight is 0 (usually: no data)

Definition at line 1020 of file StatCollector.h.

1022 {
1023  if (Weights() == Weight_t(0))
1024  throw std::range_error("StatCollector2D<>::Covariance(): divide by 0");
1025  return (SumXY() - SumX() * SumY() / Weights()) / Weights();
1026 } // StatCollector2D<T, W>::VarianceY()
Weight_t SumXY() const
Returns the weighted sum of the product of x and y values.
Weight_t SumX() const
Returns the weighted sum of the x values.
Weight_t SumY() const
Returns the weighted sum of the y values.
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t Weights() const
Returns the sum of the weights.
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::LinearCorrelation ( ) const

Returns the linear correlation.

Returns
the linear correlation RMS of the y values
Exceptions
std::range_errorif the total weight is 0 (see Covariance())
std::range_errorif any variance is non-positive

Definition at line 1039 of file StatCollector.h.

1040 {
1041  if (Weights() == Data_t(0))
1042  throw std::range_error("StatCollector2D<>::LinearCorrelation(): divide by 0");
1043 
1044  const Weight_t var_prod = VarianceX() * VarianceY();
1045  if (var_prod <= Weight_t(0))
1046  throw std::range_error("StatCollector2D<>::LinearCorrelation(): variance is 0");
1047 
1048  return Covariance() / std::sqrt(var_prod);
1049 } // StatCollector2D<T, W>::LinearCorrelation()
Weight_t Covariance() const
Returns the covariance of the (x, y) pair.
Weight_t VarianceY() const
Returns the variance of the y values.
T Data_t
type of the data
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t Weights() const
Returns the sum of the weights.
Weight_t VarianceX() const
Returns the variance of the x values.
template<typename T, typename W = T>
int lar::util::StatCollector2D< T, W >::N ( ) const
inline

Returns the number of entries added.

Definition at line 644 of file StatCollector.h.

644 { return Base_t::N(); }
int N() const
Returns the number of entries added.
Definition: StatCollector.h:63
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::RMSx ( ) const

Returns the standard deviation of the x sample.

Returns
the RMS of the x values
Exceptions
std::range_errorif the total weight is 0 (see VarianceX())
std::range_errorif VarianceX() is negative (due to rounding errors)

Definition at line 993 of file StatCollector.h.

994 {
995  const Weight_t rms2 = VarianceX();
996  if (rms2 < Weight_t(0)) return 0.;
997  // throw std::range_error("StatCollector2D<>::RMSx(): negative RMS^2");
998  return std::sqrt(rms2);
999 } // StatCollector2D<T, W>::RMSx()
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t VarianceX() const
Returns the variance of the x values.
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::RMSy ( ) const

Returns the standard deviation of the y sample.

Returns
the RMS of the y values
Exceptions
std::range_errorif the total weight is 0 (see VarianceY())
std::range_errorif VarianceY() is negative (due to rounding errors)

Definition at line 1029 of file StatCollector.h.

1030 {
1031  const Weight_t rms2 = VarianceY();
1032  if (rms2 < Weight_t(0)) return 0.;
1033  // throw std::range_error("StatCollector2D<>::RMSy(): negative RMS^2");
1034  return std::sqrt(rms2);
1035 } // StatCollector2D<T, W>::RMSy()
Weight_t VarianceY() const
Returns the variance of the y values.
typename Base_t::Weight_t Weight_t
type of the weight
template<typename W>
template<typename V >
static constexpr V lar::util::details::WeightTracker< W >::sqr ( V const &  v)
inlinestaticinherited

Returns the square of the specified value.

Definition at line 77 of file StatCollector.h.

78  {
79  return v * v;
80  }
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::SumSqX ( ) const
inline

Returns the weighted sum of the square of the x values.

Definition at line 656 of file StatCollector.h.

656 { return x.SumSq(); }
Weight_t SumSq() const
Returns the weighted sum of the square of the entries.
Variable_t x
accumulator for variable x
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::SumSqY ( ) const
inline

Returns the weighted sum of the square of the y values.

Definition at line 659 of file StatCollector.h.

659 { return y.SumSq(); }
Weight_t SumSq() const
Returns the weighted sum of the square of the entries.
Variable_t y
accumulator for variable y
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::SumX ( ) const
inline

Returns the weighted sum of the x values.

Definition at line 650 of file StatCollector.h.

650 { return x.Sum(); }
Variable_t x
accumulator for variable x
Weight_t Sum(unsigned int n) const
Returns the sum of the values to the power n (1 <= n <= 2, no check)
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::SumXY ( ) const
inline

Returns the weighted sum of the product of x and y values.

Definition at line 662 of file StatCollector.h.

662 { return sum_xy; }
Weight_t sum_xy
weighted sum of xy
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::SumY ( ) const
inline

Returns the weighted sum of the y values.

Definition at line 653 of file StatCollector.h.

653 { return y.Sum(); }
Variable_t y
accumulator for variable y
Weight_t Sum(unsigned int n) const
Returns the sum of the values to the power n (1 <= n <= 2, no check)
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::VarianceX ( ) const

Returns the variance of the x values.

Returns
the square of the RMS of the x values
Exceptions
std::range_errorif the total weight is 0 (usually: no data)

Definition at line 984 of file StatCollector.h.

References sqr().

986 {
987  if (Weights() == Weight_t(0))
988  throw std::range_error("StatCollector2D<>::VarianceX(): divide by 0");
989  return (SumSqX() - sqr(SumX()) / Weights()) / Weights();
990 } // StatCollector2D<T, W>::VarianceX()
static constexpr V sqr(V const &v)
Returns the square of the specified value.
Definition: StatCollector.h:77
Weight_t SumSqX() const
Returns the weighted sum of the square of the x values.
Weight_t SumX() const
Returns the weighted sum of the x values.
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t Weights() const
Returns the sum of the weights.
template<typename T , typename W >
lar::util::StatCollector2D< T, W >::Weight_t lar::util::StatCollector2D< T, W >::VarianceY ( ) const

Returns the variance of the y values.

Returns
the square of the RMS of the y values
Exceptions
std::range_errorif the total weight is 0 (usually: no data)

Definition at line 1011 of file StatCollector.h.

References sqr().

1013 {
1014  if (Weights() == Weight_t(0))
1015  throw std::range_error("StatCollector2D<>::VarianceY(): divide by 0");
1016  return (SumSqY() - sqr(SumY()) / Weights()) / Weights();
1017 } // StatCollector2D<T, W>::VarianceY()
Weight_t SumSqY() const
Returns the weighted sum of the square of the y values.
static constexpr V sqr(V const &v)
Returns the square of the specified value.
Definition: StatCollector.h:77
Weight_t SumY() const
Returns the weighted sum of the y values.
typename Base_t::Weight_t Weight_t
type of the weight
Weight_t Weights() const
Returns the sum of the weights.
template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::Weights ( ) const
inline

Returns the sum of the weights.

Definition at line 647 of file StatCollector.h.

647 { return Base_t::Weights(); }
Weight_t Weights() const
Returns the sum of the weights.
Definition: StatCollector.h:66

Member Data Documentation

template<typename W>
int lar::util::details::WeightTracker< W >::n = 0
protectedinherited

number of added entries

Definition at line 83 of file StatCollector.h.

template<typename T, typename W = T>
Weight_t lar::util::StatCollector2D< T, W >::sum_xy = Weight_t(0)
protected

weighted sum of xy

Definition at line 737 of file StatCollector.h.

template<typename W>
Weight_t lar::util::details::WeightTracker< W >::w = Weight_t(0)
protectedinherited

total weight

Definition at line 84 of file StatCollector.h.

template<typename T, typename W = T>
Variable_t lar::util::StatCollector2D< T, W >::x
protected

accumulator for variable x

Definition at line 735 of file StatCollector.h.

template<typename T, typename W = T>
Variable_t lar::util::StatCollector2D< T, W >::y
protected

accumulator for variable y

Definition at line 736 of file StatCollector.h.


The documentation for this class was generated from the following file: