yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.7.2
YODA::Axis1D< BIN1D, DBN > Class Template Reference

1D bin container More...

#include <Axis1D.h>

Public Types

typedef BIN1D Bin
 Typedefs. More...
 
typedef std::vector< BinBins
 A vector containing 1D bins. Not used for searching. More...
 

Public Member Functions

Constructors
 Axis1D ()
 Empty constructor. More...
 
 Axis1D (const std::vector< double > &binedges)
 Constructor accepting a list of bin edges. More...
 
 Axis1D (const std::vector< BIN1D > &bins)
 Constructor accepting a vector of bins. More...
 
 Axis1D (size_t nbins, double lower, double upper)
 
 Axis1D (const Bins &bins, const DBN &dbn_tot, const DBN &dbn_uflow, const DBN &dbn_oflow)
 Constructor accepting a vector of bins. More...
 
Statistics accessor functions
size_t numBins () const
 Get the number of bins on the axis. More...
 
const Binsbins () const
 Return a vector of bins (const) More...
 
Binsbins ()
 Return a vector of bins (non-const) More...
 
double xMin () const
 Return the lowest-value bin edge on the axis. More...
 
double xMax () const
 Return the highest-value bin edge on the axis. More...
 
std::vector< double > xEdges () const
 
BIN1D & bin (size_t index)
 Return a bin at a given index (non-const) More...
 
const BIN1D & bin (size_t index) const
 Return a bin at a given index (const) More...
 
ssize_t binIndexAt (double coord) const
 Returns an index of a bin at a given coord, -1 if no bin matches. More...
 
BIN1D & binAt (double x)
 Return a bin at a given coordinate (non-const) More...
 
const BIN1D & binAt (double x) const
 Return a bin at a given coordinate (const) More...
 
const DBN & totalDbn () const
 Return the total distribution (const) More...
 
DBN & totalDbn ()
 Return the total distribution (non-const) More...
 
void setTotalDbn (const DBN &dbn)
 Set the total distribution: CAREFUL! More...
 
const DBN & underflow () const
 Return underflow (const) More...
 
DBN & underflow ()
 Return underflow (non-const) More...
 
void setUnderflow (const DBN &dbn)
 Set the underflow distribution: CAREFUL! More...
 
const DBN & overflow () const
 Return overflow (const) More...
 
DBN & overflow ()
 Return overflow (non-const) More...
 
void setOverflow (const DBN &dbn)
 Set the overflow distribution: CAREFUL! More...
 
Modifiers and helpers
void reset ()
 Reset all the bin statistics on the axis. More...
 
void mergeBins (size_t from, size_t to)
 
void rebinBy (unsigned int n, size_t begin=0, size_t end=UINT_MAX)
 Merge every group of n bins, from start to end inclusive. More...
 
void rebin (unsigned int n, size_t begin=0, size_t end=UINT_MAX)
 Overloaded alias for rebinBy. More...
 
void rebinTo (const std::vector< double > &newedges)
 Rebin to the given list of bin edges. More...
 
void rebin (const std::vector< double > &newedges)
 Overloaded alias for rebinTo. More...
 
void addBin (const Bin &b)
 Add a bin, passed explicitly. More...
 
void addBin (double low, double high)
 Add a bin, providing its low and high edge. More...
 
void addBins (const std::vector< double > &binedges)
 Add a contiguous set of bins to an axis, via their list of edges. More...
 
void addBins (const std::vector< std::pair< double, double > > &binpairs)
 Add a list of bins as pairs of lowEdge, highEdge. More...
 
void addBins (const Bins &bins)
 Add a list of Bin objects. More...
 
void eraseBin (const size_t i)
 Remove a bin. More...
 
void eraseBins (const size_t from, const size_t to)
 Remove a bin range. More...
 
void scaleX (double scalefactor)
 Scale the size of an axis by a factor. More...
 
void scaleW (double scalefactor)
 Scale the amount of fills by a factor. More...
 
Comparisons to other Axis objects
bool sameBinning (const Axis1D &other) const
 
bool subsetBinning (const Axis1D &other) const
 
Operators
bool operator== (const Axis1D &other) const
 Check if two of the Axis have the same binning, within numeric tolerance. More...
 
bool operator!= (const Axis1D &other) const
 Check if the binning of two of the Axis is different. More...
 
