yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.9.0
YODA::Axis2D< BIN2D, DBN > Class Template Reference

2D bin container More...

#include <Axis2D.h>

Public Types

typedef BIN2D Bin
 Bin type. More...
 
typedef std::vector< BinBins
 A vector containing 2D bins. Not used for searching. More...
 
typedef std::vector< double > Edges
 
typedef std::pair< double, double > EdgePair1D
 
typedef std::pair< EdgePair1D, EdgePair1DEdgePair2D
 
typedef std::vector< EdgePair2DEdgePair2Ds
 
typedef std::vector< DBN > Outflow
 
typedef std::vector< OutflowOutflows
 

Public Member Functions

Constructors
 Axis2D ()
 
 Axis2D (const Edges &xedges, const Edges &yedges)
 A constructor with specified x and y axis bin cuts. More...
 
 Axis2D (size_t nbinsX, const std::pair< double, double > &rangeX, size_t nbinsY, const std::pair< double, double > &rangeY)
 
 Axis2D (const Bins &bins)
 Constructor accepting a list of bins. More...
 
 Axis2D (const Bins &bins, const DBN &totalDbn, const Outflows &outflows)
 State-setting constructor for persistency. More...
 
void reset ()
 
size_t numBins () const
 Get the number of bins. More...
 
size_t numBinsX () const
 
size_t numBinsY () const
 
Statistics accessor functions
Outflowoutflow (int ix, int iy)
 Get the outflow by x-index and y-index (non-const version) More...
 
const Outflowoutflow (int ix, int iy) const
 Get the outflow by x-index and y-index (const version) More...
 
void scaleX (double xscale)
 Scale each bin as if the entire x-axis had been scaled by this factor. More...
 
void scaleY (double yscale)
 Scale each bin as if the entire y-axis had been scaled by this factor. More...
 
void scaleXY (double sx, double sy)
 
void scaleW (double scalefactor)
 
void eraseBin (size_t i)
 
void eraseBins (const size_t from, const size_t to)
 Erase a rectangle of bins. More...
 
void eraseBins (const std::pair< double, double > &xrange, const std::pair< double, double > &yrange)
 
void eraseBins (const std::vector< bool > &deleteMask)
 
void mergeBins (size_t from, size_t to)
 
void rebin (unsigned int n)
 Rebin with the same rebinning factor n in x and y. More...
 
void rebinXY (unsigned int nx, unsigned int ny)
 Rebin with separate rebinning factors nx, ny in x and y. More...
 
void rebinX (unsigned int nx)
 Rebin in x by factor nx. More...
 
void rebinY (unsigned int ny)
 Rebin in y by factor ny. More...
 
double xMin () const
 Return the lowest-valued bin edge along the x-axis. More...
 
double xMax () const
 Return the highest-valued bin edge along the x-axis. More...
 
double yMin () const
 Return the lowest-valued bin edge along the y-axis. More...
 
double yMax () const
 Return the highest-valued bin edge along the y-axis. More...
 
std::vector< double > xEdges () const
 
std::vector< double > yEdges () const
 
void addBin (EdgePair1D xrange, EdgePair1D yrange)
 Add a bin, providing its x- and y- edge ranges. More...
 
void addBin (const Bin &bin)
 Add a pre-made bin. More...
 
void addBins (const Bins &bins)
 Add a vector of pre-made bins. More...
 
void addBins (const std::vector< double > &xedges, const std::vector< double > &yedges)
 Add a contiguous set of bins to an axis, via their list of edges. More...
 
Binbin (size_t i)
 Access bin by index. More...
 
const Binbin (size_t i) const
 Access bin by index (const) More...
 
int binIndexAt (double x, double y) const
 Get the bin index of the bin containing point (x, y). More...
 
BinbinAt (double x, double y)
 Get the bin containing point (x, y). More...
 
const BinbinAt (double x, double y) const
 Get the bin containing point (x, y) (const). More...
 
DBN & totalDbn ()
 Return the total distribution (non-const) More...
 
const DBN & totalDbn () const
 Return the total distribution (const) More...
 
void setTotalDbn (const DBN &dbn)
 Set the total distribution: CAREFUL! More...
 
Binsbins ()
 Return the bins vector (non-const) More...
 
