yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.9.4
Dbn0D.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of YODA -- Yet more Objects for Data Analysis
4 // Copyright (C) 2008-2021 The YODA collaboration (see AUTHORS for details)
5 //
6 #ifndef YODA_Dbn0D_h
7 #define YODA_Dbn0D_h
8 
9 #include "YODA/Exceptions.h"
10 #include "YODA/Utils/MathUtils.h"
11 #include <cmath>
12 
13 namespace YODA {
14 
15 
28  class Dbn0D {
29  public:
30 
33 
35  Dbn0D() {
36  reset();
37  }
38 
39 
43  Dbn0D(double numEntries, double sumW, double sumW2)
44  : _numEntries(numEntries),
45  _sumW(sumW),
46  _sumW2(sumW2)
47  { }
48 
49 
53  Dbn0D(const Dbn0D& toCopy) {
54  _numEntries = toCopy._numEntries;
55  _sumW = toCopy._sumW;
56  _sumW2 = toCopy._sumW2;
57  }
58 
59 
63  Dbn0D& operator=(const Dbn0D& toCopy) {
64  _numEntries = toCopy._numEntries;
65  _sumW = toCopy._sumW;
66  _sumW2 = toCopy._sumW2;
67  return *this;
68  }
69 
71 
72 
75 
79  void fill(double weight=1.0, double fraction=1.0) {
80  _numEntries += fraction;
81  _sumW += fraction*weight;
82  _sumW2 += fraction*weight*weight;
83  }
84 
85 
87  void reset() {
88  _numEntries = 0;
89  _sumW = 0;
90  _sumW2 = 0;
91  }
92 
93 
95  void scaleW(double scalefactor) {
96  _sumW *= scalefactor;
97  _sumW2 *= scalefactor*scalefactor;
98  }
99 
101 
102 
105 
107  double numEntries() const {
108  return _numEntries;
109  }
110 
112  double effNumEntries() const {
113  if (_sumW2 == 0) return 0;
114  return _sumW*_sumW / _sumW2;
115  }
116 
118  double sumW() const {
119  return _sumW;
120  }
121 
123  double sumW2() const {
124  return _sumW2;
125  }
126 
128 
129 
132 
134  double errW() const;
135 
137  double relErrW() const;
138 
140 
141 
144 
146  Dbn0D& operator += (const Dbn0D& d) {
147  return add(d);
148  }
149 
151  Dbn0D& operator -= (const Dbn0D& d) {
152  return subtract(d);
153  }
154 
156 
157 
158  protected:
159 
161  Dbn0D& add(const Dbn0D& d);
162 
164  Dbn0D& subtract(const Dbn0D& d);
165 
166 
167  private:
168 
171 
173  double _numEntries;
174 
176  double _sumW;
177 
179  double _sumW2;
180 
182 
183  };
184 
185 
187  inline Dbn0D operator + (const Dbn0D& a, const Dbn0D& b) {
188  Dbn0D rtn = a;
189  rtn += b;
190  return rtn;
191  }
192 
194  inline Dbn0D operator - (const Dbn0D& a, const Dbn0D& b) {
195  Dbn0D rtn = a;
196  rtn -= b;
197  return rtn;
198  }
199 
200 
201 }
202 
203 #endif
Dbn0D & operator=(const Dbn0D &toCopy)
Definition: Dbn0D.h:63
double sumW2() const
The sum of weights squared.
Definition: Dbn0D.h:123
Axis1D< BIN1D, DBN > operator-(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Subtract the statistics on two axis.
Definition: Axis1D.h:610
void scaleW(double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition: Dbn0D.h:95
Dbn0D(double numEntries, double sumW, double sumW2)
Constructor to set a distribution with a pre-filled state.
Definition: Dbn0D.h:43
Dbn0D & subtract(const Dbn0D &d)
Subtract one dbn from another (internal, explicitly named version)
Definition: Dbn0D.cc:31
A 0D distribution.
Definition: Dbn0D.h:28
double relErrW() const
The relative error on sumW.
Definition: Dbn0D.cc:16
void reset()
Reset the internal counters.
Definition: Dbn0D.h:87
Dbn0D()
Default constructor of a new distribution.
Definition: Dbn0D.h:35
double errW() const
The absolute error on sumW.
Definition: Dbn0D.cc:12
Axis1D< BIN1D, DBN > operator+(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Add the statistics on two axes.
Definition: Axis1D.h:602
Dbn0D & operator-=(const Dbn0D &d)
Subtract one dbn from another.
Definition: Dbn0D.h:151
double numEntries() const
Number of entries (number of times fill was called, ignoring weights)
Definition: Dbn0D.h:107
Dbn0D & operator+=(const Dbn0D &d)
Add two dbns.
Definition: Dbn0D.h:146
void fill(double weight=1.0, double fraction=1.0)
Contribute a weight weight.
Definition: Dbn0D.h:79
Dbn0D & add(const Dbn0D &d)
Add two dbns (internal, explicitly named version)
Definition: Dbn0D.cc:24
Dbn0D(const Dbn0D &toCopy)
Definition: Dbn0D.h:53
double sumW() const
The sum of weights.
Definition: Dbn0D.h:118
double effNumEntries() const
Effective number of entries .
Definition: Dbn0D.h:112