YODA is hosted by Hepforge, IPPP Durham
YODA::Bin2D< DBN > Class Template Reference

A generic 2D bin type. More...

#include <Bin2D.h>

Inheritance diagram for YODA::Bin2D< DBN >:
YODA::Bin

Public Member Functions

Constructors
 Bin2D (const std::pair< double, double > &xedges, const std::pair< double, double > &yedges)
 Make a new, empty bin with two pairs of edges. More...
 
 Bin2D (const std::pair< double, double > &xedges, const std::pair< double, double > &yedges, const DBN &dbn)
 Make a bin with all the components of a fill history. More...
 
 Bin2D (const Bin2D< DBN > &b)
 Copy constructor. More...
 
Bin2D< DBN > & operator= (const Bin2D< DBN > &b)
 Copy assignment. More...
 
Modifiers
virtual void reset ()
 Reset this bin. More...
 
void scaleW (double scalefactor)
 
void scaleXY (double scaleX, double scaleY)
 
X-axis info
std::pair< double, double > xEdges () const
 Get the {low,high} edges as an STL pair. More...
 
double xMin () const
 Lower x limit of the bin (inclusive). More...
 
double xMax () const
 Upper x limit of the bin (exclusive). More...
 
std::pair< double, double > yEdges () const
 Get the {low,high} edges as an STL pair. More...
 
double yMin () const
 Lower y limit of the bin (inclusive). More...
 
double yMax () const
 Upper y limit of the bin (exclusive). More...
 
double xMid () const
 Middle of the bin in x. More...
 
double yMid () const
 Middle of the bin in y. More...
 
std::pair< double, double > xyMid () const
 The geometric centre of the bin. More...
 
double xWidth () const
 Width of the bin in x. More...
 
double yWidth () const
 Width of the bin in y. More...
 
std::pair< double, double > xyWidths () const
 Widths of the bin in x and y. More...
 
double xFocus () const
 The mean x position in the bin, or the x midpoint if that is not available. More...
 
double yFocus () const
 The mean y position in the bin, or the y midpoint if that is not available. More...
 
std::pair< double, double > xyFocus () const
 The mean position in the bin, or the midpoint if that is not available. More...
 
Distribution statistics
double xMean () const
 Mean value of x-values in the bin. More...
 
double yMean () const
 Mean value of y-values in the bin. More...
 
double xVariance () const
 The variance of x-values in the bin. More...
 
double yVariance () const
 The variance of y-values in the bin. More...
 
double xStdDev () const
 The standard deviation (spread) of x-values in the bin. More...
 
double yStdDev () const
 The standard deviation (spread) of y-values in the bin. More...
 
double xStdErr () const
 The standard error on the bin x focus. More...
 
double yStdErr () const
 The standard error on the bin y focus. More...
 
double xRMS () const
 The x RMS in the bin. More...
 
double yRMS () const
 The y RMS in the bin. More...
 
Raw distribution statistics
DBN & dbn ()
 Statistical distribution in this bin (non-const) More...
 
const DBN & dbn () const
 Statistical distribution in this bin (const) More...
 
unsigned long numEntries () const
 The number of entries. More...
 
double effNumEntries () const
 The effective number of entries. More...
 
double sumW () const
 The sum of weights. More...
 
double sumW2 () const
 The sum of weights squared. More...
 
double sumWX () const
 The sum of x*weight. More...
 
double sumWY () const
 The sum of y*weight. More...
 
double sumWXY () const
 The sum of x*y*weight. More...
 
double sumWX2 () const
 The sum of x^2 * weight. More...
 
double sumWY2 () const
 The sum of y^2 * weight. More...
 
Operators
Bin2D< DBN > & operator+= (const Bin2D< DBN > &b)
 Add two bins. More...
 
Bin2D< DBN > & operator-= (const Bin2D< DBN > &b)
 Subtract one bin from another. More...
 
Named operators
Bin2D< DBN > & add (const Bin2D< DBN > &b)
 Merge two adjacent bins. More...
 
Bin2D< DBN > & subtract (const Bin2D< DBN > &b)
 