const Binsbins () const
 Return the bins vector (const) More...
 
bool operator== (const Axis2D &other) const
 
bool operator!= (const Axis2D &other) const
 Non-equality operator. More...
 
Axis2D< BIN2D, DBN > & operator+= (const Axis2D< BIN2D, DBN > &toAdd)
 Addition operator. More...
 
Axis2D< BIN2D, DBN > & operator-= (const Axis2D< BIN2D, DBN > &toSubtract)
 Subtraction operator. More...
 

Detailed Description

template<typename BIN2D, typename DBN>
class YODA::Axis2D< BIN2D, DBN >

2D bin container

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

Definition at line 21 of file Axis2D.h.

Member Typedef Documentation

◆ Bin

template<typename BIN2D, typename DBN>
typedef BIN2D YODA::Axis2D< BIN2D, DBN >::Bin

Bin type.

Typedefs

Definition at line 28 of file Axis2D.h.

◆ Bins

template<typename BIN2D, typename DBN>
typedef std::vector<Bin> YODA::Axis2D< BIN2D, DBN >::Bins

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

Definition at line 31 of file Axis2D.h.

◆ EdgePair1D

template<typename BIN2D, typename DBN>
typedef std::pair<double, double> YODA::Axis2D< BIN2D, DBN >::EdgePair1D

Definition at line 35 of file Axis2D.h.

◆ EdgePair2D

template<typename BIN2D, typename DBN>
typedef std::pair<EdgePair1D, EdgePair1D> YODA::Axis2D< BIN2D, DBN >::EdgePair2D

Definition at line 36 of file Axis2D.h.

◆ EdgePair2Ds

template<typename BIN2D, typename DBN>
typedef std::vector<EdgePair2D> YODA::Axis2D< BIN2D, DBN >::EdgePair2Ds

Definition at line 37 of file Axis2D.h.

◆ Edges

template<typename BIN2D, typename DBN>
typedef std::vector<double> YODA::Axis2D< BIN2D, DBN >::Edges

Definition at line 34 of file Axis2D.h.

◆ Outflow

template<typename BIN2D, typename DBN>
typedef std::vector<DBN> YODA::Axis2D< BIN2D, DBN >::Outflow

Definition at line 40 of file Axis2D.h.

◆ Outflows

template<typename BIN2D, typename DBN>
typedef std::vector<Outflow> YODA::Axis2D< BIN2D, DBN >::Outflows

Definition at line 41 of file Axis2D.h.

Constructor & Destructor Documentation

◆ Axis2D() [1/5]

template<typename BIN2D, typename DBN>
YODA::Axis2D< BIN2D, DBN >::Axis2D ( )
inline

Definition at line 49 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::reset().

50  : _locked(false)
51  {
52  reset();
53  }
void reset()
Definition: Axis2D.h:96

◆ Axis2D() [2/5]

template<typename BIN2D, typename DBN>
YODA::Axis2D< BIN2D, DBN >::Axis2D ( const Edges xedges,
const Edges yedges 
)
inline

A constructor with specified x and y axis bin cuts.

Definition at line 56 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::addBins(), and YODA::Axis2D< BIN2D, DBN >::reset().

57  : _locked(false)
58  {
59  addBins(xedges, yedges);
60  reset();
61  }
void reset()
Definition: Axis2D.h:96
void addBins(const Bins &bins)
Add a vector of pre-made bins.
Definition: Axis2D.h:354

◆ Axis2D() [3/5]

template<typename BIN2D, typename DBN>
YODA::Axis2D< BIN2D, DBN >::Axis2D ( size_t  nbinsX,
const std::pair< double, double > &  rangeX,
size_t  nbinsY,
const std::pair< double, double > &  rangeY 
)
inline

Constructor accepting X/Y ranges and number of bins on each of the axis. Both axes are divided linearly.

Definition at line 65 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::addBins(), YODA::linspace(), and YODA::Axis2D< BIN2D, DBN >::reset().

67  : _locked(false)
68  {
69  addBins(linspace(nbinsX, rangeX.first, rangeX.second),
70  linspace(nbinsY, rangeY.first, rangeY.second));
71  reset();
72  }
void reset()
Definition: Axis2D.h:96
void addBins(const Bins &bins)
Add a vector of pre-made bins.
Definition: Axis2D.h:354
std::vector< double > linspace(size_t nbins, double xmin, double xmax, bool include_end=true)
Make a list of nbins + 1 values uniformly spaced between xmin and xmax inclusive. ...
Definition: MathUtils.h:253