Axis1D< BIN1D, DBN > & operator+= (const Axis1D< BIN1D, DBN > &toAdd)
 Add two axes together. More...
 
Axis1D< BIN1D, DBN > & operator-= (const Axis1D< BIN1D, DBN > &toSubtract)
 Subtract two axes. More...
 

Detailed Description

template<typename BIN1D, typename DBN>
class YODA::Axis1D< BIN1D, DBN >

1D bin container

This class handles most of the low-level operations on an axis of bins arranged in a 1D line (including gaps).

Definition at line 20 of file Axis1D.h.

Member Typedef Documentation

◆ Bin

template<typename BIN1D, typename DBN>
typedef BIN1D YODA::Axis1D< BIN1D, DBN >::Bin

Typedefs.

Bin type

Definition at line 27 of file Axis1D.h.

◆ Bins

template<typename BIN1D, typename DBN>
typedef std::vector<Bin> YODA::Axis1D< BIN1D, DBN >::Bins

A vector containing 1D bins. Not used for searching.

Definition at line 30 of file Axis1D.h.

Constructor & Destructor Documentation

◆ Axis1D() [1/5]

template<typename BIN1D, typename DBN>
YODA::Axis1D< BIN1D, DBN >::Axis1D ( )
inline

Empty constructor.

Definition at line 38 of file Axis1D.h.

39  : _locked(false)
40  { }

◆ Axis1D() [2/5]

template<typename BIN1D, typename DBN>
YODA::Axis1D< BIN1D, DBN >::Axis1D ( const std::vector< double > &  binedges)
inline

Constructor accepting a list of bin edges.

Definition at line 44 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::addBins().

45  : _locked(false)
46  {
47  addBins(binedges);
48  }
void addBins(const std::vector< double > &binedges)
Add a contiguous set of bins to an axis, via their list of edges.
Definition: Axis1D.h:361

◆ Axis1D() [3/5]

template<typename BIN1D, typename DBN>
YODA::Axis1D< BIN1D, DBN >::Axis1D ( const std::vector< BIN1D > &  bins)
inline

Constructor accepting a vector of bins.

Note that not only dimensions of these bins will be set, all the contents of the bins will be copied across, including the statistics

Definition at line 56 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::addBins().

57  : _locked(false)
58  {
59  addBins(bins);
60  }
void addBins(const std::vector< double > &binedges)
Add a contiguous set of bins to an axis, via their list of edges.
Definition: Axis1D.h:361

◆ Axis1D() [4/5]

template<typename BIN1D, typename DBN>
YODA::Axis1D< BIN1D, DBN >::Axis1D ( size_t  nbins,
double  lower,
double  upper 
)
inline

Constructor with the number of bins and the axis limits

Todo:
Rewrite interface to use a pair for the low/high

Definition at line 65 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::addBins(), and YODA::linspace().

66  : _locked(false)
67  {
68  addBins(linspace(nbins, lower, upper));
69  }
std::vector< double > linspace(size_t nbins, double start, double end, bool include_end=true)
Make a list of nbins + 1 values equally spaced between start and end inclusive.
Definition: MathUtils.h:252
void addBins(const std::vector< double > &binedges)
Add a contiguous set of bins to an axis, via their list of edges.
Definition: Axis1D.h:361

◆ Axis1D() [5/5]

template<typename BIN1D, typename DBN>
YODA::Axis1D< BIN1D, DBN >::Axis1D ( const Bins bins,
const DBN &  dbn_tot,
const DBN &  dbn_uflow,
const DBN &  dbn_oflow 
)
inline

Constructor accepting a vector of bins.

Note that not only dimensions of these bins will be set, all the contents of the bins will be copied across, including the statistics

Definition at line 77 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::addBins().

78  : _dbn(dbn_tot), _underflow(dbn_uflow), _overflow(dbn_oflow), _locked(false)
79  {
80  addBins(bins);
81  }
void addBins(const std::vector< double > &binedges)
Add a contiguous set of bins to an axis, via their list of edges.
Definition: Axis1D.h:361
const Bins & bins() const
Return a vector of bins (const)
Definition: Axis1D.h:92

Member Function Documentation

◆ addBin() [1/2]

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::addBin ( const Bin b)
inline

