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

#include <BufferedHistogram2D.h>

Public Member Functions

 BufferedHistogram2D (double xbinsize=1.0, double ybinsize=1.0, double xmin=0.0, double ymin=0.0)
 
bool fill (double x, double y, double v=1.0)
 Add v to the bin holding x,y. Return false if point is out of bounds. More...
 
std::vector< double > popx ()
 
int size () const
 popy is not yet implemented. More...
 
int xsize () const
 
int ysize () const
 
double xmin () const
 
double ymin () const
 
double xmax () const
 
double ymax () const
 
double xbinsize () const
 
double ybinsize () const
 

Private Types

typedef std::vector< double > XBin
 
typedef std::deque< XBinXBinDeque
 

Private Attributes

double m_xmin
 
double m_ymin
 
double m_xbinsize
 
double m_ybinsize
 
XBinDeque m_xbindeque
 

Detailed Description

A 2D histogram which can expand its range based on filling and have its edge sliced off.

Definition at line 12 of file BufferedHistogram2D.h.

Member Typedef Documentation

Definition at line 16 of file BufferedHistogram2D.h.

typedef std::deque<XBin> WireCell::BufferedHistogram2D::XBinDeque
private

Definition at line 17 of file BufferedHistogram2D.h.

Constructor & Destructor Documentation

BufferedHistogram2D::BufferedHistogram2D ( double  xbinsize = 1.0,
double  ybinsize = 1.0,
double  xmin = 0.0,
double  ymin = 0.0 
)

Create a buffered 2d histogram with lower corner at xmin, ymin and with bins of given sizes.

Definition at line 7 of file BufferedHistogram2D.cxx.

Member Function Documentation

bool BufferedHistogram2D::fill ( double  x,
double  y,
double  v = 1.0 
)

Add v to the bin holding x,y. Return false if point is out of bounds.

Definition at line 31 of file BufferedHistogram2D.cxx.

32 {
33  int ybin = (y - m_ymin)/m_ybinsize;
34  if (ybin < 0) {
35  return false;
36  }
37  int xbin = (x - m_xmin)/m_xbinsize;
38  if (xbin < 0) {
39  return false;
40  }
41 
42  if ((int)m_xbindeque.size() < xbin+1) {
43  m_xbindeque.resize(xbin+1);
44  }
45  XBin& vec = m_xbindeque[xbin];
46  if ((int)vec.size() < ybin+1) {
47  vec.resize(ybin+1, 0.0);
48  }
49  vec[ybin] += v;
50 
51  return true;
52 }
double y
list x
Definition: train.py:276
std::vector< double > BufferedHistogram2D::popx ( )

Slice off the lowest X bin and return it as a vector. Note, the zeroth element of the vector corresponds to the bin starting at ymin but the length of vector may not represent the global ymax.

Definition at line 54 of file BufferedHistogram2D.cxx.

55 {
56  std::vector<double> ret;
57 
58  if (!m_xbindeque.size()) { return ret; }
59 
60  ret = m_xbindeque.front();
61  m_xbindeque.pop_front();
62  m_xmin += m_xbinsize;
63  return ret;
64 }
int WireCell::BufferedHistogram2D::size ( void  ) const
inline

popy is not yet implemented.

Definition at line 39 of file BufferedHistogram2D.h.

39 { return m_xbindeque.size(); }
double WireCell::BufferedHistogram2D::xbinsize ( ) const
inline

Definition at line 48 of file BufferedHistogram2D.h.

double BufferedHistogram2D::xmax ( ) const

Definition at line 13 of file BufferedHistogram2D.cxx.

double WireCell::BufferedHistogram2D::xmin ( ) const
inline

Definition at line 44 of file BufferedHistogram2D.h.

int WireCell::BufferedHistogram2D::xsize ( ) const
inline

Definition at line 40 of file BufferedHistogram2D.h.

40 { return size(); }
int size() const
popy is not yet implemented.
double WireCell::BufferedHistogram2D::ybinsize ( ) const
inline

Definition at line 49 of file BufferedHistogram2D.h.

double BufferedHistogram2D::ymax ( ) const

Definition at line 17 of file BufferedHistogram2D.cxx.

double WireCell::BufferedHistogram2D::ymin ( ) const
inline

Definition at line 45 of file BufferedHistogram2D.h.

int BufferedHistogram2D::ysize ( ) const

Definition at line 21 of file BufferedHistogram2D.cxx.

22 {
23  int imax = 0;
24  for (auto v: m_xbindeque) {
25  imax = std::max((int)v.size(), imax);
26  }
27  return imax;
28 }
static int max(int a, int b)

Member Data Documentation

XBinDeque WireCell::BufferedHistogram2D::m_xbindeque
private

Definition at line 18 of file BufferedHistogram2D.h.

double WireCell::BufferedHistogram2D::m_xbinsize
private

Definition at line 13 of file BufferedHistogram2D.h.

double WireCell::BufferedHistogram2D::m_xmin
private

Definition at line 13 of file BufferedHistogram2D.h.

double WireCell::BufferedHistogram2D::m_ybinsize
private

Definition at line 13 of file BufferedHistogram2D.h.

double WireCell::BufferedHistogram2D::m_ymin
private

Definition at line 13 of file BufferedHistogram2D.h.


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