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

2D bin container More...

#include <Axis2D.h>

Public Types

typedef BIN2D Bin
 Typedefs. 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...
 
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

Typedefs.

Bin type

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

◆ 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  }
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 reset()
Definition: Axis2D.h:96
void addBins(const Bins &bins)
Add a vector of pre-made bins.
Definition: Axis2D.h:352

◆ 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:352

◆ 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:352

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 336 of file Axis2D.h.

336  {
337  _checkUnlocked();
338  Bins newBins = _bins;
339  newBins.push_back(Bin(xrange, yrange));
340  _updateAxis(newBins);
341  }
std::vector< Bin > Bins
A vector containing 2D bins. Not used for searching.
Definition: Axis2D.h:31
BIN2D Bin
Typedefs.
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 344 of file Axis2D.h.

344  {
345  _checkUnlocked();
346  Bins newBins = _bins;
347  newBins.push_back(bin);
348  _updateAxis(newBins);
349  }
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.

Todo:
Reinstate when C++11 allowed in API

Definition at line 352 of file Axis2D.h.

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

352  {
353  if (bins.size() == 0) return;
354  _checkUnlocked();
355  Bins newBins = _bins;
357  // for (const Bin& b : bins)
358  // newBins.push_back(b);
359  for (size_t ib = 0; ib < bins.size(); ++ib) newBins.push_back(bins[ib]);
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

◆ 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
Typedefs.
Definition: Axis2D.h:28

◆ bin() [1/2]

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

◆ 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 207 of file Axis2D.h.

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

207  {
208  if (i >= numBins())
209  throw RangeError("Bin index is out of range");
210 
211  // Temporarily unlock the axis during the update
212  _bins.erase(_bins.begin() + i);
213  _updateAxis(_bins);
214  }
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 218 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().

218  {
219  if (from >= numBins())
220  throw RangeError("Initial bin index is out of range");
221  if (from >= numBins())
222  throw RangeError("Final bin index is out of range");
223 
224  Bin& fromBin = bin(from);
225  Bin& toBin = bin(to);
226 
227  eraseBins(std::make_pair(fromBin.xMin(), toBin.xMax()),
228  std::make_pair(fromBin.yMin(), toBin.yMax()));
229  }
void eraseBins(const size_t from, const size_t to)
Erase a rectangle of bins.
Definition: Axis2D.h:218
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384
BIN2D Bin
Typedefs.
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 237 of file Axis2D.h.

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

239  {
240  size_t xiLow = _binSearcherX.index(xrange.first) - 1;
241  size_t xiHigh = _binSearcherX.index(xrange.second) - 1;
242 
243  size_t yiLow = _binSearcherY.index(yrange.first) - 1;
244  size_t yiHigh = _binSearcherY.index(yrange.second) - 1;
245 
247  std::vector<bool> deleteMask(numBins(), false);
248 
249  for (size_t yi = yiLow; yi < yiHigh; yi++) {
250  for (size_t xi = xiLow; xi < xiHigh; xi++) {
251  ssize_t i = _indexes[_index(_nx, xi, yi)];
252  if (i == -1 || deleteMask[i]) continue;
253  if (bin(i).fitsInside(xrange, yrange)) deleteMask[i] = true;
254  }
255  }
256 
257  // Now we just update
258  eraseBins(deleteMask);
259  }
void eraseBins(const size_t from, const size_t to)
Erase a rectangle of bins.
Definition: Axis2D.h:218
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 264 of file Axis2D.h.

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

264  {
265  Bins newBins;
266  for (size_t i = 0; i < numBins(); i++)
267  if (!deleteMask[i]) newBins.push_back(bins(i));
268  _update(newBins);
269  }
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 274 of file Axis2D.h.

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

274  {
275  // Correctness checking
276  if (from >= numBins())
277  throw RangeError("Initial merge index is out of range");
278  if (to >= numBins())
279  throw RangeError("Final merge index is out of range");
280  if (from > to)
281  throw RangeError("Final bin must be greater than or equal to initial bin");
282  if (_gapInRange(from, to))
283  throw RangeError("Bin ranges containing gaps cannot be merged");
284  if (from == to)
285  return; // nothing to be done
286 
287  Bin& b = bin(from);
288  for (size_t i = from + 1; i <= to; ++i)
289  b.merge(_bins[i]);
290  eraseBins(from+1, to);
291  }
void eraseBins(const size_t from, const size_t to)
Erase a rectangle of bins.
Definition: Axis2D.h:218
Bin & bin(size_t i)
Access bin by index.
Definition: Axis2D.h:384
BIN2D Bin
Typedefs.
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;
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;
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:72
double xMin() const
Return the lowest-valued bin edge along the x-axis.
Definition: Axis2D.h:322
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 295 of file Axis2D.h.

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

295  {
296  rebinXY(n, n);
297  }
void rebinXY(unsigned int nx, unsigned int ny)
Rebin with separate rebinning factors nx, ny in x and y.
Definition: Axis2D.h:300

◆ 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 306 of file Axis2D.h.

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

306  {
308  }

◆ 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 300 of file Axis2D.h.

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

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

300  {
301  rebinX(nx);
302  rebinY(ny);
303  }
void rebinY(unsigned int ny)
Rebin in y by factor ny.
Definition: Axis2D.h:311
void rebinX(unsigned int nx)
Rebin in x by factor nx.
Definition: Axis2D.h:306

◆ 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 311 of file Axis2D.h.

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

311  {
313  }

◆ 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
Typedefs.
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.

Todo:
Reinstate when C++11 allowed in API
Todo:
Reinstate when C++11 allowed in API

Definition at line 183 of file Axis2D.h.

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

183  {
184  _dbn.scaleW(scalefactor);
186  // for (Outflow& outflow : _outflows)
187  // for (DBN& dbn : outflow)
188  // dbn.scaleW(scalefactor);
189  for (size_t io = 0; io < _outflows.size(); ++io) {
190  Outflow& outflow = _outflows[io];
191  for (size_t id = 0; id < outflow.size(); ++id) {
192  DBN& dbn = outflow[id];
193  dbn.scaleW(scalefactor);
194  }
195  }
197  // for (Bin& bin : _bins)
198  // bin.scaleW(scalefactor);
199  for (size_t ib = 0; ib < _bins.size(); ++ib) _bins[ib].scaleW(scalefactor);
200  _updateAxis(_bins);
201  }
void scaleW(double scalefactor)
Definition: Axis2D.h:183
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.

Todo:
Reinstate when C++11 allowed in API
Todo:
Reinstate when C++11 allowed in API

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);
163  // for (Outflow& outflow : _outflows)
164  // for (DBN& dbn : outflow)
165  // dbn.scaleXY(sx, sy);
166  for (size_t io = 0; io < _outflows.size(); ++io) {
167  Outflow& outflow = _outflows[io];
168  for (size_t id = 0; id < outflow.size(); ++id) {
169  DBN& dbn = outflow[id];
170  dbn.scaleXY(sx, sy);
171  }
172  }
174  // for (Bin& bin : _bins)
175  // bin.scaleXY(sx, sy);
176  for (size_t ib = 0; ib < _bins.size(); ++ib) _bins[ib].scaleXY(sx, sy);
177  _updateAxis(_bins);
178  }
void scaleXY(double sx, double sy)
Definition: Axis2D.h:160
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  }

◆ 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 325 of file Axis2D.h.

325 { 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.

Definition at line 322 of file Axis2D.h.

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

322 { return _xRange.first; }

◆ 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 332 of file Axis2D.h.

332 { 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 329 of file Axis2D.h.

329 { return _yRange.first; }

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