yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
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

size_t dim ()
 Dimension of the fill space. More...
 
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...
 
double 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

◆ Bin1D() [1/3]

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  }

◆ Bin1D() [2/3]

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:197

◆ Bin1D() [3/3]

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

◆ add()

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

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

281  {
282  if (!fuzzyEquals(_edges.first, b._edges.first) ||
283  !fuzzyEquals(_edges.second, b._edges.second)) {
284  throw LogicError("Attempted to add two bins with different edges");
285  }
286  _dbn += b._dbn;
287  return *this;
288  }
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:72

◆ dbn() [1/2]

template<class DBN>
DBN& YODA::Bin1D< DBN >::dbn ( )
inline

Statistical distribution in this bin (non-const)

Definition at line 197 of file Bin1D.h.

197  {
198  return _dbn;
199  }

◆ dbn() [2/2]

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

Statistical distribution in this bin (const)

Definition at line 202 of file Bin1D.h.

202  {
203  return _dbn;
204  }

◆ dim()

template<class DBN>
size_t YODA::Bin1D< DBN >::dim ( )
inlinevirtual

Dimension of the fill space.

Implements YODA::Bin.

Definition at line 84 of file Bin1D.h.

84 { return 1; }

◆ effNumEntries()

template<class DBN>
double YODA::Bin1D< DBN >::effNumEntries ( ) const
inlinevirtual

The effective number of entries.

Implements YODA::Bin.

Definition at line 213 of file Bin1D.h.

213  {
214  return _dbn.effNumEntries();
215  }

◆ merge()

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

Merge two adjacent bins.

Definition at line 262 of file Bin1D.h.

262  {
263  if (fuzzyEquals(_edges.second, b._edges.first)) {
264  _edges.second = b._edges.second;
265  } else if (fuzzyEquals(_edges.second, b._edges.first)) {
266  _edges.first = b._edges.first;
267  } else {
268  throw LogicError("Attempted to merge two non-adjacent bins");
269  }
270  // std::cout << "a " << _dbn.sumW() << std::endl;
271  _dbn += b._dbn;
272  // std::cout << "b " << _dbn.sumW() << std::endl;
273  return *this;
274  }
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:72

◆ midpoint()

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

141 { return xMid(); }
double xMid() const
Geometric centre of the bin, i.e. high+low/2.0.
Definition: Bin1D.h:136

◆ numEntries()

template<class DBN>
double YODA::Bin1D< DBN >::numEntries ( ) const
inlinevirtual

The number of entries.

Implements YODA::Bin.

Definition at line 208 of file Bin1D.h.

Referenced by YODA::efficiency().

208  {
209  return _dbn.numEntries();
210  }

◆ operator+=()

template<class DBN>
Bin1D<DBN>& YODA::Bin1D< DBN >::operator+= ( const Bin1D< DBN > &  b)
inline

Add two bins.

Definition at line 246 of file Bin1D.h.

246  {
247  return add(b);
248  }
Bin1D< DBN > & add(const Bin1D< DBN > &b)
Definition: Bin1D.h:281

◆ operator-=()

template<class DBN>
Bin1D<DBN>& YODA::Bin1D< DBN >::operator-= ( const Bin1D< DBN > &  b)
inline

Subtract one bin from another.

Definition at line 251 of file Bin1D.h.

251  {
252  return subtract(b);
253  }
Bin1D< DBN > & subtract(const Bin1D< DBN > &b)
Definition: Bin1D.h:295

◆ operator=()

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  }

◆ reset()

template<class DBN>
virtual void YODA::Bin1D< DBN >::reset ( )
inlinevirtual

Reset this bin.

Implements YODA::Bin.

Definition at line 92 of file Bin1D.h.

92  {
93  _dbn.reset();
94  }

◆ scaleW()

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

99  {
100  _dbn.scaleW(scalefactor);
101  }

◆ scaleX()

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

106  {
107  _edges.first *= factor;
108  _edges.second *= factor;
109  _dbn.scaleX(factor);
110  }

◆ subtract()

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

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

295  {
296  if (!fuzzyEquals(_edges.first, b._edges.first) ||
297  !fuzzyEquals(_edges.second, b._edges.second)) {
298  throw LogicError("Attempted to subtract two bins with different edges");
299  }
300  _dbn -= b._dbn;
301  return *this;
302  }
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:72

◆ sumW()

template<class DBN>
double YODA::Bin1D< DBN >::sumW ( ) const
inlinevirtual