bool fitsInside (std::pair< double, double > xrange, std::pair< double, double > yrange) const
 Test whether this bin would fit inside the given area. More...
 
bool bounds (double x, double y) const
 Test whether a point lies within the current bin. More...
 
int adjacentTo (const Bin2D< DBN > &b) const
 Test whether two bins are adjacent and, if so, return how as an integer. More...
 
- Public Member Functions inherited from YODA::Bin
virtual ~Bin ()
 Virtual destructor for inheritance. More...
 

Detailed Description

template<class DBN>
class YODA::Bin2D< DBN >

A generic 2D bin type.

This is a generic 2D bin type which supplies the accessors for the two "x" and "y" axis directions in which it is defined. Bin2D is not intended to be directly instantiated: it is inherited from to make specific histogram and profile bin types as HistoBin2D and ProfileBin2D. The lower bin edges in x and y are inclusive. This base class provides no fill method, since the signatures for standard and profile histos differ.

Definition at line 25 of file Bin2D.h.

Constructor & Destructor Documentation

template<class DBN>
YODA::Bin2D< DBN >::Bin2D ( const std::pair< double, double > &  xedges,
const std::pair< double, double > &  yedges 
)
inline

Make a new, empty bin with two pairs of edges.

Definition at line 46 of file Bin2D.h.

47  : _xedges(xedges), _yedges(yedges)
48  {
49  if (_xedges.second < _xedges.first) {
50  throw RangeError("The bin x-edges are wrongly defined!");
51  }
52  if (_yedges.second < _yedges.first) {
53  throw RangeError("The bin y-edges are wrongly defined!");
54  }
55  }
template<class DBN>
YODA::Bin2D< DBN >::Bin2D ( const std::pair< double, double > &  xedges,
const std::pair< double, double > &  yedges,
const DBN &  dbn 
)
inline

Make a bin with all the components of a fill history.

Mainly intended for internal persistency use.

Definition at line 61 of file Bin2D.h.

63  : _xedges(xedges), _yedges(yedges), _dbn(dbn)
64  {
65  if (_xedges.second < _xedges.first) {
66  throw RangeError("The bin x-edges are wrongly defined!");
67  }
68  if (_yedges.second < _yedges.first) {
69  throw RangeError("The bin y-edges are wrongly defined!");
70  }
71  }
DBN & dbn()
Statistical distribution in this bin (non-const)
Definition: Bin2D.h:276
template<class DBN>
YODA::Bin2D< DBN >::Bin2D ( const Bin2D< DBN > &  b)
inline

Copy constructor.

Definition at line 75 of file Bin2D.h.

76  : _xedges(b._xedges),
77  _yedges(b._yedges),
78  _dbn(b._dbn)
79  { }

Member Function Documentation

template<class DBN>
Bin2D<DBN>& YODA::Bin2D< DBN >::add ( const Bin2D< DBN > &  b)
inline

Merge two adjacent bins.

Add two bins (internal, explicitly named version)

This operator is defined for adding two bins with equivalent binning. It cannot be used to merge two bins into one larger bin.

Definition at line 377 of file Bin2D.h.

Referenced by YODA::ProfileBin2D::add(), and YODA::Bin2D< Dbn3D >::operator+=().

377  {
378  if (_xedges != b._xedges || _yedges != b._yedges) {
379  throw LogicError("Attempted to add two bins with different edges");
380  }
381  _dbn += b._dbn;
382  return *this;
383  }
template<class DBN>
int YODA::Bin2D< DBN >::adjacentTo ( const Bin2D< DBN > &  b) const
inline

Test whether two bins are adjacent and, if so, return how as an integer.

Definition at line 415 of file Bin2D.h.

415  {
416  for (int i = 0; i < 4; i++) {
417  if (_edges_equal(b, i, (i+2) % 4))
418  return i;
419  }
420  return -1;
421  }
template<class DBN>
bool YODA::Bin2D< DBN >::bounds ( double  x,
double  y 
) const
inline

Test whether a point lies within the current bin.

Definition at line 408 of file Bin2D.h.