Add a bin, passed explicitly.

Todo:
Efficiency?

Definition at line 346 of file Axis1D.h.

Referenced by YODA::Axis1D< BIN1D, DBN >::addBin().

346  {
348  Bins newBins(_bins);
349  newBins.push_back(b);
350  _updateAxis(newBins);
351  }
std::vector< Bin > Bins
A vector containing 1D bins. Not used for searching.
Definition: Axis1D.h:30

◆ addBin() [2/2]

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::addBin ( double  low,
double  high 
)
inline

Add a bin, providing its low and high edge.

Definition at line 355 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::addBin().

355  {
356  addBin(Bin(low, high));
357  }
BIN1D Bin
Typedefs.
Definition: Axis1D.h:27
void addBin(const Bin &b)
Add a bin, passed explicitly.
Definition: Axis1D.h:346

◆ addBins() [1/3]

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::addBins ( const std::vector< double > &  binedges)
inline

Add a contiguous set of bins to an axis, via their list of edges.

Definition at line 361 of file Axis1D.h.

Referenced by YODA::Axis1D< BIN1D, DBN >::Axis1D().

361  {
362  Bins newBins(_bins);
363  if (binedges.size() == 0) return;
364 
365  double low = binedges.front();
366  for (size_t i = 1; i < binedges.size(); ++i) {
367  const double high = binedges[i];
368  assert(high>low); // Make sure binedges are meaningful
369  newBins.push_back(Bin(low, high));
370  low = high;
371  }
372 
373  _updateAxis(newBins);
374  }
BIN1D Bin
Typedefs.
Definition: Axis1D.h:27
std::vector< Bin > Bins
A vector containing 1D bins. Not used for searching.
Definition: Axis1D.h:30

◆ addBins() [2/3]

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::addBins ( const std::vector< std::pair< double, double > > &  binpairs)
inline

Add a list of bins as pairs of lowEdge, highEdge.

Definition at line 378 of file Axis1D.h.

378  {
379  // Make a copy of the current binning
380  Bins newBins(_bins);
381 
382  // Iterate over given bins
383  for (size_t i = 0; i < binpairs.size(); ++i) {
384  std::pair<double, double> b = binpairs[i];
385  newBins.push_back(Bin(b.first, b.second));
386  }
387  _updateAxis(newBins);
388  }
BIN1D Bin
Typedefs.
Definition: Axis1D.h:27
std::vector< Bin > Bins
A vector containing 1D bins. Not used for searching.
Definition: Axis1D.h:30

◆ addBins() [3/3]

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::addBins ( const Bins bins)
inline

Add a list of Bin objects.

Definition at line 392 of file Axis1D.h.

392  {
393  Bins newBins(_bins);
394  for (const Bin& b : bins) newBins.push_back(b);
395  _updateAxis(newBins);
396  }
BIN1D Bin
Typedefs.
Definition: Axis1D.h:27
const Bins & bins() const
Return a vector of bins (const)
Definition: Axis1D.h:92
std::vector< Bin > Bins
A vector containing 1D bins. Not used for searching.
Definition: Axis1D.h:30

◆ bin() [1/2]

template<typename BIN1D, typename DBN>
BIN1D& YODA::Axis1D< BIN1D, DBN >::bin ( size_t  index)
inline

Return a bin at a given index (non-const)

Definition at line 123 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::numBins().

Referenced by YODA::Axis1D< BIN1D, DBN >::binAt(), YODA::Axis1D< BIN1D, DBN >::mergeBins(), YODA::Axis1D< BIN1D, DBN >::operator-=(), YODA::Axis1D< BIN1D, DBN >::rebinTo(), and YODA::Axis1D< BIN1D, DBN >::reset().

123  {
124  if (index >= numBins()) throw RangeError("YODA::Histo1D: index out of range!");
125  return _bins[index];
126  }
size_t numBins() const
Get the number of bins on the axis.
Definition: Axis1D.h:87

◆ bin() [2/2]

template<typename BIN1D, typename DBN>
const BIN1D& YODA::Axis1D< BIN1D, DBN >::bin ( size_t  index) const
inline

Return a bin at a given index (const)

Definition at line 129 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::numBins().