◆ Axis2D() [4/5]

template<typename BIN2D, typename DBN>
YODA::Axis2D< BIN2D, DBN >::Axis2D ( const Bins bins)
inline

Constructor accepting a list of bins.

Definition at line 75 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::addBins(), and YODA::Axis2D< BIN2D, DBN >::reset().

76  : _locked(false)
77  {
78  addBins(bins);
79  reset();
80  }
Bins & bins()
Return the bins vector (non-const)
Definition: Axis2D.h:433
void reset()
Definition: Axis2D.h:96
void addBins(const Bins &bins)
Add a vector of pre-made bins.
Definition: Axis2D.h:354

◆ Axis2D() [5/5]

template<typename BIN2D, typename DBN>
YODA::Axis2D< BIN2D, DBN >::Axis2D ( const Bins bins,
const DBN &  totalDbn,
const Outflows outflows 
)
inline

State-setting constructor for persistency.

Definition at line 83 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::addBins().

86  : _dbn(totalDbn), _outflows(outflows),
87  _locked(false) // Does this make sense?
88  {
89  if (_outflows.size() != 8) {
90  throw Exception("Axis2D outflow containers must have exactly 8 elements");
91  }
92  addBins(bins);
93  }
Bins & bins()
Return the bins vector (non-const)
Definition: Axis2D.h:433
DBN & totalDbn()
Return the total distribution (non-const)
Definition: Axis2D.h:419
void addBins(const Bins &bins)
Add a vector of pre-made bins.
Definition: Axis2D.h:354

Member Function Documentation

◆ addBin() [1/2]

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::addBin ( EdgePair1D  xrange,
EdgePair1D  yrange 
)
inline

Add a bin, providing its x- and y- edge ranges.

Definition at line 338 of file Axis2D.h.

338  {
339  _checkUnlocked();
340  Bins newBins = _bins;
341  newBins.push_back(Bin(xrange, yrange));
342  _updateAxis(newBins);
343  }
std::vector< Bin > Bins
A vector containing 2D bins. Not used for searching.
Definition: Axis2D.h:31
BIN2D Bin
Bin type.
Definition: Axis2D.h:28

◆ addBin() [2/2]

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::addBin ( const Bin bin)
inline

Add a pre-made bin.

Definition at line 346 of file Axis2D.h.

346  {
347  _checkUnlocked();
348  Bins newBins = _bins;
349  newBins.push_back(bin);
350  _updateAxis(newBins);
351  }
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384
std::vector< Bin > Bins
A vector containing 2D bins. Not used for searching.
Definition: Axis2D.h:31

◆ addBins() [1/2]

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

Add a vector of pre-made bins.

Definition at line 354 of file Axis2D.h.

Referenced by YODA::Axis2D< BIN2D, DBN >::Axis2D().

354  {
355  if (bins.size() == 0) return;
356  _checkUnlocked();
357  Bins newBins = _bins;
358  for (const Bin& b : bins)
359  newBins.push_back(b);
360  _updateAxis(newBins);
361  }
Bins & bins()
Return the bins vector (non-const)
Definition: Axis2D.h:433
std::vector< Bin > Bins
A vector containing 2D bins. Not used for searching.
Definition: Axis2D.h:31
BIN2D Bin
Bin type.
Definition: Axis2D.h:28

◆ addBins() [2/2]

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::addBins ( const std::vector< double > &  xedges,
const std::vector< double > &  yedges 
)
inline

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

Definition at line 364 of file Axis2D.h.

364  {
365  if (xedges.size() == 0) return;
366  if (yedges.size() == 0) return;
367  _checkUnlocked();
368 
369  Bins newBins = _bins;
370  for (size_t xi = 0; xi < xedges.size()-1; xi++) {
371  for (size_t yi = 0; yi < yedges.size()-1; yi++) {
372  const std::pair<double,double> xx = std::make_pair(xedges[xi], xedges[xi+1]);
373  const std::pair<double,double> yy = std::make_pair(yedges[yi], yedges[yi+1]);
374  // std::cout << "New bin with edges: [(" << xx.first << "," << xx.second << "), " << yy.first << "," << yy.second << ")]" << std::endl;
375  newBins.push_back(Bin(xx, yy));
376  }
377  }
378 
379  _updateAxis(newBins);
380  }
std::vector< Bin > Bins
A vector containing 2D bins. Not used for searching.
Definition: Axis2D.h:31
BIN2D Bin
Bin type.
Definition: Axis2D.h:28

