yoda is hosted by Hepforge, IPPP Durham
 YODA - Yet more Objects for Data Analysis  1.7.2
HistoBin1D.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-2017 The YODA collaboration (see AUTHORS for details)
5 //
6 #ifndef YODA_HistoBin1D_h
7 #define YODA_HistoBin1D_h
8
9 #include "YODA/Bin1D.h"
10 #include "YODA/Dbn1D.h"
11 #include "YODA/Exceptions.h"
12
13 namespace YODA {
14
15
21  class HistoBin1D : public Bin1D<Dbn1D> {
22  public:
23
25
26
28  HistoBin1D(double lowedge, double highedge)
29  : Bin1D<Dbn1D>(std::make_pair(lowedge, highedge))
30  { }
31
32
34  HistoBin1D(const std::pair<double,double>& edges)
35  : Bin1D<Dbn1D>(edges)
36  { }
37
38
42  HistoBin1D(std::pair<double, double> edges, const Dbn1D& dbnx)
43  : Bin1D<Dbn1D>(edges, dbnx)
44  { }
45
46
49  : Bin1D<Dbn1D>(hb)
50  { }
51
52
56  return *this;
57  }
58
60
61
62  public:
63
65
66
67
68
72  void fill(double x, double weight=1.0, double fraction=1.0) {
73  _dbn.fill(x, weight, fraction);
74  }
75
79  void fillBin(double weight=1.0, double fraction=1.0) {
80  fill(xMid(), weight, fraction);
81  }
82
84
85
86  public:
87
89
90
93  double area() const {
94  return sumW();
95  }
96
98  double height() const {
99  return area() / xWidth();
100  }
101
103
104
106
107
110  double areaErr() const {
111  return sqrt(sumW2());
112  }
113
116  double heightErr() const {
117  return areaErr() / xWidth();
118  }
119
121  double relErr() const {
123  return sumW2() != 0 ? sqrt(sumW2()) / sumW() : 0;
124  }
125
127
128
129  public:
130
134  }
135
137  HistoBin1D& operator -= (const HistoBin1D& toSubtract) {
138  return subtract(toSubtract);
139  }
140
141
142  protected:
143
145  HistoBin1D& add(const HistoBin1D& hb) {
147  return *this;
148  }
149
153  return *this;
154  }
155
156  };
157
158
160  inline HistoBin1D operator + (const HistoBin1D& a, const HistoBin1D& b) {
161  HistoBin1D rtn(a);
162  rtn += b;
163  return rtn;
164  }
165
167  inline HistoBin1D operator - (const HistoBin1D& a, const HistoBin1D& b) {
168  HistoBin1D rtn(a);
169  rtn -= b;
170  return rtn;
171  }
172
173
174 }
175
176 #endif
Bin1D & operator=(const Bin1D< DBN > &b)
Copy assignment.
Definition: Bin1D.h:73
void fillBin(double weight=1.0, double fraction=1.0)
Definition: HistoBin1D.h:79
Axis1D< BIN1D, DBN > operator-(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Subtract the statistics on two axis.
Definition: Axis1D.h:597
STL namespace.
double xWidth() const
Separation of low and high edges, i.e. high-low.
Definition: Bin1D.h:144
double heightErr() const
Definition: HistoBin1D.h:116
A generic 1D bin type.
Definition: Bin1D.h:27
A Bin1D specialised for handling histogram-type information.
Definition: HistoBin1D.h:21
HistoBin1D(const std::pair< double, double > &edges)
Make a new, empty bin with a pair of edges.
Definition: HistoBin1D.h:34
Add two bins (for use by Histo1D).
Definition: HistoBin1D.h:132
double sumW2() const
The sum of weights squared.
Definition: Bin1D.h:223
double relErr() const
The relative size of the error (same for either area or height errors)
Definition: HistoBin1D.h:121
double xMid() const
Geometric centre of the bin, i.e. high+low/2.0.
Definition: Bin1D.h:136
HistoBin1D & subtract(const HistoBin1D &hb)
Subtract one bin from another (internal, explicitly named version)
Definition: HistoBin1D.h:151
HistoBin1D(double lowedge, double highedge)
Make a new, empty bin with a pair of edges.
Definition: HistoBin1D.h:28
Axis1D< BIN1D, DBN > operator+(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Add the statistics on two axes.
Definition: Axis1D.h:589
HistoBin1D & operator=(const HistoBin1D &hb)
Copy assignment.
Definition: HistoBin1D.h:54
Bin1D< DBN > & add(const Bin1D< DBN > &b)
Definition: Bin1D.h:281
Bin1D< DBN > & subtract(const Bin1D< DBN > &b)
Definition: Bin1D.h:295
double area() const
Definition: HistoBin1D.h:93
double areaErr() const
Definition: HistoBin1D.h:110
HistoBin1D & operator-=(const HistoBin1D &toSubtract)
Subtract two bins.
Definition: HistoBin1D.h:137
double height() const
The height is defined as area/width.
Definition: HistoBin1D.h:98
double sumW() const
The sum of weights.
Definition: Bin1D.h:218
HistoBin1D(const HistoBin1D &hb)
Copy constructor.
Definition: HistoBin1D.h:48
HistoBin1D(std::pair< double, double > edges, const Dbn1D &dbnx)
Make a bin with all the components of a fill history.
Definition: HistoBin1D.h:42
void fill(double x, double weight=1.0, double fraction=1.0)
Definition: HistoBin1D.h:72
A 1D distribution.
Definition: Dbn1D.h:28