The sum of weights.

Implements YODA::Bin.

Definition at line 218 of file Bin1D.h.

Referenced by YODA::Histo1D::integralRange(), YODA::toIntegralHisto(), YODA::toTH1D(), YODA::toTProfile(), and YODA::Bin1D< Dbn2D >::xFocus().

218  {
219  return _dbn.sumW();
220  }

◆ sumW2()

template<class DBN>
double YODA::Bin1D< DBN >::sumW2 ( ) const
inlinevirtual

The sum of weights squared.

Implements YODA::Bin.

Definition at line 223 of file Bin1D.h.

Referenced by YODA::toTH1D().

223  {
224  return _dbn.sumW2();
225  }

◆ sumWX()

template<class DBN>
double YODA::Bin1D< DBN >::sumWX ( ) const
inline

The sum of x*weight.

Definition at line 228 of file Bin1D.h.

228  {
229  return _dbn.sumWX();
230  }

◆ sumWX2()

template<class DBN>
double YODA::Bin1D< DBN >::sumWX2 ( ) const
inline

The sum of x^2 * weight.

Definition at line 233 of file Bin1D.h.

233  {
234  return _dbn.sumWX2();
235  }

◆ width()

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

149 { return xWidth(); }
double xWidth() const
Separation of low and high edges, i.e. high-low.
Definition: Bin1D.h:144

◆ xEdges()

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

Referenced by YODA::operator<().

121  {
122  return _edges;
123  }

◆ xFocus()

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

153  {
154  return (!isZero(sumW())) ? xMean() : xMid();
155  }
bool isZero(double val, double tolerance=1E-8)
Definition: MathUtils.h:55
double xMid() const
Geometric centre of the bin, i.e. high+low/2.0.
Definition: Bin1D.h:136
double sumW() const
The sum of weights.
Definition: Bin1D.h:218
double xMean() const
Mean value of x-values in the bin.
Definition: Bin1D.h:164

◆ xMax()

template<class DBN>
double YODA::Bin1D< DBN >::xMax ( ) const
inline

Upper limit of the bin (exclusive).

Definition at line 131 of file Bin1D.h.

Referenced by YODA::add(), YODA::divide(), YODA::multiply(), YODA::subtract(), YODA::toTH1D(), and YODA::toTProfile().

131  {
132  return _edges.second;
133  }

◆ xMean()

template<class DBN>
double YODA::Bin1D< DBN >::xMean ( ) const
inline

Mean value of x-values in the bin.

Definition at line 164 of file Bin1D.h.

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

164  {
165  return _dbn.xMean();
166  }

◆ xMid()

template<class DBN>
double YODA::Bin1D< DBN >::xMid ( ) const
inline

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

Definition at line 136 of file Bin1D.h.

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

136  {
137  return ( _edges.second + _edges.first ) / 2;
138  }

◆ xMin()

template<class DBN>
double YODA::Bin1D< DBN >::xMin ( ) const
inline

Lower limit of the bin (inclusive).

Definition at line 126 of file Bin1D.h.

Referenced by YODA::add(), YODA::divide(), YODA::multiply(), YODA::subtract(), YODA::toTH1D(), and YODA::toTProfile().

126  {
127  return _edges.first;
128  }

◆ xRMS()

template<class DBN>
double YODA::Bin1D< DBN >::xRMS ( ) const
inline

The x RMS in the bin.

Definition at line 184 of file Bin1D.h.

184  {
185  return _dbn.xRMS();
186  }

◆ xStdDev()

template<class DBN>
double YODA::Bin1D< DBN >::xStdDev ( ) const
inline

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

Definition at line 174 of file Bin1D.h.

174  {
175  return _dbn.xStdDev();
176  }

◆ xStdErr()

template<class DBN>
double YODA::Bin1D< DBN >::xStdErr ( ) const
inline

The standard error on the bin focus.

Definition at line 179 of file Bin1D.h.

179  {
180  return _dbn.xStdErr();
181  }

◆ xVariance()

template<class DBN>
double YODA::Bin1D< DBN >::xVariance ( ) const
inline

The variance of x-values in the bin.

Definition at line 169 of file Bin1D.h.

169  {
170  return _dbn.xVariance();
171  }

◆ xWidth()

template<class DBN>
double YODA::Bin1D< DBN >::xWidth ( ) const
inline

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

Definition at line 144 of file Bin1D.h.

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

144  {
145  return _edges.second - _edges.first;
146  }

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