◆ bin() [1/2]

◆ bin() [2/2]

template<typename BIN2D, typename DBN>
const Bin& YODA::Axis2D< BIN2D, DBN >::bin ( size_t  i) const
inline

Access bin by index (const)

Definition at line 389 of file Axis2D.h.

389  {
390  return _bins[i];
391  }

◆ binAt() [1/2]

template<typename BIN2D, typename DBN>
Bin& YODA::Axis2D< BIN2D, DBN >::binAt ( double  x,
double  y 
)
inline

Get the bin containing point (x, y).

Definition at line 404 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::bin(), and YODA::Axis2D< BIN2D, DBN >::binIndexAt().

404  {
405  const int ret = binIndexAt(x, y);
406  if (ret == -1) throw RangeError("No bin found!!");
407  return bin(ret);
408  }
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384
int binIndexAt(double x, double y) const
Get the bin index of the bin containing point (x, y).
Definition: Axis2D.h:394

◆ binAt() [2/2]

template<typename BIN2D, typename DBN>
const Bin& YODA::Axis2D< BIN2D, DBN >::binAt ( double  x,
double  y 
) const
inline

Get the bin containing point (x, y) (const).

Definition at line 411 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::bin(), and YODA::Axis2D< BIN2D, DBN >::binIndexAt().

411  {
412  const int ret = binIndexAt(x, y);
413  if (ret == -1) throw RangeError("No bin found!!");
414  return bin(ret);
415  }
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384
int binIndexAt(double x, double y) const
Get the bin index of the bin containing point (x, y).
Definition: Axis2D.h:394

◆ binIndexAt()

template<typename BIN2D, typename DBN>
int YODA::Axis2D< BIN2D, DBN >::binIndexAt ( double  x,
double  y 
) const
inline

Get the bin index of the bin containing point (x, y).

Definition at line 394 of file Axis2D.h.

Referenced by YODA::Axis2D< BIN2D, DBN >::binAt().

394  {
395  size_t xi = _binSearcherX.index(x) - 1;
396  size_t yi = _binSearcherY.index(y) - 1;
397  if (xi > _nx) return -1;
398  if (yi > _ny) return -1;
399 
400  return _indexes[_index(_nx, xi, yi)];
401  }

◆ bins() [1/2]

template<typename BIN2D, typename DBN>
Bins& YODA::Axis2D< BIN2D, DBN >::bins ( )
inline

Return the bins vector (non-const)

Definition at line 433 of file Axis2D.h.

Referenced by YODA::Axis2D< BIN2D, DBN >::eraseBins(), YODA::Axis2D< BIN2D, DBN >::operator+=(), and YODA::Axis2D< BIN2D, DBN >::operator-=().

433  {
434  return _bins;
435  }

◆ bins() [2/2]

template<typename BIN2D, typename DBN>
const Bins& YODA::Axis2D< BIN2D, DBN >::bins ( ) const
inline

Return the bins vector (const)

Definition at line 438 of file Axis2D.h.

438  {
439  return _bins;
440  }

◆ eraseBin()

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::eraseBin ( size_t  i)
inline

Remove the bin at the given index. If many bins need to be removed, prefer eraseBins(vector[size_t] &) over many calls to this, as recreating the binhash is comparatively expensive.

Definition at line 187 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::numBins().

187  {
188  if (i >= numBins())
189  throw RangeError("Bin index is out of range");
190 
191  // Temporarily unlock the axis during the update
192  _bins.erase(_bins.begin() + i);
193  _updateAxis(_bins);
194  }
size_t numBins() const
Get the number of bins.
Definition: Axis2D.h:105

◆ eraseBins() [1/3]

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

Erase a rectangle of bins.

Definition at line 198 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::bin(), and YODA::Axis2D< BIN2D, DBN >::numBins().