129  {
130  if (index >= numBins()) throw RangeError("YODA::Histo1D: index out of range!");
131  return _bins[index];
132  }
size_t numBins() const
Get the number of bins on the axis.
Definition: Axis1D.h:87

◆ binAt() [1/2]

template<typename BIN1D, typename DBN>
BIN1D& YODA::Axis1D< BIN1D, DBN >::binAt ( double  x)
inline

Return a bin at a given coordinate (non-const)

Definition at line 141 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::bin(), and YODA::Axis1D< BIN1D, DBN >::binIndexAt().

141  {
142  const ssize_t index = binIndexAt(x);
143  if (index == -1) throw RangeError("There is no bin at the specified x");
144  return bin(index);
145  }
BIN1D & bin(size_t index)
Return a bin at a given index (non-const)
Definition: Axis1D.h:123
ssize_t binIndexAt(double coord) const
Returns an index of a bin at a given coord, -1 if no bin matches.
Definition: Axis1D.h:135

◆ binAt() [2/2]

template<typename BIN1D, typename DBN>
const BIN1D& YODA::Axis1D< BIN1D, DBN >::binAt ( double  x) const
inline

Return a bin at a given coordinate (const)

Definition at line 148 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::bin(), and YODA::Axis1D< BIN1D, DBN >::binIndexAt().

148  {
149  const ssize_t index = binIndexAt(x);
150  if (index == -1) throw RangeError("There is no bin at the specified x");
151  return bin(index);
152  }
BIN1D & bin(size_t index)
Return a bin at a given index (non-const)
Definition: Axis1D.h:123
ssize_t binIndexAt(double coord) const
Returns an index of a bin at a given coord, -1 if no bin matches.
Definition: Axis1D.h:135

◆ binIndexAt()

template<typename BIN1D, typename DBN>
ssize_t YODA::Axis1D< BIN1D, DBN >::binIndexAt ( double  coord) const
inline

Returns an index of a bin at a given coord, -1 if no bin matches.

Definition at line 135 of file Axis1D.h.

Referenced by YODA::Axis1D< BIN1D, DBN >::binAt().

135  {
136  // Yes, this is robust even with an empty axis: there's always at least one outflow
137  return _indexes[_binsearcher.index(coord)];
138  }

◆ bins() [1/2]

template<typename BIN1D, typename DBN>
const Bins& YODA::Axis1D< BIN1D, DBN >::bins ( ) const
inline

◆ bins() [2/2]

template<typename BIN1D, typename DBN>
Bins& YODA::Axis1D< BIN1D, DBN >::bins ( )
inline

Return a vector of bins (non-const)

Definition at line 97 of file Axis1D.h.

97  {
98  return _bins;
99  }

◆ eraseBin()

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::eraseBin ( const size_t  i)
inline

Remove a bin.

Definition at line 400 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::numBins().

Referenced by YODA::Axis1D< BIN1D, DBN >::rebinTo().

400  {
401  // Might as well erase from the internal bins, as we can guarantee
402  // consistency.
403  if (i >= numBins())
404  throw RangeError("Bin index is out of range");
405 
406  const bool wasLocked = _locked;
407  _locked = false;
408  _bins.erase(_bins.begin() + i);
409  _updateAxis(_bins);
410  _locked = wasLocked;
411  }
size_t numBins() const
Get the number of bins on the axis.
Definition: Axis1D.h:87

◆ eraseBins()

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::eraseBins ( const size_t  from,
const size_t  to 
)
inline

Remove a bin range.

Definition at line 415 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::numBins().

Referenced by YODA::Axis1D< BIN1D, DBN >::mergeBins().

415  {
416  if (from >= numBins())
417  throw RangeError("Initial index out of range");
418  if (to >= numBins())
419  throw RangeError("Final index out of range");
420  if (from > to)
421  throw RangeError("Final index is less than initial index");
422 
423  const bool wasLocked = _locked;
424  _locked = false;
425  _bins.erase(_bins.begin() + from, _bins.begin() + to + 1);
426  _updateAxis(_bins);
427  _locked = wasLocked;
428  }
size_t numBins() const
Get the number of bins on the axis.
Definition: Axis1D.h:87

◆ mergeBins()

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::mergeBins ( size_t  from,
size_t  to 
)
inline

Merge together the bin range with indices from from to to, inclusive. Merge a series of bins, between the bins identified by indices from and to

