yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
Dbn2D.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-2017 The YODA collaboration (see AUTHORS for details)
5 //
6 #ifndef YODA_Dbn2D_h
7 #define YODA_Dbn2D_h
8 
9 #include "YODA/Exceptions.h"
10 #include "YODA/Dbn1D.h"
11 
12 namespace YODA {
13 
14 
16  class Dbn2D {
17  public:
18 
20 
21 
23  Dbn2D() {
24  reset();
25  }
26 
27 
31  Dbn2D(double numEntries, double sumW, double sumW2,
32  double sumWX, double sumWX2, double sumWY, double sumWY2, double sumWXY)
33  : _dbnX(numEntries, sumW, sumW2, sumWX, sumWX2),
34  _dbnY(numEntries, sumW, sumW2, sumWY, sumWY2),
35  _sumWXY(sumWXY)
36  { }
37 
38 
42  Dbn2D(const Dbn2D& toCopy) {
43  _dbnX = toCopy._dbnX;
44  _dbnY = toCopy._dbnY;
45  _sumWXY = toCopy._sumWXY;
46  }
47 
48 
52  Dbn2D& operator=(const Dbn2D& toCopy) {
53  _dbnX = toCopy._dbnX;
54  _dbnY = toCopy._dbnY;
55  _sumWXY = toCopy._sumWXY;
56  return *this;
57  }
58 
60 
61 
63 
64 
66  void fill(double valX, double valY, double weight=1.0, double fraction=1.0) {
67  _dbnX.fill(valX, weight, fraction);
68  _dbnY.fill(valY, weight, fraction);
69  _sumWXY += fraction*weight*valX*valY;
70  }
71 
72 
74  void fill(std::pair<double,double> val, double weight=1.0, double fraction=1.0) {
75  fill(val.first, val.second, weight, fraction);
76  }
77 
78 
80  void reset() {
81  _dbnX.reset();
82  _dbnY.reset();
83  _sumWXY = 0;
84  }
85 
86 
88  void scaleW(double scalefactor) {
89  _dbnX.scaleW(scalefactor);
90  _dbnY.scaleW(scalefactor);
91  _sumWXY *= scalefactor;
92  }
93 
94 
96  void scaleX(double xscale) {
97  _dbnX.scaleX(xscale);
98  _sumWXY *= xscale;
99  }
100 
101 
103  void scaleY(double yscale) {
104  _dbnY.scaleX(yscale);
105  _sumWXY *= yscale;
106  }
107 
108 
110  void scaleXY(double xscale, double yscale) {
111  scaleX(xscale);
112  scaleY(yscale);
113  }
114 
116 
117  public:
118 
119 
121 
122 
124  double errW() const { return _dbnX.errW(); }
125 
127  double relErrW() const { return _dbnX.relErrW(); }
128 
130  double xMean() const { return _dbnX.xMean();}
131 
133  double yMean() const { return _dbnY.xMean(); }
134 
136  double xVariance() const { return _dbnX.xVariance(); }
137 
139  double yVariance() const { return _dbnY.xVariance(); }
140 
142  double xStdDev() const { return _dbnX.xStdDev(); }
143 
145  double yStdDev() const { return _dbnY.xStdDev(); }
146 
148  double xStdErr() const { return _dbnX.xStdErr(); }
149 
151  double yStdErr() const { return _dbnY.xStdErr(); }
152 
154  double xRMS() const { return _dbnX.xRMS(); }
155 
157  double yRMS() const { return _dbnY.xRMS(); }
158 
160 
161 
163 
164 
166  double numEntries() const {
167  return _dbnX.numEntries();
168  }
169 
171  double effNumEntries() const {
172  return _dbnX.effNumEntries();
173  }
174 
176  double sumW() const {
177  return _dbnX.sumW();
178  }
179 
181  double sumW2() const {
182  return _dbnX.sumW2();
183  }
184 
186  double sumWX() const {
187  return _dbnX.sumWX();
188  }
189 
191  double sumWX2() const {
192  return _dbnX.sumWX2();
193  }
194 
196  double sumWY() const {
197  return _dbnY.sumWX();
198  }
199 
201  double sumWY2() const {
202  return _dbnY.sumWX2();
203  }
204 
206  double sumWXY() const {
207  return _sumWXY;
208  }
209 
211 
212 
214 
215 
217  Dbn2D& operator += (const Dbn2D& d) {
218  return add(d);
219  }
220 
222  Dbn2D& operator -= (const Dbn2D& d) {
223  return subtract(d);
224  }
225 
229  void flipXY() {
230  Dbn1D temp(_dbnX);
231  _dbnX = _dbnY;
232  _dbnY = temp;
233  }
234 
239  Dbn1D ret(_dbnX);
240  return ret;
241  }
242 
247  Dbn1D ret(_dbnY);
248  return ret;
249  }
251 
252 
253  protected:
254 
256  Dbn2D& add(const Dbn2D& d) {
257  _dbnX += d._dbnX;
258  _dbnY += d._dbnY;
259  _sumWXY += d._sumWXY;
260  return *this;
261  }
262 
264  Dbn2D& subtract(const Dbn2D& d) {
265  _dbnX -= d._dbnX;
266  _dbnY -= d._dbnY;
267  _sumWXY -= d._sumWXY;
268  return *this;
269  }
270 
271 
272  private:
273 
275 
276 
278  Dbn1D _dbnX;
279 
281  Dbn1D _dbnY;
282 
284  double _sumWXY;
285 
287 
288  };
289 
290 
292  inline Dbn2D operator + (const Dbn2D& a, const Dbn2D& b) {
293  Dbn2D rtn = a;
294  rtn += b;
295  return rtn;
296  }
297 
299  inline Dbn2D operator - (const Dbn2D& a, const Dbn2D& b) {
300  Dbn2D rtn = a;
301  rtn -= b;
302  return rtn;
303  }
304 
305 
306 }
307 
308 #endif
Dbn2D()
Default constructor of a new distribution.
Definition: Dbn2D.h:23
double xVariance() const
Weighted variance, , of distribution.
Definition: Dbn2D.h:136
double sumWY2() const
The sum of y^2*weight.
Definition: Dbn2D.h:201
Dbn2D & subtract(const Dbn2D &d)
Subtract one dbn from another (internal, explicitly named version)
Definition: Dbn2D.h:264
void scaleY(double yscale)
Rescale y: needed if y histo bin edges are rescaled.
Definition: Dbn2D.h:103
Dbn2D & operator=(const Dbn2D &toCopy)
Definition: Dbn2D.h:52
double sumWY() const
The sum of y*weight.
Definition: Dbn2D.h:196
double xMean() const
Weighted mean, , of distribution.
Definition: Dbn2D.h:130
Dbn2D & operator-=(const Dbn2D &d)
Subtract one dbn from another.
Definition: Dbn2D.h:222
void fill(std::pair< double, double > val, double weight=1.0, double fraction=1.0)
Fill, providing the fill coordinates as a pair.
Definition: Dbn2D.h:74
double errW() const
The absolute error on sumW.
Definition: Dbn2D.h:124
double yVariance() const
Weighted variance, , of distribution.
Definition: Dbn2D.h:139
double sumW2() const
The sum of weights squared.
Definition: Dbn2D.h:181
Axis1D< BIN1D, DBN > operator-(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Subtract the statistics on two axis.
Definition: Axis1D.h:597
double xStdErr() const
Weighted standard error on the mean, , of distribution.
Definition: Dbn2D.h:148
void scaleW(double scalefactor)
Rescale as if all fill weights had been different by factor scalefactor.
Definition: Dbn2D.h:88
double yMean() const
Weighted mean, , of distribution.
Definition: Dbn2D.h:133
double sumWX2() const
The sum of x^2*weight.
Definition: Dbn2D.h:191
double effNumEntries() const
Effective number of entries .
Definition: Dbn2D.h:171
A 2D distribution.
Definition: Dbn2D.h:16
void reset()
Reset the distribution to an unfilled state.
Definition: Dbn2D.h:80
Dbn2D & add(const Dbn2D &d)
Add two dbns (internal, explicitly named version)
Definition: Dbn2D.h:256
void scaleXY(double xscale, double yscale)
Rescale x and y: needed if histo bin edges are rescaled.
Definition: Dbn2D.h:110
double xStdDev() const
Weighted standard deviation, , of distribution.
Definition: Dbn2D.h:142
Dbn2D(double numEntries, double sumW, double sumW2, double sumWX, double sumWX2, double sumWY, double sumWY2, double sumWXY)
Definition: Dbn2D.h:31
double sumWX() const
The sum of x*weight.
Definition: Dbn2D.h:186
void flipXY()
Interchange X and Y subdistributions.
Definition: Dbn2D.h:229
double sumW() const
The sum of weights.
Definition: Dbn2D.h:176
double yStdErr() const
Weighted standard error on the mean, , of distribution.
Definition: Dbn2D.h:151
Axis1D< BIN1D, DBN > operator+(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Add the statistics on two axes.
Definition: Axis1D.h:589
Dbn2D(const Dbn2D &toCopy)
Definition: Dbn2D.h:42
double yStdDev() const
Weighted standard deviation, , of distribution.
Definition: Dbn2D.h:145
void fill(double valX, double valY, double weight=1.0, double fraction=1.0)
Fill, providing the fill coordinates as two different numbers.
Definition: Dbn2D.h:66
double xRMS() const
Weighted RMS, , of distribution.
Definition: Dbn2D.h:154
double relErrW() const
The relative error on sumW.
Definition: Dbn2D.h:127
double yRMS() const
Weighted RMS, , of distribution.
Definition: Dbn2D.h:157
Dbn1D transformX()
Definition: Dbn2D.h:238
void scaleX(double xscale)
Rescale x: needed if x histo bin edges are rescaled.
Definition: Dbn2D.h:96
Dbn1D transformY()
Definition: Dbn2D.h:246
Dbn2D & operator+=(const Dbn2D &d)
Add two dbns.
Definition: Dbn2D.h:217
double sumWXY() const
The sum of x*y*weight.
Definition: Dbn2D.h:206
A 1D distribution.
Definition: Dbn1D.h:28
double numEntries() const
Number of entries (number of times fill was called, ignoring weights)
Definition: Dbn2D.h:166