yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.9.0
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-2021 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 
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 
66 
70  void fill(double x, double weight=1.0, double fraction=1.0) {
71  _dbn.fill(x, weight, fraction);
72  }
73 
77  void fillBin(double weight=1.0, double fraction=1.0) {
78  fill(xMid(), weight, fraction);
79  }
80 
82 
83 
84  public:
85 
88 
91  double area() const {
92  return sumW();
93  }
94 
96  double height() const {
97  return area() / xWidth();
98  }
99 
101 
102 
105 
108  double areaErr() const {
109  return sqrt(sumW2());
110  }
111 
114  double heightErr() const {
115  return areaErr() / xWidth();
116  }
117 
119  double relErr() const {
121  return sumW2() != 0 ? sqrt(sumW2()) / sumW() : 0;
122  }
123 
125 
126 
127  public:
128 
131  return add(toAdd);
132  }
133 
135  HistoBin1D& operator -= (const HistoBin1D& toSubtract) {
136  return subtract(toSubtract);
137  }
138 
139 
140  protected:
141 
143  HistoBin1D& add(const HistoBin1D& hb) {
144  Bin1D<Dbn1D>::add(hb);
145  return *this;
146  }
147 
151  return *this;
152  }
153 
154  };
155 
156 
158  inline HistoBin1D operator + (const HistoBin1D& a, const HistoBin1D& b) {
159  HistoBin1D rtn(a);
160  rtn += b;
161  return rtn;
162  }
163 
165  inline HistoBin1D operator - (const HistoBin1D& a, const HistoBin1D& b) {
166  HistoBin1D rtn(a);
167  rtn -= b;
168  return rtn;
169  }
170 
171 
172 }
173 
174 #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:77
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:152
double heightErr() const
Definition: HistoBin1D.h:114
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
HistoBin1D & operator+=(const HistoBin1D &toAdd)
Add two bins (for use by Histo1D).
Definition: HistoBin1D.h:130
double sumW2() const
The sum of weights squared.
Definition: Bin1D.h:231
double relErr() const
The relative size of the error (same for either area or height errors)
Definition: HistoBin1D.h:119
double xMid() const
Geometric centre of the bin, i.e. high+low/2.0.
Definition: Bin1D.h:144
HistoBin1D & subtract(const HistoBin1D &hb)
Subtract one bin from another (internal, explicitly named version)
Definition: HistoBin1D.h:149
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:289
Bin1D< DBN > & subtract(const Bin1D< DBN > &b)
Definition: Bin1D.h:303
double area() const
Definition: HistoBin1D.h:91
double areaErr() const
Definition: HistoBin1D.h:108
HistoBin1D & operator-=(const HistoBin1D &toSubtract)
Subtract two bins.
Definition: HistoBin1D.h:135
double height() const
The height is defined as area/width.
Definition: HistoBin1D.h:96
double sumW() const
The sum of weights.
Definition: Bin1D.h:226
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:70
A 1D distribution.
Definition: Dbn1D.h:28
HistoBin1D & add(const HistoBin1D &hb)
Add two bins (internal, explicitly named version)
Definition: HistoBin1D.h:143