Definition at line 258 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::bin(), YODA::Axis1D< BIN1D, DBN >::eraseBins(), and YODA::Axis1D< BIN1D, DBN >::numBins().

Referenced by YODA::Axis1D< BIN1D, DBN >::rebinBy(), and YODA::Axis1D< BIN1D, DBN >::rebinTo().

258  {
259  // Correctness checking
260  if (from >= numBins())
261  throw RangeError("Initial merge index is out of range");
262  if (to >= numBins())
263  throw RangeError("Final merge index is out of range");
264  if (from > to)
265  throw RangeError("Final bin must be greater than or equal to initial bin");
266  if (_gapInRange(from, to))
267  throw RangeError("Bin ranges containing gaps cannot be merged");
268  if (from == to)
269  return; // nothing to be done
270 
271  Bin& b = bin(from);
272  for (size_t i = from + 1; i <= to; ++i)
273  b.merge(_bins[i]);
274  eraseBins(from+1, to);
275  }
BIN1D Bin
Typedefs.
Definition: Axis1D.h:27
void eraseBins(const size_t from, const size_t to)
Remove a bin range.
Definition: Axis1D.h:415
BIN1D & bin(size_t index)
Return a bin at a given index (non-const)
Definition: Axis1D.h:123
size_t numBins() const
Get the number of bins on the axis.
Definition: Axis1D.h:87

◆ numBins()

◆ operator!=()

template<typename BIN1D, typename DBN>
bool YODA::Axis1D< BIN1D, DBN >::operator!= ( const Axis1D< BIN1D, DBN > &  other) const
inline

Check if the binning of two of the Axis is different.

Definition at line 483 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::operator==().

483  {
484  return ! operator == (other);
485  }
bool operator==(const Axis1D &other) const
Check if two of the Axis have the same binning, within numeric tolerance.
Definition: Axis1D.h:477

◆ operator+=()

template<typename BIN1D, typename DBN>
Axis1D<BIN1D,DBN>& YODA::Axis1D< BIN1D, DBN >::operator+= ( const Axis1D< BIN1D, DBN > &  toAdd)
inline

Add two axes together.

Definition at line 489 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::bins().

489  {
490  if (*this != toAdd) throw LogicError("YODA::Histo1D: Cannot add axes with different binnings.");
491 
492  for (size_t i = 0; i < _bins.size(); ++i) {
493  _bins[i] += toAdd.bins().at(i);
494  }
495 
496  _dbn += toAdd._dbn;
497  _underflow += toAdd._underflow;
498  _overflow += toAdd._overflow;
499  return *this;
500  }

◆ operator-=()

template<typename BIN1D, typename DBN>
Axis1D<BIN1D,DBN>& YODA::Axis1D< BIN1D, DBN >::operator-= ( const Axis1D< BIN1D, DBN > &  toSubtract)
inline

Subtract two axes.

Definition at line 504 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::bin(), YODA::Axis1D< BIN1D, DBN >::bins(), and YODA::Axis1D< BIN1D, DBN >::numBins().

504  {
505  if (*this != toSubtract) throw LogicError("YODA::Histo1D: Cannot add axes with different binnings.");
506 
507  for (size_t i = 0; i < _bins.size(); ++i) {
508  _bins[i] -= toSubtract.bins().at(i);
509  }
510 
511  _dbn -= toSubtract._dbn;
512  _underflow -= toSubtract._underflow;
513  _overflow -= toSubtract._overflow;
514  return *this;
515  }

◆ operator==()

template<typename BIN1D, typename DBN>
bool YODA::Axis1D< BIN1D, DBN >::operator== ( const Axis1D< BIN1D, DBN > &  other) const
inline

Check if two of the Axis have the same binning, within numeric tolerance.

Definition at line 477 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::sameBinning().

Referenced by YODA::Axis1D< BIN1D, DBN >::operator!=().

477  {
478  return sameBinning(other);
479  }
bool sameBinning(const Axis1D &other) const
Definition: Axis1D.h:457

◆ overflow() [1/2]

template<typename BIN1D, typename DBN>
const DBN& YODA::Axis1D< BIN1D, DBN >::overflow ( ) const
inline

Return overflow (const)

Definition at line 182 of file Axis1D.h.

