YODA is hosted by Hepforge, IPPP Durham
YODA::Dbn0D Class Reference

A 0D distribution. More...

#include <Dbn0D.h>

Public Member Functions

Constructors
 Dbn0D ()
 Default constructor of a new distribution. More...
 
 Dbn0D (unsigned long numEntries, double sumW, double sumW2)
 Constructor to set a distribution with a pre-filled state. More...
 
 Dbn0D (const Dbn0D &toCopy)
 
Dbn0Doperator= (const Dbn0D &toCopy)
 
Modifiers
void fill (double weight=1.0)
 Contribute a weight weight. More...
 
void reset ()
 Reset the internal counters. More...
 
void scaleW (double scalefactor)
 Rescale as if all fill weights had been different by factor scalefactor. More...
 
Raw distribution running sums
unsigned long numEntries () const
 Number of entries (number of times fill was called, ignoring weights) More...
 
double effNumEntries () const
 Effective number of entries $ = (\sum w)^2 / \sum w^2 $. More...
 
double sumW () const
 The sum of weights. More...
 
double sumW2 () const
 The sum of weights squared. More...
 
Uncertainties on sumW
double errW () const
 The absolute error on sumW. More...
 
double relErrW () const
 The relative error on sumW. More...
 
Operators
Dbn0Doperator+= (const Dbn0D &d)
 Add two dbns. More...
 
Dbn0Doperator-= (const Dbn0D &d)
 Subtract one dbn from another. More...
 

Protected Member Functions

Dbn0Dadd (const Dbn0D &d)
 Add two dbns (internal, explicitly named version) More...
 
Dbn0Dsubtract (const Dbn0D &d)
 Subtract one dbn from another (internal, explicitly named version) More...
 

Detailed Description

A 0D distribution.

This class is used internally by YODA to centralise the calculation of statistics of unbounded, unbinned sampled distributions. Each distribution fill contributes a weight, $ w $. Unlike e.g. Dbn1D there are no dimensionful value terms such as $ \sum wx $, and $ \sum wx^2 $.

By storing the total number of fills (ignoring weights), $ \sum w $, and $ \sum w^2 $ the Dbn0D can calculate the mean and error on the aggregate of the supplied weights. It is used to provide this information in the Counter class and in Dbn1D, Dbn2D, etc. (which themselves are used to implement histogram and profile bins).

Definition at line 28 of file Dbn0D.h.

Constructor & Destructor Documentation

YODA::Dbn0D::Dbn0D ( )
inline

Default constructor of a new distribution.

Definition at line 35 of file Dbn0D.h.

References reset().

35  {
36  reset();
37  }
void reset()
Reset the internal counters.
Definition: Dbn0D.h:87
YODA::Dbn0D::Dbn0D ( unsigned long  numEntries,
double  sumW,
double  sumW2 
)
inline

Constructor to set a distribution with a pre-filled state.

Principally designed for internal persistency use.

Definition at line 43 of file Dbn0D.h.

44  : _numFills(numEntries),
45  _sumW(sumW),
46  _sumW2(sumW2)
47  { }
double sumW() const
The sum of weights.
Definition: Dbn0D.h:118
double sumW2() const
The sum of weights squared.
Definition: Dbn0D.h:123
unsigned long numEntries() const
Number of entries (number of times fill was called, ignoring weights)
Definition: Dbn0D.h:107
YODA::Dbn0D::Dbn0D ( const Dbn0D toCopy)
inline

Copy constructor

Sets all the parameters using the ones provided from an existing Dbn0D.

Definition at line 53 of file Dbn0D.h.

53  {
54  _numFills = toCopy._numFills;
55  _sumW = toCopy._sumW;
56  _sumW2 = toCopy._sumW2;
57  }

Member Function Documentation

Dbn0D & YODA::Dbn0D::add ( const Dbn0D d)
protected

Add two dbns (internal, explicitly named version)

Definition at line 24 of file Dbn0D.cc.

Referenced by operator+=().

24  {
25  _numFills += d._numFills;
26  _sumW += d._sumW;
27  _sumW2 += d._sumW2;
28  return *this;
29  }
double YODA::Dbn0D::effNumEntries ( ) const
inline

Effective number of entries $ = (\sum w)^2 / \sum w^2 $.