Referenced by YODA::Axis2D< BIN2D, DBN >::eraseBins(), and YODA::Axis2D< BIN2D, DBN >::mergeBins().

198  {
199  if (from >= numBins())
200  throw RangeError("Initial bin index is out of range");
201  if (from >= numBins())
202  throw RangeError("Final bin index is out of range");
203 
204  Bin& fromBin = bin(from);
205  Bin& toBin = bin(to);
206 
207  eraseBins(std::make_pair(fromBin.xMin(), toBin.xMax()),
208  std::make_pair(fromBin.yMin(), toBin.yMax()));
209  }
void eraseBins(const size_t from, const size_t to)
Erase a rectangle of bins.
Definition: Axis2D.h:198
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384
BIN2D Bin
Bin type.
Definition: Axis2D.h:28
size_t numBins() const
Get the number of bins.
Definition: Axis2D.h:105

◆ eraseBins() [2/3]

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::eraseBins ( const std::pair< double, double > &  xrange,
const std::pair< double, double > &  yrange 
)
inline

Erase bins in an x- and y-range. Any bins which lie entirely within the region are deleted. If any part of the bin lies outside this range, the bin remains, so this has similar behaviour to select tools in vector graphics GUI packages.

Todo:
How to test this?
Todo:
Beware the specialisation problems with vector<bool>...

Definition at line 217 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::bin(), YODA::Axis2D< BIN2D, DBN >::eraseBins(), and YODA::Axis2D< BIN2D, DBN >::numBins().

219  {
220  size_t xiLow = _binSearcherX.index(xrange.first) - 1;
221  size_t xiHigh = _binSearcherX.index(xrange.second) - 1;
222 
223  size_t yiLow = _binSearcherY.index(yrange.first) - 1;
224  size_t yiHigh = _binSearcherY.index(yrange.second) - 1;
225 
227  std::vector<bool> deleteMask(numBins(), false);
228 
229  for (size_t yi = yiLow; yi < yiHigh; yi++) {
230  for (size_t xi = xiLow; xi < xiHigh; xi++) {
231  ssize_t i = _indexes[_index(_nx, xi, yi)];
232  if (i == -1 || deleteMask[i]) continue;
233  if (bin(i).fitsInside(xrange, yrange)) deleteMask[i] = true;
234  }
235  }
236 
237  // Now we just update
238  eraseBins(deleteMask);
239  }
void eraseBins(const size_t from, const size_t to)
Erase a rectangle of bins.
Definition: Axis2D.h:198
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384
size_t numBins() const
Get the number of bins.
Definition: Axis2D.h:105

◆ eraseBins() [3/3]

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::eraseBins ( const std::vector< bool > &  deleteMask)
inline

Erase using a vector<bool>, where true represents that a bin will be deleted, and false means it will be kept.

Definition at line 244 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::bins(), and YODA::Axis2D< BIN2D, DBN >::numBins().

244  {
245  Bins newBins;
246  for (size_t i = 0; i < numBins(); i++)
247  if (!deleteMask[i]) newBins.push_back(bins(i));
248  _update(newBins);
249  }
Bins & bins()
Return the bins vector (non-const)
Definition: Axis2D.h:433
std::vector< Bin > Bins
A vector containing 2D bins. Not used for searching.
Definition: Axis2D.h:31
size_t numBins() const
Get the number of bins.
Definition: Axis2D.h:105

◆ mergeBins()

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, 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 254 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::bin(), YODA::Axis2D< BIN2D, DBN >::eraseBins(), and YODA::Axis2D< BIN2D, DBN >::numBins().

254  {
255  // Correctness checking
256  if (from >= numBins())
257  throw RangeError("Initial merge index is out of range");
258  if (to >= numBins())
259  throw RangeError("Final merge index is out of range");
260  if (from > to)
261  throw RangeError("Final bin must be greater than or equal to initial bin");
262  if (_gapInRange(from, to))
263  throw RangeError("Bin ranges containing gaps cannot be merged");
264  if (from == to)
265  return; // nothing to be done
266 
267  Bin& b = bin(from);
268  for (size_t i = from + 1; i <= to; ++i)
269  b.merge(_bins[i]);
270  eraseBins(from+1, to);
271  }
void eraseBins(const size_t from, const size_t to)
Erase a rectangle of bins.
Definition: Axis2D.h:198
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384
BIN2D Bin
Bin type.
Definition: Axis2D.h:28
size_t numBins() const
Get the number of bins.
Definition: Axis2D.h:105