182  {
183  return _overflow;
184  }

◆ overflow() [2/2]

template<typename BIN1D, typename DBN>
DBN& YODA::Axis1D< BIN1D, DBN >::overflow ( )
inline

Return overflow (non-const)

Definition at line 186 of file Axis1D.h.

186  {
187  return _overflow;
188  }

◆ rebin() [1/2]

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::rebin ( unsigned int  n,
size_t  begin = 0,
size_t  end = UINT_MAX 
)
inline

Overloaded alias for rebinBy.

Definition at line 296 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::rebinBy().

296 { rebinBy(n, begin, end); }
void rebinBy(unsigned int n, size_t begin=0, size_t end=UINT_MAX)
Merge every group of n bins, from start to end inclusive.
Definition: Axis1D.h:283

◆ rebin() [2/2]

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::rebin ( const std::vector< double > &  newedges)
inline

Overloaded alias for rebinTo.

Definition at line 342 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::rebinTo().

342 { rebinTo(newedges); }
void rebinTo(const std::vector< double > &newedges)
Rebin to the given list of bin edges.
Definition: Axis1D.h:300

◆ rebinBy()

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::rebinBy ( unsigned int  n,
size_t  begin = 0,
size_t  end = UINT_MAX 
)
inline

Merge every group of n bins, from start to end inclusive.

If the number of bins is not a multiple of n, the last m < n bins on the RHS will also be merged, as the closest possible approach to factor
rebinning everywhere.

Definition at line 283 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::mergeBins(), and YODA::Axis1D< BIN1D, DBN >::numBins().

Referenced by YODA::Axis1D< BIN1D, DBN >::rebin().

283  {
284  if (n < 1) throw UserError("Rebinning requested in groups of 0!");
285  for (size_t m = begin; m < end; ++m) {
286  if (m > numBins()) break;
287  const size_t myend = (m+n-1 < numBins()) ? m+n-1 : numBins()-1;
288  if (myend > m) {
289  mergeBins(m, myend);
290  end -= myend-m; //< reduce upper index by the number of removed bins
291  }
292  }
293  }
void mergeBins(size_t from, size_t to)
Definition: Axis1D.h:258
size_t numBins() const
Get the number of bins on the axis.
Definition: Axis1D.h:87

◆ rebinTo()

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::rebinTo ( const std::vector< double > &  newedges)
inline

Rebin to the given list of bin edges.

Definition at line 300 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::bin(), YODA::Axis1D< BIN1D, DBN >::eraseBin(), YODA::fuzzyEquals(), YODA::Axis1D< BIN1D, DBN >::mergeBins(), YODA::Axis1D< BIN1D, DBN >::xMax(), and YODA::Axis1D< BIN1D, DBN >::xMin().

Referenced by YODA::Axis1D< BIN1D, DBN >::rebin().

300  {
301  if (newedges.size() < 2)
302  throw UserError("Requested rebinning to an edge list which defines no bins");
303  const Utils::BinSearcher newbs(newedges);
304  const std::vector<double> eshared = newbs.shared_edges(_binsearcher);
305  if (eshared.size() != newbs.size())
306  throw BinningError("Requested rebinning to incompatible edges");
307  // std::cout << "Before merging" << std::endl;
308  // for (double x : _binsearcher.edges()) std::cout << x << std::endl;
309  // If the new min finite edge isn't the same, merge it into the underflow
310  // NB. Edge search match the *next* bin, so step back one unit... and note these are BinSearcher indices, i.e. i+1
311  if (!fuzzyEquals(xMin(), newedges.front())) {
312  const size_t kmatch = _binsearcher.index(newedges.front()) - 1;
313  mergeBins(0, kmatch-1);
314  _underflow += bin(0).dbn();
315  eraseBin(0);
316  }
317  // std::cout << "Merged start bins" << std::endl;
318  // for (double x : _binsearcher.edges()) std::cout << x << std::endl;
319  // Now the same for the overflow
320  if (!fuzzyEquals(xMax(), newedges.back())) {
321  const size_t kmatch = _binsearcher.index(newedges.back()) - 1;
322  // std::cout << newedges.back() << " -> " << kmatch << " .. " << _bins.size()-1 << " / " << numBins() << std::endl;
323  mergeBins(kmatch, _bins.size()-1);
324  _overflow += bin(_bins.size()-1).dbn();
325  eraseBin(_bins.size()-1);
326  }
327  // std::cout << "Merged end bins" << std::endl;
328  // for (double x : _binsearcher.edges()) std::cout << x << std::endl;
329  // Now merge the in-range bins
330  size_t jcurr = 0;
331  for (size_t i = 1; i < newedges.size(); ++i) { //< we already know that i=0 matches (until we support merging into overflows)
332  const size_t kmatch = _binsearcher.index(newedges.at(i)) - 1; //< Will match the *next* bin, so step back one unit... and note these are BinSearcher indices
333  assert(kmatch >= jcurr+1);
334  mergeBins(jcurr, kmatch-1);
335  jcurr += 1; //< The next bin to be merged, in the new numbering
336  }
337  // std::cout << "After merging" << std::endl;
338  // for (double x : _binsearcher.edges()) std::cout << x << std::endl;
339  }
double xMin() const
Return the lowest-value bin edge on the axis.
Definition: Axis1D.h:102
void eraseBin(const size_t i)
Remove a bin.
Definition: Axis1D.h:400
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
BIN1D & bin(size_t index)
Return a bin at a given index (non-const)
Definition: Axis1D.h:123
void mergeBins(size_t from, size_t to)
Definition: Axis1D.h:258
double xMax() const
Return the highest-value bin edge on the axis.
Definition: Axis1D.h:108

