BufferedHistogram2D.cxx
Go to the documentation of this file.
2 
3 using namespace WireCell;
4 using namespace std;
5 
6 
7 BufferedHistogram2D::BufferedHistogram2D(double xbinsize, double ybinsize,
8  double xmin, double ymin)
9  : m_xmin(xmin), m_ymin(ymin), m_xbinsize(xbinsize), m_ybinsize(ybinsize)
10 {
11 }
12 
14 {
15  return xmin() + m_xbinsize * m_xbindeque.size();
16 }
18 {
19  return ymin() + m_ybinsize * ysize();
20 }
22 {
23  int imax = 0;
24  for (auto v: m_xbindeque) {
25  imax = std::max((int)v.size(), imax);
26  }
27  return imax;
28 }
29 
30 
31 bool BufferedHistogram2D::fill(double x, double y, double v)
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 }
53 
54 std::vector<double> BufferedHistogram2D::popx()
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 }
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.
BufferedHistogram2D(double xbinsize=1.0, double ybinsize=1.0, double xmin=0.0, double ymin=0.0)
STL namespace.
double y
static int max(int a, int b)
Definition: Main.h:22
list x
Definition: train.py:276