◆ numBins()

template<typename BIN2D, typename DBN>
size_t YODA::Axis2D< BIN2D, DBN >::numBins ( ) const
inline

Get the number of bins.

Definition at line 105 of file Axis2D.h.

Referenced by YODA::Axis2D< BIN2D, DBN >::eraseBin(), YODA::Axis2D< BIN2D, DBN >::eraseBins(), YODA::Axis2D< BIN2D, DBN >::mergeBins(), and YODA::Axis2D< BIN2D, DBN >::operator==().

105  {
106  return _bins.size();
107  }

◆ numBinsX()

template<typename BIN2D, typename DBN>
size_t YODA::Axis2D< BIN2D, DBN >::numBinsX ( ) const
inline

Get the number of bins on the x-axis. This is only sensible for perfectly regular gridded bins. For irregular binnings, this is the number of cuts that were necessary to grid the data.

Definition at line 112 of file Axis2D.h.

112  {
113  return _nx-1;
114  }

◆ numBinsY()

template<typename BIN2D, typename DBN>
size_t YODA::Axis2D< BIN2D, DBN >::numBinsY ( ) const
inline

Get the number of bins on the y-axis. This is only sensible for perfectly regular gridded bins. For irregular binnings, this is the number of cuts that were necessary to grid the data.

Definition at line 119 of file Axis2D.h.

119  {
120  return _ny-1;
121  }

◆ operator!=()

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

Non-equality operator.

Definition at line 460 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::operator==().

460  {
461  return ! operator == (other);
462  }
bool operator==(const Axis2D &other) const
Definition: Axis2D.h:448

◆ operator+=()

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

Addition operator.

Definition at line 466 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::bin(), and YODA::Axis2D< BIN2D, DBN >::bins().

466  {
467  if (*this != toAdd) {
468  throw LogicError("YODA::Axis2D: Cannot add axes with different binnings.");
469  }
470  for (size_t i = 0; i < bins().size(); ++i) {
471  bin(i) += toAdd.bin(i);
472  }
473  _dbn += toAdd._dbn;
474  return *this;
475  }
Bins & bins()
Return the bins vector (non-const)
Definition: Axis2D.h:433
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384

◆ operator-=()

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

Subtraction operator.

Definition at line 478 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::bin(), and YODA::Axis2D< BIN2D, DBN >::bins().

478  {
479  if (*this != toSubtract) {
480  throw LogicError("YODA::Axis2D: Cannot add axes with different binnings.");
481  }
482  for (size_t i = 0; i < bins().size(); ++i) {
483  bin(i) -= toSubtract.bin(i);
484  }
485  _dbn -= toSubtract._dbn;
486  return *this;
487  }
Bins & bins()
Return the bins vector (non-const)
Definition: Axis2D.h:433
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384

◆ operator==()

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

Equality operator (on binning only)

Todo:
Change as discussed below if we expose the Axis classes for direct use

Definition at line 448 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::bin(), YODA::fuzzyEquals(), YODA::Axis2D< BIN2D, DBN >::numBins(), and YODA::Axis2D< BIN2D, DBN >::xMin().

Referenced by YODA::Axis2D< BIN2D, DBN >::operator!=().

448  {
449  if (numBins() != other.numBins()) return false;
450  for (size_t i = 0; i < numBins(); i++)
451  if (!(fuzzyEquals(bin(i).xMin(), other.bin(i).xMin()) &&
452  fuzzyEquals(bin(i).xMax(), other.bin(i).xMax()) &&
453  fuzzyEquals(bin(i).yMin(), other.bin(i).yMin()) &&
454  fuzzyEquals(bin(i).yMax(), other.bin(i).yMax())))
455  return false;
456  return true;
457  }
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384
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:73
double xMin() const
Return the lowest-valued bin edge along the x-axis.
Definition: Axis2D.h:305
size_t numBins() const
Get the number of bins.
Definition: Axis2D.h:105

◆ outflow() [1/2]

template<typename BIN2D, typename DBN>
Outflow& YODA::Axis2D< BIN2D, DBN >::outflow ( int  ix,
int  iy 
)
inline