408  {
409  return (x >= xMin() && x < xMax() && y >= yMin() && y < yMax());
410  }
double xMax() const
Upper x limit of the bin (exclusive).
Definition: Bin2D.h:141
double xMin() const
Lower x limit of the bin (inclusive).
Definition: Bin2D.h:136
double yMin() const
Lower y limit of the bin (inclusive).
Definition: Bin2D.h:152
double yMax() const
Upper y limit of the bin (exclusive).
Definition: Bin2D.h:157
template<class DBN>
DBN& YODA::Bin2D< DBN >::dbn ( )
inline

Statistical distribution in this bin (non-const)

Definition at line 276 of file Bin2D.h.

276  {
277  return _dbn;
278  }
template<class DBN>
const DBN& YODA::Bin2D< DBN >::dbn ( ) const
inline

Statistical distribution in this bin (const)

Definition at line 281 of file Bin2D.h.

281  {
282  return _dbn;
283  }
template<class DBN>
double YODA::Bin2D< DBN >::effNumEntries ( ) const
inline

The effective number of entries.

Definition at line 291 of file Bin2D.h.

291  {
292  return _dbn.effNumEntries();
293  }
template<class DBN>
bool YODA::Bin2D< DBN >::fitsInside ( std::pair< double, double >  xrange,
std::pair< double, double >  yrange 
) const
inline

Test whether this bin would fit inside the given area.

Definition at line 399 of file Bin2D.h.

400  {
401  return (xMin() >= xrange.first &&
402  yMin() >= yrange.first &&
403  xMax() < xrange.second &&
404  yMax() < yrange.second);
405  }
double xMax() const
Upper x limit of the bin (exclusive).
Definition: Bin2D.h:141
double xMin() const
Lower x limit of the bin (inclusive).
Definition: Bin2D.h:136
double yMin() const
Lower y limit of the bin (inclusive).
Definition: Bin2D.h:152
double yMax() const
Upper y limit of the bin (exclusive).
Definition: Bin2D.h:157
template<class DBN>
unsigned long YODA::Bin2D< DBN >::numEntries ( ) const
inlinevirtual

The number of entries.

Implements YODA::Bin.

Definition at line 286 of file Bin2D.h.

Referenced by YODA::efficiency(), YODA::WriterYODA::writeHisto2D(), and YODA::WriterYODA::writeProfile2D().

286  {
287  return _dbn.numEntries();
288  }
template<class DBN>
Bin2D<DBN>& YODA::Bin2D< DBN >::operator+= ( const Bin2D< DBN > &  b)
inline

Add two bins.

Definition at line 339 of file Bin2D.h.

339  {
340  return add(b);
341  }
Bin2D< DBN > & add(const Bin2D< DBN > &b)
Merge two adjacent bins.
Definition: Bin2D.h:377
template<class DBN>
Bin2D<DBN>& YODA::Bin2D< DBN >::operator-= ( const Bin2D< DBN > &  b)
inline

Subtract one bin from another.

Definition at line 344 of file Bin2D.h.

344  {
345  return subtract(b);
346  }
Bin2D< DBN > & subtract(const Bin2D< DBN > &b)
Definition: Bin2D.h:390
template<class DBN>
Bin2D<DBN>& YODA::Bin2D< DBN >::operator= ( const Bin2D< DBN > &  b)
inline

Copy assignment.

Definition at line 83 of file Bin2D.h.

Referenced by YODA::HistoBin2D::operator=(), and YODA::ProfileBin2D::operator=().

83  {
84  _xedges = b._xedges;
85  _yedges = b._yedges;
86  _dbn = b._dbn;
87  return *this;
88  }
template<class DBN>
virtual void YODA::Bin2D< DBN >::reset ( )
inlinevirtual

Reset this bin.

Implements YODA::Bin.

Reimplemented in YODA::ProfileBin2D, and YODA::HistoBin2D.

Definition at line 97 of file Bin2D.h.

Referenced by YODA::HistoBin2D::reset(), and YODA::ProfileBin2D::reset().

97  {
98  _dbn.reset();
99  }
template<class DBN>
void YODA::Bin2D< DBN >::scaleW ( double  scalefactor)
inline

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