◆ reset()

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::reset ( )
inline

Reset all the bin statistics on the axis.

Definition at line 201 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::bin(), and YODA::Axis1D< BIN1D, DBN >::bins().

201  {
202  _dbn.reset();
203  _underflow.reset();
204  _overflow.reset();
205  for (Bin& bin : _bins) bin.reset();
206  _locked = false;
207  }
BIN1D Bin
Typedefs.
Definition: Axis1D.h:27
BIN1D & bin(size_t index)
Return a bin at a given index (non-const)
Definition: Axis1D.h:123

◆ sameBinning()

template<typename BIN1D, typename DBN>
bool YODA::Axis1D< BIN1D, DBN >::sameBinning ( const Axis1D< BIN1D, DBN > &  other) const
inline

Definition at line 457 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::numBins().

Referenced by YODA::Axis1D< BIN1D, DBN >::operator==(), and YODA::Axis1D< BIN1D, DBN >::subsetBinning().

457  {
458  if (numBins() != other.numBins()) return false;
459  if (_indexes != other._indexes) return false;
460  return _binsearcher.same_edges(other._binsearcher);
461  }
size_t numBins() const
Get the number of bins on the axis.
Definition: Axis1D.h:87

◆ scaleW()

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::scaleW ( double  scalefactor)
inline

Scale the amount of fills by a factor.

Definition at line 444 of file Axis1D.h.

444  {
445  _dbn.scaleW(scalefactor);
446  _underflow.scaleW(scalefactor);
447  _overflow.scaleW(scalefactor);
448  for (size_t i = 0; i < _bins.size(); ++i) _bins[i].scaleW(scalefactor);
449  }
void scaleW(double scalefactor)
Scale the amount of fills by a factor.
Definition: Axis1D.h:444

◆ scaleX()

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::scaleX ( double  scalefactor)
inline

Scale the size of an axis by a factor.

Definition at line 433 of file Axis1D.h.

433  {
434  _dbn.scaleX(scalefactor);
435  _underflow.scaleX(scalefactor);
436  _overflow.scaleX(scalefactor);
437  for (size_t i = 0; i < _bins.size(); ++i)
438  _bins[i].scaleX(scalefactor);
439  _updateAxis(_bins);
440  }
void scaleX(double scalefactor)
Scale the size of an axis by a factor.
Definition: Axis1D.h:433

◆ setOverflow()

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::setOverflow ( const DBN &  dbn)
inline

Set the overflow distribution: CAREFUL!

Definition at line 190 of file Axis1D.h.

190  {
191  _overflow = dbn;
192  }

◆ setTotalDbn()

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::setTotalDbn ( const DBN &  dbn)
inline

Set the total distribution: CAREFUL!

Definition at line 164 of file Axis1D.h.

164  {
165  _dbn = dbn;
166  }

◆ setUnderflow()