Get the outflow by x-index and y-index (non-const version)

Indices are -1 = below range, 0 = in range, +1 = above range, e.g. (+1, -1) is in the "bottom right" position by being greater than the greatest x-edge and less than the lowest y-edge.

Definition at line 134 of file Axis2D.h.

Referenced by YODA::Axis2D< BIN2D, DBN >::scaleW(), and YODA::Axis2D< BIN2D, DBN >::scaleXY().

134  {
135  return _outflows[_outflowIndex(ix, iy)];
136  }

◆ outflow() [2/2]

template<typename BIN2D, typename DBN>
const Outflow& YODA::Axis2D< BIN2D, DBN >::outflow ( int  ix,
int  iy 
) const
inline

Get the outflow by x-index and y-index (const version)

Indices are -1 = below range, 0 = in range, +1 = above range, e.g. (+1, -1) is in the "bottom right" position by being greater than the greatest x-edge and less than the lowest y-edge.

Definition at line 144 of file Axis2D.h.

144  {
145  return _outflows[_outflowIndex(ix, iy)];
146  }

◆ rebin()

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::rebin ( unsigned int  n)
inline

Rebin with the same rebinning factor n in x and y.

Definition at line 275 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::rebinXY().

275  {
276  rebinXY(n, n);
277  }
void rebinXY(unsigned int nx, unsigned int ny)
Rebin with separate rebinning factors nx, ny in x and y.
Definition: Axis2D.h:280

◆ rebinX()

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::rebinX ( unsigned int  nx)
inline

Rebin in x by factor nx.

Todo:
WRITE THIS!

Definition at line 286 of file Axis2D.h.

Referenced by YODA::Axis2D< BIN2D, DBN >::rebinXY().

286  {
288  }

◆ rebinXY()

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::rebinXY ( unsigned int  nx,
unsigned int  ny 
)
inline

Rebin with separate rebinning factors nx, ny in x and y.

Definition at line 280 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::rebinX(), and YODA::Axis2D< BIN2D, DBN >::rebinY().

Referenced by YODA::Axis2D< BIN2D, DBN >::rebin().

280  {
281  rebinX(nx);
282  rebinY(ny);
283  }
void rebinY(unsigned int ny)
Rebin in y by factor ny.
Definition: Axis2D.h:291
void rebinX(unsigned int nx)
Rebin in x by factor nx.
Definition: Axis2D.h:286

◆ rebinY()

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::rebinY ( unsigned int  ny)
inline

Rebin in y by factor ny.

Todo:
WRITE THIS!

Definition at line 291 of file Axis2D.h.

Referenced by YODA::Axis2D< BIN2D, DBN >::rebinXY().

291  {
293  }

◆ reset()

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::reset ( )
inline

Definition at line 96 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::bin().

Referenced by YODA::Axis2D< BIN2D, DBN >::Axis2D().

96  {
97  _dbn.reset();
98  _outflows.assign(8, Outflow());
99  for (Bin& bin : _bins) bin.reset();
100  _locked = false;
101  }
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384
BIN2D Bin
Bin type.
Definition: Axis2D.h:28
std::vector< DBN > Outflow
Definition: Axis2D.h:40

◆ scaleW()

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::scaleW ( double  scalefactor)
inline

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

Definition at line 173 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::bin(), and YODA::Axis2D< BIN2D, DBN >::outflow().

173  {
174  _dbn.scaleW(scalefactor);
175  for (Outflow& outflow : _outflows)
176  for (DBN& dbn : outflow)
177  dbn.scaleW(scalefactor);
178  for (Bin& bin : _bins)
179  bin.scaleW(scalefactor);
180  _updateAxis(_bins);
181  }
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384
BIN2D Bin
Bin type.
Definition: Axis2D.h:28
std::vector< DBN > Outflow
Definition: Axis2D.h:40
Outflow & outflow(int ix, int iy)
Get the outflow by x-index and y-index (non-const version)
Definition: Axis2D.h:134

◆ scaleX()

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::scaleX ( double  xscale)
inline

Scale each bin as if the entire x-axis had been scaled by this factor.

Definition at line 149 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::scaleXY().