Definition at line 112 of file Dbn0D.h.

Referenced by relErrW().

112  {
113  if (_sumW2 == 0) return 0;
114  return _sumW*_sumW / _sumW2;
115  }
double YODA::Dbn0D::errW ( ) const

The absolute error on sumW.

Definition at line 12 of file Dbn0D.cc.

References sumW2().

Referenced by relErrW().

12  {
13  return sqrt(sumW2());
14  }
double sumW2() const
The sum of weights squared.
Definition: Dbn0D.h:123
void YODA::Dbn0D::fill ( double  weight = 1.0)
inline

Contribute a weight weight.

Todo:
Be careful about negative weights.

Definition at line 79 of file Dbn0D.h.

79  {
80  _numFills += 1;
81  _sumW += weight;
82  _sumW2 += weight*weight;
83  }
unsigned long YODA::Dbn0D::numEntries ( ) const
inline

Number of entries (number of times fill was called, ignoring weights)

Definition at line 107 of file Dbn0D.h.

107  {
108  return _numFills;
109  }
Dbn0D& YODA::Dbn0D::operator+= ( const Dbn0D d)
inline

Add two dbns.

Definition at line 146 of file Dbn0D.h.

References add().

146  {
147  return add(d);
148  }
Dbn0D & add(const Dbn0D &d)
Add two dbns (internal, explicitly named version)
Definition: Dbn0D.cc:24
Dbn0D& YODA::Dbn0D::operator-= ( const Dbn0D d)
inline

Subtract one dbn from another.

Definition at line 151 of file Dbn0D.h.

References subtract().

151  {
152  return subtract(d);
153  }
Dbn0D & subtract(const Dbn0D &d)
Subtract one dbn from another (internal, explicitly named version)
Definition: Dbn0D.cc:31
Dbn0D& YODA::Dbn0D::operator= ( const Dbn0D toCopy)
inline

Copy assignment

Sets all the parameters using the ones provided from an existing Dbn0D.

Definition at line 63 of file Dbn0D.h.

63  {
64  _numFills = toCopy._numFills;
65  _sumW = toCopy._sumW;
66  _sumW2 = toCopy._sumW2;
67  return *this;
68  }
double YODA::Dbn0D::relErrW ( ) const

The relative error on sumW.

Definition at line 16 of file Dbn0D.cc.

References effNumEntries(), errW(), and sumW().

16  {
17  if (effNumEntries() == 0 || sumW() == 0) {
18  throw LowStatsError("Requested relative error of a distribution with no net fill weights");
19  }
20  return errW()/sumW();
21  }
double sumW() const
The sum of weights.
Definition: Dbn0D.h:118
double effNumEntries() const
Effective number of entries .
Definition: Dbn0D.h:112
double errW() const
The absolute error on sumW.
Definition: Dbn0D.cc:12
void YODA::Dbn0D::reset ( )
inline

Reset the internal counters.

Definition at line 87 of file Dbn0D.h.

Referenced by Dbn0D().

87  {
88  _numFills = 0;
89  _sumW = 0;
90  _sumW2 = 0;
91  }
void YODA::Dbn0D::scaleW ( double  scalefactor)
inline

Rescale as if all fill weights had been different by factor scalefactor.

Definition at line 95 of file Dbn0D.h.

95  {
96  _sumW *= scalefactor;
97  _sumW2 *= scalefactor*scalefactor;
98  }
Dbn0D & YODA::Dbn0D::subtract ( const Dbn0D d)
protected

Subtract one dbn from another (internal, explicitly named version)

Definition at line 31 of file Dbn0D.cc.

Referenced by operator-=().

31  {
32  _numFills += d._numFills; //< @todo Hmm, add or subtract?!?
33  _sumW -= d._sumW;
34  _sumW2 += d._sumW2;
35  return *this;
36  }
double YODA::Dbn0D::sumW ( ) const
inline

The sum of weights.

Definition at line 118 of file Dbn0D.h.

Referenced by relErrW().

118  {
119  return _sumW;
120  }
double YODA::Dbn0D::sumW2 ( ) const
inline

The sum of weights squared.

Definition at line 123 of file Dbn0D.h.

Referenced by errW().

123  {
124  return _sumW2;
125  }

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