Note
This should not be used, since it breaks histogram consistency. It will be removed in a future version.

Definition at line 104 of file Bin2D.h.

104  {
105  _dbn.scaleW(scalefactor);
106  }
template<class DBN>
void YODA::Bin2D< DBN >::scaleXY ( double  scaleX,
double  scaleY 
)
inline

Scale the x and y coordinates and distributions.

Note
This should not be used, since it breaks histogram consistency. It will be removed in a future version.

Definition at line 111 of file Bin2D.h.

111  {
112  _xedges.first *= scaleX;
113  _xedges.second *= scaleX;
114 
115  _yedges.first *= scaleY;
116  _yedges.second *= scaleY;
117 
118  _dbn.scaleX(scaleX);
119  _dbn.scaleY(scaleY);
120  }
template<class DBN>
Bin2D<DBN>& YODA::Bin2D< DBN >::subtract ( const Bin2D< DBN > &  b)
inline

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

This operator is defined for subtracting two bins with equivalent binning. It cannot be used to merge two bins into one larger bin.

Definition at line 390 of file Bin2D.h.

Referenced by YODA::Bin2D< Dbn3D >::operator-=(), and YODA::ProfileBin2D::subtract().

390  {
391  if (_xedges != b._xedges || _yedges != b._yedges) {
392  throw LogicError("Attempted to subtract two bins with different edges");
393  }
394  _dbn -= b._dbn;
395  return *this;
396  }
template<class DBN>
double YODA::Bin2D< DBN >::sumW ( ) const
inlinevirtual
template<class DBN>
double YODA::Bin2D< DBN >::sumW2 ( ) const
inlinevirtual

The sum of weights squared.

Implements YODA::Bin.

Definition at line 301 of file Bin2D.h.

Referenced by YODA::efficiency(), YODA::Histo2D::sumW2(), YODA::toTH2D(), YODA::WriterYODA::writeHisto2D(), and YODA::WriterYODA::writeProfile2D().

301  {
302  return _dbn.sumW2();
303  }
template<class DBN>
double YODA::Bin2D< DBN >::sumWX ( ) const
inline

The sum of x*weight.

Definition at line 306 of file Bin2D.h.

Referenced by YODA::WriterYODA::writeHisto2D(), YODA::WriterYODA::writeProfile2D(), YODA::Profile2D::xMean(), and YODA::Histo2D::xMean().

306  {
307  return _dbn.sumWX();
308  }
template<class DBN>
double YODA::Bin2D< DBN >::sumWX2 ( ) const
inline

The sum of x^2 * weight.

Definition at line 321 of file Bin2D.h.

Referenced by YODA::WriterYODA::writeHisto2D(), and YODA::WriterYODA::writeProfile2D().

321  {
322  return _dbn.sumWX2();
323  }
template<class DBN>
double YODA::Bin2D< DBN >::sumWXY ( ) const
inline

The sum of x*y*weight.

Definition at line 316 of file Bin2D.h.

Referenced by YODA::WriterYODA::writeHisto2D(), and YODA::WriterYODA::writeProfile2D().

316  {
317  return _dbn.sumWXY();
318  }
template<class DBN>
double YODA::Bin2D< DBN >::sumWY ( ) const
inline

The sum of y*weight.

Definition at line 311 of file Bin2D.h.

Referenced by YODA::WriterYODA::writeHisto2D(), YODA::WriterYODA::writeProfile2D(), YODA::Profile2D::yMean(), and YODA::Histo2D::yMean().

311  {
312  return _dbn.sumWY();
313  }
template<class DBN>
double YODA::Bin2D< DBN >::sumWY2 ( ) const
inline

The sum of y^2 * weight.

Definition at line 326 of file Bin2D.h.

Referenced by YODA::WriterYODA::writeHisto2D(), and YODA::WriterYODA::writeProfile2D().

326  {
327  return _dbn.sumWY2();
328  }
template<class DBN>
std::pair<double,double> YODA::Bin2D< DBN >::xEdges ( ) const
inline

Get the {low,high} edges as an STL pair.