149  {
150  scaleXY(xscale, 1.0);
151  }
void scaleXY(double sx, double sy)
Definition: Axis2D.h:160

◆ scaleXY()

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::scaleXY ( double  sx,
double  sy 
)
inline

Scale each bin as if the entire x and y-axes had been scaled by their respective factors.

Definition at line 160 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::outflow().

Referenced by YODA::Axis2D< BIN2D, DBN >::scaleX(), and YODA::Axis2D< BIN2D, DBN >::scaleY().

160  {
161  _dbn.scaleXY(sx, sy);
162  for (Outflow& outflow : _outflows)
163  for (DBN& dbn : outflow)
164  dbn.scaleXY(sx, sy);
165  for (Bin& b : _bins)
166  b.scaleXY(sx, sy);
167  _updateAxis(_bins);
168  }
BIN2D Bin
Bin type.
Definition: Axis2D.h:28
std::vector< DBN > Outflow
Definition: Axis2D.h:40
Outflow & outflow(int ix, int iy)
Get the outflow by x-index and y-index (non-const version)
Definition: Axis2D.h:134

◆ scaleY()

template<typename BIN2D, typename DBN>
void YODA::Axis2D< BIN2D, DBN >::scaleY ( double  yscale)
inline

Scale each bin as if the entire y-axis had been scaled by this factor.

Definition at line 154 of file Axis2D.h.

References YODA::Axis2D< BIN2D, DBN >::scaleXY().

154  {
155  scaleXY(1.0, yscale);
156  }
void scaleXY(double sx, double sy)
Definition: Axis2D.h:160

◆ setTotalDbn()

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

Set the total distribution: CAREFUL!

Definition at line 427 of file Axis2D.h.

427  {
428  _dbn = dbn;
429  }

◆ totalDbn() [1/2]

template<typename BIN2D, typename DBN>
DBN& YODA::Axis2D< BIN2D, DBN >::totalDbn ( )
inline

Return the total distribution (non-const)

Definition at line 419 of file Axis2D.h.

419  {
420  return _dbn;
421  }

◆ totalDbn() [2/2]

template<typename BIN2D, typename DBN>
const DBN& YODA::Axis2D< BIN2D, DBN >::totalDbn ( ) const
inline

Return the total distribution (const)

Definition at line 423 of file Axis2D.h.

423  {
424  return _dbn;
425  }

◆ xEdges()

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

Return all the NbinX+1 bin edges on the x-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 322 of file Axis2D.h.

322  {
323  std::vector<double> rtn(_binSearcherX.edges().begin()+1, _binSearcherX.edges().end()-1);
324  return rtn;
325  }

◆ xMax()

template<typename BIN2D, typename DBN>
double YODA::Axis2D< BIN2D, DBN >::xMax ( ) const
inline

Return the highest-valued bin edge along the x-axis.

Definition at line 308 of file Axis2D.h.

308 { return _xRange.second; }

◆ xMin()

template<typename BIN2D, typename DBN>
double YODA::Axis2D< BIN2D, DBN >::xMin ( ) const
inline

Return the lowest-valued bin edge along the x-axis.

Todo:
Add xMins, xMaxs, xMids, xFoci, and y-versions

Definition at line 305 of file Axis2D.h.

Referenced by YODA::Axis2D< BIN2D, DBN >::operator==().

305 { return _xRange.first; }

◆ yEdges()

template<typename BIN2D, typename DBN>
std::vector<double> YODA::Axis2D< BIN2D, DBN >::yEdges ( ) const
inline

Return all the NbinY+1 bin edges on the y-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 331 of file Axis2D.h.

331  {
332  std::vector<double> rtn(_binSearcherY.edges().begin()+1, _binSearcherY.edges().end()-1);
333  return rtn;
334  }

◆ yMax()

template<typename BIN2D, typename DBN>
double YODA::Axis2D< BIN2D, DBN >::yMax ( ) const
inline

Return the highest-valued bin edge along the y-axis.

Definition at line 315 of file Axis2D.h.

315 { return _yRange.second; }

◆ yMin()

template<typename BIN2D, typename DBN>
double YODA::Axis2D< BIN2D, DBN >::yMin ( ) const
inline

Return the lowest-valued bin edge along the y-axis.

Definition at line 312 of file Axis2D.h.

312 { return _yRange.first; }

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