template<typename BIN1D, typename DBN>
void YODA::Axis1D< BIN1D, DBN >::setUnderflow ( const DBN &  dbn)
inline

Set the underflow distribution: CAREFUL!

Definition at line 177 of file Axis1D.h.

177  {
178  _underflow = dbn;
179  }

◆ subsetBinning()

template<typename BIN1D, typename DBN>
bool YODA::Axis1D< BIN1D, DBN >::subsetBinning ( const Axis1D< BIN1D, DBN > &  other) const
inline
Todo:
Do we require the finite axis begin/end to be the same?

Definition at line 463 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::numBins(), and YODA::Axis1D< BIN1D, DBN >::sameBinning().

463  {
464  const int ndiff = numBins() - other.numBins();
465  if (ndiff == 0) return sameBinning(other);
467  return !_binsearcher.shared_edges(other._binsearcher).empty();
468  }
size_t numBins() const
Get the number of bins on the axis.
Definition: Axis1D.h:87
bool sameBinning(const Axis1D &other) const
Definition: Axis1D.h:457

◆ totalDbn() [1/2]

template<typename BIN1D, typename DBN>
const DBN& YODA::Axis1D< BIN1D, DBN >::totalDbn ( ) const
inline

Return the total distribution (const)

Definition at line 156 of file Axis1D.h.

156  {
157  return _dbn;
158  }

◆ totalDbn() [2/2]

template<typename BIN1D, typename DBN>
DBN& YODA::Axis1D< BIN1D, DBN >::totalDbn ( )
inline

Return the total distribution (non-const)

Definition at line 160 of file Axis1D.h.

160  {
161  return _dbn;
162  }

◆ underflow() [1/2]

template<typename BIN1D, typename DBN>
const DBN& YODA::Axis1D< BIN1D, DBN >::underflow ( ) const
inline

Return underflow (const)

Definition at line 169 of file Axis1D.h.

169  {
170  return _underflow;
171  }

◆ underflow() [2/2]

template<typename BIN1D, typename DBN>
DBN& YODA::Axis1D< BIN1D, DBN >::underflow ( )
inline

Return underflow (non-const)

Definition at line 173 of file Axis1D.h.

173  {
174  return _underflow;
175  }

◆ xEdges()

template<typename BIN1D, typename DBN>
std::vector<double> YODA::Axis1D< BIN1D, DBN >::xEdges ( ) const
inline

Return all the Nbin+1 bin edges on the axis

Note
This only returns the finite edges, i.e. -inf and +inf are removed
Todo:
Make the +-inf stripping controllable by a default-valued bool arg

Definition at line 117 of file Axis1D.h.

117  {
118  std::vector<double> rtn(_binsearcher.edges().begin()+1, _binsearcher.edges().end()-1);
119  return rtn;
120  }

◆ xMax()

template<typename BIN1D, typename DBN>
double YODA::Axis1D< BIN1D, DBN >::xMax ( ) const
inline

Return the highest-value bin edge on the axis.

Definition at line 108 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::bins(), and YODA::Axis1D< BIN1D, DBN >::numBins().

Referenced by YODA::Axis1D< BIN1D, DBN >::rebinTo().

108  {
109  if (numBins() == 0) throw RangeError("This axis contains no bins and so has no defined range");
110  return bins().back().xMax();
111  }
size_t numBins() const
Get the number of bins on the axis.
Definition: Axis1D.h:87
const Bins & bins() const
Return a vector of bins (const)
Definition: Axis1D.h:92

◆ xMin()

template<typename BIN1D, typename DBN>
double YODA::Axis1D< BIN1D, DBN >::xMin ( ) const
inline

Return the lowest-value bin edge on the axis.

Definition at line 102 of file Axis1D.h.

References YODA::Axis1D< BIN1D, DBN >::bins(), and YODA::Axis1D< BIN1D, DBN >::numBins().

Referenced by YODA::Axis1D< BIN1D, DBN >::rebinTo().

102  {
103  if (numBins() == 0) throw RangeError("This axis contains no bins and so has no defined range");
104  return bins().front().xMin();
105  }
size_t numBins() const
Get the number of bins on the axis.
Definition: Axis1D.h:87
const Bins & bins() const
Return a vector of bins (const)
Definition: Axis1D.h:92

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