Definition at line 131 of file Bin2D.h.

131  {
132  return _xedges;
133  }
template<class DBN>
double YODA::Bin2D< DBN >::xFocus ( ) const
inline

The mean x position in the bin, or the x midpoint if that is not available.

Definition at line 195 of file Bin2D.h.

Referenced by YODA::mkScatter(), and YODA::Bin2D< Dbn3D >::xyFocus().

195  {
196  return (!isZero(sumW())) ? xMean() : xMid();
197  }
bool isZero(double val, double tolerance=1E-8)
Definition: MathUtils.h:51
double xMean() const
Mean value of x-values in the bin.
Definition: Bin2D.h:218
double xMid() const
Middle of the bin in x.
Definition: Bin2D.h:163
double sumW() const
The sum of weights.
Definition: Bin2D.h:296
template<class DBN>
double YODA::Bin2D< DBN >::xMax ( ) const
inline
template<class DBN>
double YODA::Bin2D< DBN >::xMean ( ) const
inline

Mean value of x-values in the bin.

Definition at line 218 of file Bin2D.h.

Referenced by YODA::Bin2D< Dbn3D >::xFocus().

218  {
219  return _dbn.xMean();
220  }
template<class DBN>
double YODA::Bin2D< DBN >::xMid ( ) const
inline

Middle of the bin in x.

Definition at line 163 of file Bin2D.h.

Referenced by YODA::mkScatter(), YODA::Bin2D< Dbn3D >::xFocus(), and YODA::Bin2D< Dbn3D >::xyMid().

163  {
164  return (xMax() + xMin())/2.0;
165  }
double xMax() const
Upper x limit of the bin (exclusive).
Definition: Bin2D.h:141
double xMin() const
Lower x limit of the bin (inclusive).
Definition: Bin2D.h:136
template<class DBN>
double YODA::Bin2D< DBN >::xMin ( ) const
inline
template<class DBN>
double YODA::Bin2D< DBN >::xRMS ( ) const
inline

The x RMS in the bin.

Definition at line 258 of file Bin2D.h.

258  {
259  return _dbn.xRMS();
260  }
template<class DBN>
double YODA::Bin2D< DBN >::xStdDev ( ) const
inline

The standard deviation (spread) of x-values in the bin.

Definition at line 238 of file Bin2D.h.

238  {
239  return _dbn.xStdDev();
240  }
template<class DBN>
double YODA::Bin2D< DBN >::xStdErr ( ) const
inline

The standard error on the bin x focus.

Definition at line 248 of file Bin2D.h.

248  {
249  return _dbn.xStdErr();
250  }
template<class DBN>
double YODA::Bin2D< DBN >::xVariance ( ) const
inline

The variance of x-values in the bin.

Definition at line 228 of file Bin2D.h.

228  {
229  return _dbn.xVariance();
230  }
template<class DBN>
double YODA::Bin2D< DBN >::xWidth ( ) const
inline

Width of the bin in x.

Definition at line 179 of file Bin2D.h.

Referenced by YODA::Bin2D< Dbn3D >::xyWidths().

179  {
180  return xMax() - xMin();
181  }
double xMax() const
Upper x limit of the bin (exclusive).
Definition: Bin2D.h:141
double xMin() const
Lower x limit of the bin (inclusive).
Definition: Bin2D.h:136
template<class DBN>
std::pair<double, double> YODA::Bin2D< DBN >::xyFocus ( ) const
inline

The mean position in the bin, or the midpoint if that is not available.

Definition at line 205 of file Bin2D.h.

205  {
206  return std::make_pair(xFocus(), yFocus());
207  }
double xFocus() const
The mean x position in the bin, or the x midpoint if that is not available.
Definition: Bin2D.h:195
double yFocus() const
The mean y position in the bin, or the y midpoint if that is not available.
Definition: Bin2D.h:200
template<class DBN>
std::pair<double, double> YODA::Bin2D< DBN >::xyMid ( ) const
inline

The geometric centre of the bin.

Definition at line 173 of file Bin2D.h.

