Public Member Functions | Private Attributes | List of all members
WireCell::Binning Class Reference

#include <Binning.h>

Public Member Functions

 Binning (int nbins, double minval, double maxval)
 
 Binning ()
 
void set (int nbins, double minval, double maxval)
 
int nbins () const
 
double min () const
 
double max () const
 
double span () const
 Return the max-min. More...
 
std::pair< double, double > range () const
 
std::pair< int, int > irange () const
 
double binsize () const
 
int bin (double val) const
 
double center (int ind) const
 
int edge_index (double val) const
 
double edge (int ind) const
 
bool inside (double val) const
 
bool inbounds (int bin) const
 Return true if bin is in bounds. More...
 
std::pair< int, int > sample_bin_range (double minval, double maxval) const
 

Private Attributes

int m_nbins
 
double m_minval
 
double m_maxval
 
double m_binsize
 

Detailed Description

A binning is a uniform discretization of a linear space.

This class largely provides methods that give semantic labels to various calculations related to a binned region.

Definition at line 15 of file Binning.h.

Constructor & Destructor Documentation

WireCell::Binning::Binning ( int  nbins,
double  minval,
double  maxval 
)
inline

Create a binning

Parameters
nbinsgives the number of uniform, discrete separation between bounds.
minvalgives the lower bound of the linear space (low edge of bin 0)
maxvalgives the upper bound of the linear space (high edge of bin nbins-1)

Definition at line 26 of file Binning.h.

27  : m_nbins(0), m_minval(0), m_maxval(0), m_binsize(0)
28  { set(nbins, minval, maxval); }
double m_maxval
Definition: Binning.h:18
double m_minval
Definition: Binning.h:18
int nbins() const
Definition: Binning.h:42
double m_binsize
Definition: Binning.h:18
WireCell::Binning::Binning ( )
inline

Definition at line 29 of file Binning.h.

30  : m_nbins(0), m_minval(0), m_maxval(0), m_binsize(0)
31  { }
double m_maxval
Definition: Binning.h:18
double m_minval
Definition: Binning.h:18
double m_binsize
Definition: Binning.h:18

Member Function Documentation

int WireCell::Binning::bin ( double  val) const
inline

Return the bin containing value. If val is in range, return value is [0,nbins-1] but no range checking is performed.

Definition at line 80 of file Binning.h.

double WireCell::Binning::binsize ( ) const
inline

Definition at line 73 of file Binning.h.

73  {
74  return m_binsize;
75  }
double m_binsize
Definition: Binning.h:18
double WireCell::Binning::center ( int  ind) const
inline

Return the center value of given bin. Range checking is not done.

Definition at line 86 of file Binning.h.

86  {
87  return m_minval + (ind+0.5)*m_binsize;
88  }
double m_minval
Definition: Binning.h:18
double m_binsize
Definition: Binning.h:18
double WireCell::Binning::edge ( int  ind) const
inline

Return the position of the given bin edge. Range checking is not done.

Definition at line 99 of file Binning.h.

99  {
100  return m_minval + ind*m_binsize;
101  }
double m_minval
Definition: Binning.h:18
double m_binsize
Definition: Binning.h:18
int WireCell::Binning::edge_index ( double  val) const
inline

Return the edge, nominally in [0,nbins] closest to the given value. Range checking is not done so returned edge may be outside of range.

Definition at line 93 of file Binning.h.

93  {
94  return int(round((val-m_minval)/m_binsize));
95  }
double m_minval
Definition: Binning.h:18
double m_binsize
Definition: Binning.h:18
bool WireCell::Binning::inbounds ( int  bin) const
inline

Return true if bin is in bounds.

Definition at line 110 of file Binning.h.

110  {
111  return 0 <= bin && bin < m_nbins;
112  }
int bin(double val) const
Definition: Binning.h:80
bool WireCell::Binning::inside ( double  val) const
inline

Return true value is in range. Range is considered half open. Ig, edge(nbins) is not inside range.

Definition at line 105 of file Binning.h.

105  {
106  return m_minval <= val && val < m_maxval;
107  }
double m_maxval
Definition: Binning.h:18
double m_minval
Definition: Binning.h:18
std::pair<int, int> WireCell::Binning::irange ( ) const
inline

Definition at line 68 of file Binning.h.

68  {
69  return std::make_pair(0, m_nbins);
70  }
double WireCell::Binning::max ( void  ) const
inline

Definition at line 52 of file Binning.h.

52  {
53  return m_maxval;
54  }
double m_maxval
Definition: Binning.h:18
double WireCell::Binning::min ( void  ) const
inline

Definition at line 47 of file Binning.h.

47  {
48  return m_minval;
49  }
double m_minval
Definition: Binning.h:18
int WireCell::Binning::nbins ( ) const
inline

Definition at line 42 of file Binning.h.

42  {
43  return m_nbins;
44  }
std::pair<double, double> WireCell::Binning::range ( ) const
inline

Definition at line 62 of file Binning.h.

62  {
63  return std::make_pair(m_minval, m_maxval);
64  }
double m_maxval
Definition: Binning.h:18
double m_minval
Definition: Binning.h:18
std::pair<int,int> WireCell::Binning::sample_bin_range ( double  minval,
double  maxval 
) const
inline

Return half-open bin range which covers the range of values. Bounds are forced to return values in [0,nbins].

Definition at line 116 of file Binning.h.

116  {
117  return std::make_pair(std::max(bin(minval), 0),
118  std::min(bin(maxval)+1, m_nbins));
119  }
int bin(double val) const
Definition: Binning.h:80
static int max(int a, int b)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
void WireCell::Binning::set ( int  nbins,
double  minval,
double  maxval 
)
inline

Definition at line 34 of file Binning.h.

34  {
35  m_nbins = nbins;
36  m_minval = minval;
37  m_maxval = maxval;
38  m_binsize = ((maxval-minval)/nbins);
39  }
double m_maxval
Definition: Binning.h:18
double m_minval
Definition: Binning.h:18
int nbins() const
Definition: Binning.h:42
double m_binsize
Definition: Binning.h:18
double WireCell::Binning::span ( ) const
inline

Return the max-min.

Definition at line 57 of file Binning.h.

57  {
58  return m_maxval - m_minval;
59  }
double m_maxval
Definition: Binning.h:18
double m_minval
Definition: Binning.h:18

Member Data Documentation

double WireCell::Binning::m_binsize
private

Definition at line 18 of file Binning.h.

double WireCell::Binning::m_maxval
private

Definition at line 18 of file Binning.h.

double WireCell::Binning::m_minval
private

Definition at line 18 of file Binning.h.

int WireCell::Binning::m_nbins
private

Definition at line 17 of file Binning.h.


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