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

A generic 1D bin type. More...

#include <Bin1D.h>

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

Public Member Functions

Constructors
 Bin1D (const std::pair< double, double > &edges)
 Make a new, empty bin with a pair of edges. More...
 
 Bin1D (const std::pair< double, double > &edges, const DBN &dbn)
 Make a bin with all the components of a fill history. More...
 
 Bin1D (const Bin1D< DBN > &b)
 Copy constructor. More...
 
Bin1Doperator= (const Bin1D< DBN > &b)
 Copy assignment. More...
 
Modifiers
virtual void reset ()
 Reset this bin. More...
 
void scaleW (double scalefactor)
 
void scaleX (double factor)
 
X-axis info
std::pair< double, double > xEdges () const
 Get the {low,high} edges as an STL pair. More...
 
double xMin () const
 Lower limit of the bin (inclusive). More...
 
double xMax () const
 Upper limit of the bin (exclusive). More...
 
double xMid () const
 Geometric centre of the bin, i.e. high+low/2.0. More...
 
double midpoint () const
 
double xWidth () const
 Separation of low and high edges, i.e. high-low. More...
 
double width () const
 
double xFocus () const
 The mean position in the bin, or the midpoint if that is not available. More...
 
X distribution statistics
double xMean () const
 Mean value of x-values in the bin. More...
 
double xVariance () const
 The variance of x-values in the bin. More...
 
double xStdDev () const
 The standard deviation (spread) of x-values in the bin. More...
 
double xStdErr () const
 The standard error on the bin focus. More...
 
double xRMS () const
 The x 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 sumWX2 () const
 The sum of x^2 * weight. More...
 
Operators
Bin1D< DBN > & operator+= (const Bin1D< DBN > &b)
 Add two bins. More...
 
Bin1D< DBN > & operator-= (const Bin1D< DBN > &b)
 Subtract one bin from another. More...
 
Named operators
Bin1D< DBN > & merge (const Bin1D< DBN > &b)
 Merge two adjacent bins. More...
 
Bin1D< DBN > & add (const Bin1D< DBN > &b)
 
Bin1D< DBN > & subtract (const Bin1D< DBN > &b)
 
- Public Member Functions inherited from YODA::Bin
virtual ~Bin ()
 Virtual destructor for inheritance. More...
 

Detailed Description

template<class DBN>
class YODA::Bin1D< DBN >

A generic 1D bin type.

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

Todo:
It would also be nice to have an untemplated generic Bin1D interface

Definition at line 27 of file Bin1D.h.

Constructor & Destructor Documentation

template<class DBN>
YODA::Bin1D< DBN >::Bin1D ( const std::pair< double, double > &  edges)
inline

Make a new, empty bin with a pair of edges.

Definition at line 44 of file Bin1D.h.

45  : _edges(edges)
46  {
47  if (_edges.second < _edges.first) {
48  throw RangeError("The bin edges are wrongly defined!");
49  }
50  }
template<class DBN>
YODA::Bin1D< DBN >::Bin1D ( const std::pair< double, double > &  edges,
const DBN &  dbn 
)
inline

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

Mainly intended for internal persistency use.

Definition at line 56 of file Bin1D.h.

57  : _edges(edges), _dbn(dbn)
58  {
59  if (_edges.second < _edges.first) {
60  throw RangeError("The bin edges are wrongly defined!");
61  }
62  }
DBN & dbn()
Statistical distribution in this bin (non-const)
Definition: Bin1D.h:191
template<class DBN>
YODA::Bin1D< DBN >::Bin1D ( const Bin1D< DBN > &  b)
inline

Copy constructor.

Definition at line 66 of file Bin1D.h.

67  : _edges(b._edges),
68  _dbn(b._dbn)
69  { }

Member Function Documentation

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

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 275 of file Bin1D.h.

Referenced by YODA::HistoBin1D::add(), YODA::ProfileBin1D::add(), and YODA::Bin1D< Dbn2D >::operator+=().