173  {
174  return std::make_pair(xMid(), yMid());
175  }
double xMid() const
Middle of the bin in x.
Definition: Bin2D.h:163
double yMid() const
Middle of the bin in y.
Definition: Bin2D.h:168
template<class DBN>
std::pair<double, double> YODA::Bin2D< DBN >::xyWidths ( ) const
inline

Widths of the bin in x and y.

Definition at line 189 of file Bin2D.h.

189  {
190  return std::make_pair(xWidth(), yWidth());
191  }
double xWidth() const
Width of the bin in x.
Definition: Bin2D.h:179
double yWidth() const
Width of the bin in y.
Definition: Bin2D.h:184
template<class DBN>
std::pair<double,double> YODA::Bin2D< DBN >::yEdges ( ) const
inline

Get the {low,high} edges as an STL pair.

Definition at line 147 of file Bin2D.h.

147  {
148  return _yedges;
149  }
template<class DBN>
double YODA::Bin2D< DBN >::yFocus ( ) const
inline

The mean y position in the bin, or the y midpoint if that is not available.

Definition at line 200 of file Bin2D.h.

Referenced by YODA::mkScatter(), and YODA::Bin2D< Dbn3D >::xyFocus().

200  {
201  return (!isZero(sumW())) ? yMean() : yMid();
202  }
bool isZero(double val, double tolerance=1E-8)
Definition: MathUtils.h:51
double sumW() const
The sum of weights.
Definition: Bin2D.h:296
double yMid() const
Middle of the bin in y.
Definition: Bin2D.h:168
double yMean() const
Mean value of y-values in the bin.
Definition: Bin2D.h:223
template<class DBN>
double YODA::Bin2D< DBN >::yMax ( ) const
inline
template<class DBN>
double YODA::Bin2D< DBN >::yMean ( ) const
inline

Mean value of y-values in the bin.

Definition at line 223 of file Bin2D.h.

Referenced by YODA::Bin2D< Dbn3D >::yFocus().

223  {
224  return _dbn.yMean();
225  }
template<class DBN>
double YODA::Bin2D< DBN >::yMid ( ) const
inline

Middle of the bin in y.

Definition at line 168 of file Bin2D.h.

Referenced by YODA::mkScatter(), YODA::Bin2D< Dbn3D >::xyMid(), and YODA::Bin2D< Dbn3D >::yFocus().

168  {
169  return (yMax() + yMin())/2.0;
170  }
double yMin() const
Lower y limit of the bin (inclusive).
Definition: Bin2D.h:152
double yMax() const
Upper y limit of the bin (exclusive).
Definition: Bin2D.h:157
template<class DBN>
double YODA::Bin2D< DBN >::yMin ( ) const
inline
template<class DBN>
double YODA::Bin2D< DBN >::yRMS ( ) const
inline

The y RMS in the bin.

Definition at line 263 of file Bin2D.h.

263  {
264  return _dbn.yRMS();
265  }
template<class DBN>
double YODA::Bin2D< DBN >::yStdDev ( ) const
inline

The standard deviation (spread) of y-values in the bin.

Definition at line 243 of file Bin2D.h.

243  {
244  return _dbn.yStdDev();
245  }
template<class DBN>
double YODA::Bin2D< DBN >::yStdErr ( ) const
inline

The standard error on the bin y focus.

Definition at line 253 of file Bin2D.h.

253  {
254  return _dbn.yStdErr();
255  }
template<class DBN>
double YODA::Bin2D< DBN >::yVariance ( ) const
inline

The variance of y-values in the bin.

Definition at line 233 of file Bin2D.h.

233  {
234  return _dbn.yVariance();
235  }
template<class DBN>
double YODA::Bin2D< DBN >::yWidth ( ) const
inline

Width of the bin in y.

Definition at line 184 of file Bin2D.h.

Referenced by YODA::Bin2D< Dbn3D >::xyWidths().

184  {
185  return yMax() - yMin();
186  }
double yMin() const
Lower y limit of the bin (inclusive).
Definition: Bin2D.h:152
double yMax() const
Upper y limit of the bin (exclusive).
Definition: Bin2D.h:157

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