yoda is hosted by Hepforge, IPPP Durham
 YODA - Yet more Objects for Data Analysis  1.9.4
Dbn1D.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_Dbn1D_h
7 #define YODA_Dbn1D_h
8
9 #include "YODA/Dbn0D.h"
10 #include "YODA/Exceptions.h"
11 #include "YODA/Utils/MathUtils.h"
12 #include <cmath>
13
14 namespace YODA {
15
16
28  class Dbn1D {
29  public:
30
33
35  Dbn1D() {
36  reset();
37  }
38
39
43  Dbn1D(double numEntries, double sumW, double sumW2, double sumWX, double sumWX2)
44  : _dbnW(numEntries, sumW, sumW2),
45  _sumWX(sumWX),
46  _sumWX2(sumWX2)
47  { }
48
49
53  Dbn1D(const Dbn1D& toCopy) {
54  _dbnW = toCopy._dbnW;
55  _sumWX = toCopy._sumWX;
56  _sumWX2 = toCopy._sumWX2;
57  }
58
59
63  Dbn1D& operator=(const Dbn1D& toCopy) {
64  _dbnW = toCopy._dbnW;
65  _sumWX = toCopy._sumWX;
66  _sumWX2 = toCopy._sumWX2;
67  return *this;
68  }
69
71
72
75
77  void fill(double val, double weight=1.0, double fraction=1.0) {
78  _dbnW.fill(weight, fraction);
79  _sumWX += fraction*weight*val;
80  _sumWX2 += fraction*weight*val*val;
81  }
82
83
85  void reset() {
86  _dbnW.reset();
87  _sumWX = 0;
88  _sumWX2 = 0;
89  }
90
91
93  void scaleW(double scalefactor) {
94  _dbnW.scaleW(scalefactor);
95  _sumWX *= scalefactor;
96  _sumWX2 *= scalefactor;
97  }
98
99
101  void scaleX(double factor) {
102  _sumWX *= factor;
103  _sumWX2 *= factor*factor;
104  }
105
107
108  public:
109
110
113
115  double errW() const { return _dbnW.errW(); }
116
118  double relErrW() const { return _dbnW.relErrW(); }
119
121  double xMean() const;
122
124  double xVariance() const;
125
127  double xStdDev() const { return std::sqrt(xVariance()); }
128
130  double xStdErr() const;
131
133  double xRMS() const;
134
136
137
140
142  double numEntries() const {
143  return _dbnW.numEntries();
144  }
145
147  double effNumEntries() const {
148  return _dbnW.effNumEntries();
149  }
150
152  double sumW() const {
153  return _dbnW.sumW();
154  }
155
157  double sumW2() const {
158  return _dbnW.sumW2();
159  }
160
162  double sumWX() const {
163  return _sumWX;
164  }
165
167  double sumWX2() const {
168  return _sumWX2;
169  }
170
172
173
176
178  Dbn1D& operator += (const Dbn1D& d) {
180  }
181
183  Dbn1D& operator -= (const Dbn1D& d) {
184  return subtract(d);
185  }
186
188
189
190  protected:
191
194
196  Dbn1D& subtract(const Dbn1D& d);
197
198
199  private:
200
203
205  Dbn0D _dbnW;
206
208  double _sumWX;
209
211  double _sumWX2;
212
214
215  };
216
217
219  inline Dbn1D operator + (const Dbn1D& a, const Dbn1D& b) {
220  Dbn1D rtn = a;
221  rtn += b;
222  return rtn;
223  }
224
226  inline Dbn1D operator - (const Dbn1D& a, const Dbn1D& b) {
227  Dbn1D rtn = a;
228  rtn -= b;
229  return rtn;
230  }
231
232
233 }
234
235 #endif
Dbn1D & operator+=(const Dbn1D &d)
Definition: Dbn1D.h:178
double sumWX2() const
The sum of x^2*weight.
Definition: Dbn1D.h:167
Dbn1D & subtract(const Dbn1D &d)
Subtract one dbn from another (internal, explicitly named version)
Definition: Dbn1D.cc:77
double xMean() const
Weighted mean, , of distribution.
Definition: Dbn1D.cc:11
double sumWX() const
The sum of x*weight.
Definition: Dbn1D.h:162
void reset()
Reset the internal counters.
Definition: Dbn1D.h:85
double sumW() const
The sum of weights.
Definition: Dbn1D.h:152
Axis1D< BIN1D, DBN > operator-(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Subtract the statistics on two axis.
Definition: Axis1D.h:610
double numEntries() const
Number of entries (number of times fill was called, ignoring weights)
Definition: Dbn1D.h:142
void fill(double val, double weight=1.0, double fraction=1.0)
Contribute a sample at val with weight weight.
Definition: Dbn1D.h:77
double xVariance() const
Weighted variance, , of distribution.
Definition: Dbn1D.cc:20
Dbn1D(double numEntries, double sumW, double sumW2, double sumWX, double sumWX2)
Constructor to set a distribution with a pre-filled state.
Definition: Dbn1D.h:43
double xRMS() const
Weighted RMS, , of distribution.
Definition: Dbn1D.cc:58
double xStdErr() const
Weighted standard error on the mean, , of distribution.
Definition: Dbn1D.cc:48
A 0D distribution.
Definition: Dbn0D.h:28
Dbn1D()
Default constructor of a new distribution.
Definition: Dbn1D.h:35
void scaleW(double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition: Dbn1D.h:93
double errW() const
The absolute error on sumW.
Definition: Dbn1D.h:115
Axis1D< BIN1D, DBN > operator+(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Add the statistics on two axes.
Definition: Axis1D.h:602
double xStdDev() const
Weighted standard deviation, , of distribution.
Definition: Dbn1D.h:127
Add two dbns (internal, explicitly named version)
Definition: Dbn1D.cc:69
Dbn1D & operator=(const Dbn1D &toCopy)
Definition: Dbn1D.h:63
Dbn1D(const Dbn1D &toCopy)
Definition: Dbn1D.h:53
double effNumEntries() const
Effective number of entries .
Definition: Dbn1D.h:147
double relErrW() const
The relative error on sumW.
Definition: Dbn1D.h:118
double sumW2() const
The sum of weights squared.
Definition: Dbn1D.h:157
A 1D distribution.
Definition: Dbn1D.h:28
Dbn1D & operator-=(const Dbn1D &d)
Subtract one dbn from another.
Definition: Dbn1D.h:183
void scaleX(double factor)
Rescale x: needed if histo bin edges are rescaled.
Definition: Dbn1D.h:101