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

#include "StatCollector.h"

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

Public Types

using Weight_t = W
 type of the weight More...
 

Public Member Functions

void add (Weight_t weight)
 Adds the specified weight to the statistics. More...
 
void clear ()
 Resets the count. More...
 
int N () const
 Returns the number of entries added. More...
 
Weight_t Weights () const
 Returns the sum of the weights. 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 Attributes

int n = 0
 number of added entries More...
 
Weight_t w = Weight_t(0)
 total weight More...
 

Detailed Description

template<typename W>
class lar::util::details::WeightTracker< W >

Class tracking the number of entries and their total weight

Template Parameters
Wtype of the weight

Definition at line 44 of file StatCollector.h.

Member Typedef Documentation

template<typename W>
using lar::util::details::WeightTracker< W >::Weight_t = W

type of the weight

Definition at line 46 of file StatCollector.h.

Member Function Documentation

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

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 W >
lar::util::details::WeightTracker< W >::Weight_t lar::util::details::WeightTracker< W >::AverageWeight ( ) const

Returns the arithmetic average of the weights.

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

Definition at line 839 of file StatCollector.h.

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

840 {
841  if (N() == 0) throw std::range_error("WeightTracker<>::AverageWeight(): divide by 0");
842  return Weights() / N();
843 } // details::WeightTracker<W>::AverageWeight()
Weight_t Weights() const
Returns the sum of the weights.
Definition: StatCollector.h:66
int N() const
Returns the number of entries added.
Definition: StatCollector.h:63
template<typename W>
void lar::util::details::WeightTracker< W >::clear ( )
inline

Resets the count.

Definition at line 56 of file StatCollector.h.

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

57  {
58  n = 0;
59  w = Weight_t(0);
60  }
int n
number of added entries
Definition: StatCollector.h:83
W Weight_t
type of the weight
Definition: StatCollector.h:46
template<typename W>
int lar::util::details::WeightTracker< W >::N ( ) const
inline

Returns the number of entries added.

Definition at line 63 of file StatCollector.h.

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

63 { return n; }
int n
number of added entries
Definition: StatCollector.h:83
template<typename W>
template<typename V >
static constexpr V lar::util::details::WeightTracker< W >::sqr ( V const &  v)
inlinestatic

Returns the square of the specified value.

Definition at line 77 of file StatCollector.h.

78  {
79  return v * v;
80  }

Member Data Documentation

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

number of added entries

Definition at line 83 of file StatCollector.h.

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

total weight

Definition at line 84 of file StatCollector.h.


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