YODA is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.3.1
HistoBin2D.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of YODA -- Yet more Objects for Data Analysis
4 // Copyright (C) 2008-2015 The YODA collaboration (see AUTHORS for details)
5 //
6 #ifndef YODA_HistoBin2D_h
7 #define YODA_HistoBin2D_h
8 
9 #include "YODA/Bin2D.h"
10 #include "YODA/Dbn2D.h"
11 #include "YODA/Exceptions.h"
12 
13 namespace YODA {
14 
15 
21  class HistoBin2D : public Bin2D<Dbn2D> {
22  public:
23 
25 
26 
28  HistoBin2D(double xmin, double xmax, double ymin, double ymax)
29  : Bin2D<Dbn2D>(std::make_pair(xmin, xmax), std::make_pair(ymin, ymax))
30  { }
31 
33  HistoBin2D(const std::pair<double,double>& xedges,
34  const std::pair<double,double>& yedges)
35  : Bin2D<Dbn2D>(xedges, yedges)
36  { }
37 
41  HistoBin2D(const std::pair<double, double>& xedges,
42  const std::pair<double, double>& yedges, const Dbn2D& dbn)
43  : Bin2D<Dbn2D>(xedges, yedges, dbn)
44  { }
45 
48  : Bin2D<Dbn2D>(pb)
49  { }
50 
54  return *this;
55  }
56 
58 
59 
61 
62 
66  void fill(double x, double y, double weight=1.0) {
67  _dbn.fill(x, y, weight);
68  }
69 
73  void fill(std::pair<double,double> coords, double weight=1.0) {
74  fill(coords.first, coords.second, weight);
75  }
76 
80  void fillBin(double weight=1.0) {
81  fill(xyMid(), weight);
82  }
83 
85  void reset() {
87  }
88 
90 
91 
93 
94 
96  double volume() const {
97  return sumW();
98  }
99 
101  double volumeErr() const {
102  return sqrt(sumW2());
103  }
104 
106  double height() const {
107  return volume()/(xWidth()*yWidth());
108  }
109 
111  double heightErr() const {
112  return volumeErr()/(xWidth()*yWidth());
113  }
114 
116  double relErr() const {
117  return sumW2() != 0 ? sqrt(sumW2()) / sumW() : 0;
118  }
119 
121 
122 
124 
125 
126  // /// @brief Transformer taking x as the primary axis of ProfileBin1D
127  // ///
128  // /// @todo Need to think about the name, and clarify what "primary axis" means
129  // ProfileBin1D transformX() {
130  // ProfileBin1D ret(std::make_pair(xMin(), xMax()), Dbn2D(_dbn));
131  // return ret;
132  // }
133 
134  // /// @brief Transformer taking y as the primary axis of ProfileBin1D
135  // ///
136  // /// @todo Need to think about the name, and clarify what "primary axis" means
137  // ProfileBin1D transformY() {
138  // Dbn2D dbn = _dbn; dbn.flipXY();
139  // ProfileBin1D ret(std::make_pair(yMin(), yMax()), Dbn2D(dbn));
140  // return ret;
141  // }
142 
144  };
145 
146 
148  inline HistoBin2D operator + (const HistoBin2D& a, const HistoBin2D& b) {
149  HistoBin2D rtn(a);
150  rtn += b;
151  return rtn;
152  }
153 
154 
156  inline HistoBin2D operator - (const HistoBin2D& a, const HistoBin2D& b) {
157  HistoBin2D rtn(a);
158  rtn -= b;
159  return rtn;
160  }
161 
162 
163 }
164 
165 #endif
double volumeErr() const
Error on volume.
Definition: HistoBin2D.h:101
Dbn2D & dbn()
Statistical distribution in this bin (non-const)
Definition: Bin2D.h:276
void reset()
A reset function.
Definition: HistoBin2D.h:85
HistoBin2D(const HistoBin2D &pb)
Copy constructor.
Definition: HistoBin2D.h:47
Bin2D< DBN > & operator=(const Bin2D< DBN > &b)
Copy assignment.
Definition: Bin2D.h:83
Axis1D< BIN1D, DBN > operator-(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Subtract the statistics on two axis.
Definition: Axis1D.h:494
double sumW() const
The sum of weights.
Definition: Bin2D.h:296
void fillBin(double weight=1.0)
Definition: HistoBin2D.h:80
A 2D distribution.
Definition: Dbn2D.h:16
std::pair< double, double > xyMid() const
The geometric centre of the bin.
Definition: Bin2D.h:173
double sumW2() const
The sum of weights squared.
Definition: Bin2D.h:301
HistoBin2D & operator=(const HistoBin2D &hb)
Copy assignment.
Definition: HistoBin2D.h:52
Axis1D< BIN1D, DBN > operator+(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Add the statistics on two axes.
Definition: Axis1D.h:486
double height() const
The height of a bin.
Definition: HistoBin2D.h:106
double xWidth() const
Width of the bin in x.
Definition: Bin2D.h:179
double relErr() const
The relative size of the error (same for either volume or height errors)
Definition: HistoBin2D.h:116
void fill(std::pair< double, double > coords, double weight=1.0)
Definition: HistoBin2D.h:73
A Bin2D specialised for handling histogram-type information.
Definition: HistoBin2D.h:21
HistoBin2D(const std::pair< double, double > &xedges, const std::pair< double, double > &yedges)
Constructor accepting a set of all edges of a bin.
Definition: HistoBin2D.h:33
virtual void reset()
Reset this bin.
Definition: Bin2D.h:97
double volume() const
The volume of a bin.
Definition: HistoBin2D.h:96
A generic 2D bin type.
Definition: Bin2D.h:25
double heightErr() const
Error on height.
Definition: HistoBin2D.h:111
HistoBin2D(const std::pair< double, double > &xedges, const std::pair< double, double > &yedges, const Dbn2D &dbn)
Make a bin with all the components of a fill history.
Definition: HistoBin2D.h:41
double yWidth() const
Width of the bin in y.
Definition: Bin2D.h:184
HistoBin2D(double xmin, double xmax, double ymin, double ymax)
Make a new, empty bin with two pairs of edges.
Definition: HistoBin2D.h:28
void fill(double x, double y, double weight=1.0)
Definition: HistoBin2D.h:66