275  {
276  if (!fuzzyEquals(_edges.first, b._edges.first) ||
277  !fuzzyEquals(_edges.second, b._edges.second)) {
278  throw LogicError("Attempted to add two bins with different edges");
279  }
280  _dbn += b._dbn;
281  return *this;
282  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:68
template<class DBN>
DBN& YODA::Bin1D< DBN >::dbn ( )
inline

Statistical distribution in this bin (non-const)

Definition at line 191 of file Bin1D.h.

191  {
192  return _dbn;
193  }
template<class DBN>
const DBN& YODA::Bin1D< DBN >::dbn ( ) const
inline

Statistical distribution in this bin (const)

Definition at line 196 of file Bin1D.h.

196  {
197  return _dbn;
198  }
template<class DBN>
double YODA::Bin1D< DBN >::effNumEntries ( ) const
inline

The effective number of entries.

Definition at line 207 of file Bin1D.h.

207  {
208  return _dbn.effNumEntries();
209  }
template<class DBN>
Bin1D<DBN>& YODA::Bin1D< DBN >::merge ( const Bin1D< DBN > &  b)
inline

Merge two adjacent bins.

Definition at line 256 of file Bin1D.h.

256  {
257  if (fuzzyEquals(_edges.second, b._edges.first)) {
258  _edges.second = b._edges.second;
259  } else if (fuzzyEquals(_edges.second, b._edges.first)) {
260  _edges.first = b._edges.first;
261  } else {
262  throw LogicError("Attempted to merge two non-adjacent bins");
263  }
264  // std::cout << "a " << _dbn.sumW() << std::endl;
265  _dbn += b._dbn;
266  // std::cout << "b " << _dbn.sumW() << std::endl;
267  return *this;
268  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:68
template<class DBN>
double YODA::Bin1D< DBN >::midpoint ( ) const
inline

Alias for xMid

Deprecated:
Only retained for temporary backward compatibility: use xMid

Definition at line 135 of file Bin1D.h.

135 { return xMid(); }
double xMid() const
Geometric centre of the bin, i.e. high+low/2.0.
Definition: Bin1D.h:130
template<class DBN>
unsigned long YODA::Bin1D< DBN >::numEntries ( ) const
inlinevirtual

The number of entries.

Implements YODA::Bin.

Definition at line 202 of file Bin1D.h.

Referenced by YODA::efficiency(), YODA::WriterYODA::writeHisto1D(), and YODA::WriterYODA::writeProfile1D().

202  {
203  return _dbn.numEntries();
204  }
template<class DBN>
Bin1D<DBN>& YODA::Bin1D< DBN >::operator+= ( const Bin1D< DBN > &  b)
inline

Add two bins.

Definition at line 240 of file Bin1D.h.

240  {
241  return add(b);
242  }
Bin1D< DBN > & add(const Bin1D< DBN > &b)
Definition: Bin1D.h:275
template<class DBN>
Bin1D<DBN>& YODA::Bin1D< DBN >::operator-= ( const Bin1D< DBN > &  b)
inline

Subtract one bin from another.

Definition at line 245 of file Bin1D.h.

245  {
246  return subtract(b);
247  }
Bin1D< DBN > & subtract(const Bin1D< DBN > &b)
Definition: Bin1D.h:289
template<class DBN>
Bin1D& YODA::Bin1D< DBN >::operator= ( const Bin1D< DBN > &  b)
inline

Copy assignment.

Definition at line 73 of file Bin1D.h.

Referenced by YODA::HistoBin1D::operator=(), and YODA::ProfileBin1D::operator=().

73  {
74  _edges = b._edges;
75  _dbn = b._dbn;
76  return *this;
77  }
template<class DBN>
virtual void YODA::Bin1D< DBN >::reset ( )
inlinevirtual

Reset this bin.

Implements YODA::Bin.

Definition at line 86 of file Bin1D.h.

86  {
87  _dbn.reset();
88  }
template<class DBN>
void YODA::Bin1D< 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 93 of file Bin1D.h.

93  {
94  _dbn.scaleW(scalefactor);
95  }
template<class DBN>
void YODA::Bin1D< DBN >::scaleX ( double  factor)
inline

Scale the x dimension

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

Definition at line 100 of file Bin1D.h.

100  {
101  _edges.first *= factor;
102  _edges.second *= factor;
103  _dbn.scaleX(factor);
104  }
template<class DBN>
Bin1D<DBN>& YODA::Bin1D< DBN >::subtract ( const Bin1D< 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 289 of file Bin1D.h.

Referenced by YODA::Bin1D< Dbn2D >::operator-=(), YODA::HistoBin1D::subtract(), and YODA::ProfileBin1D::subtract().

289  {
290  if (!fuzzyEquals(_edges.first, b._edges.first) ||
291  !fuzzyEquals(_edges.second, b._edges.second)) {
292  throw LogicError("Attempted to subtract two bins with different edges");
293  }
294  _dbn -= b._dbn;
295  return *this;
296  }
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:68
template<class DBN>
double YODA::Bin1D< DBN >::sumW ( ) const
inlinevirtual
template<class DBN>
double YODA::Bin1D< DBN >::sumW2 ( ) const
inlinevirtual

The sum of weights squared.

Implements YODA::Bin.

Definition at line 217 of file Bin1D.h.

Referenced by YODA::efficiency(), YODA::Profile1D::sumW2(), YODA::Histo1D::sumW2(), YODA::toTH1D(), YODA::WriterYODA::writeHisto1D(), and YODA::WriterYODA::writeProfile1D().

217  {
218  return _dbn.sumW2();
219  }
template<class DBN>
double YODA::Bin1D< DBN >::sumWX ( ) const
inline

The sum of x*weight.

Definition at line 222 of file Bin1D.h.

Referenced by YODA::WriterYODA::writeHisto1D(), YODA::WriterYODA::writeProfile1D(), and YODA::Histo1D::xMean().

222  {
223  return _dbn.sumWX();
224  }
template<class DBN>
double YODA::Bin1D< DBN >::sumWX2 ( ) const
inline

The sum of x^2 * weight.

Definition at line 227 of file Bin1D.h.

Referenced by YODA::WriterYODA::writeHisto1D(), and YODA::WriterYODA::writeProfile1D().

227  {
228  return _dbn.sumWX2();
229  }
template<class DBN>
double YODA::Bin1D< DBN >::width ( ) const
inline

Alias for xWidth

Deprecated:
Only retained for temporary backward compatibility: use xWidth

Definition at line 143 of file Bin1D.h.

143 { return xWidth(); }
double xWidth() const
Separation of low and high edges, i.e. high-low.
Definition: Bin1D.h:138
template<class DBN>
std::pair<double,double> YODA::Bin1D< DBN >::xEdges ( ) const
inline

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

Definition at line 115 of file Bin1D.h.

Referenced by YODA::operator<().

115  {
116  return _edges;
117  }
template<class DBN>
double YODA::Bin1D< DBN >::xFocus ( ) const
inline

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

Definition at line 147 of file Bin1D.h.

Referenced by YODA::mkScatter(), and YODA::Histo1D::xVariance().

147  {
148  return (!isZero(sumW())) ? xMean() : xMid();
149  }
bool isZero(double val, double tolerance=1E-8)
Definition: MathUtils.h:51
double sumW() const
The sum of weights.
Definition: Bin1D.h:212
double xMid() const
Geometric centre of the bin, i.e. high+low/2.0.
Definition: Bin1D.h:130
double xMean() const
Mean value of x-values in the bin.
Definition: Bin1D.h:158
template<class DBN>
double YODA::Bin1D< DBN >::xMax ( ) const
inline

Upper limit of the bin (exclusive).

Definition at line 125 of file Bin1D.h.

Referenced by YODA::Histo1D::Histo1D(), YODA::mkScatter(), YODA::Profile1D::Profile1D(), YODA::toTH1D(), YODA::toTProfile(), YODA::WriterYODA::writeHisto1D(), and YODA::WriterYODA::writeProfile1D().

125  {
126  return _edges.second;
127  }
template<class DBN>
double YODA::Bin1D< DBN >::xMean ( ) const
inline

Mean value of x-values in the bin.

Definition at line 158 of file Bin1D.h.

Referenced by YODA::Bin1D< Dbn2D >::xFocus().

158  {
159  return _dbn.xMean();
160  }
template<class DBN>
double YODA::Bin1D< DBN >::xMid ( ) const
inline

Geometric centre of the bin, i.e. high+low/2.0.

Definition at line 130 of file Bin1D.h.

Referenced by YODA::Bin1D< Dbn2D >::midpoint(), YODA::mkScatter(), and YODA::Bin1D< Dbn2D >::xFocus().

130  {
131  return ( _edges.second + _edges.first ) / 2;
132  }
template<class DBN>
double YODA::Bin1D< DBN >::xMin ( ) const
inline

Lower limit of the bin (inclusive).

Definition at line 120 of file Bin1D.h.

Referenced by YODA::Histo1D::Histo1D(), YODA::mkScatter(), YODA::Profile1D::Profile1D(), YODA::toTH1D(), YODA::toTProfile(), YODA::WriterYODA::writeHisto1D(), and YODA::WriterYODA::writeProfile1D().

120  {
121  return _edges.first;
122  }
template<class DBN>
double YODA::Bin1D< DBN >::xRMS ( ) const
inline

The x RMS in the bin.

Definition at line 178 of file Bin1D.h.

178  {
179  return _dbn.xRMS();
180  }
template<class DBN>
double YODA::Bin1D< DBN >::xStdDev ( ) const
inline

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

Definition at line 168 of file Bin1D.h.

168  {
169  return _dbn.xStdDev();
170  }
template<class DBN>
double YODA::Bin1D< DBN >::xStdErr ( ) const
inline

The standard error on the bin focus.

Definition at line 173 of file Bin1D.h.

173  {
174  return _dbn.xStdErr();
175  }
template<class DBN>
double YODA::Bin1D< DBN >::xVariance ( ) const
inline

The variance of x-values in the bin.

Definition at line 163 of file Bin1D.h.

163  {
164  return _dbn.xVariance();
165  }
template<class DBN>
double YODA::Bin1D< DBN >::xWidth ( ) const
inline

Separation of low and high edges, i.e. high-low.

Definition at line 138 of file Bin1D.h.

Referenced by YODA::Bin1D< Dbn2D >::width().

138  {
139  return _edges.second - _edges.first;
140  }

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