yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.3
BinEstimators.h
Go to the documentation of this file.
1#ifndef YODA_BINESTIMATORS_H
2#define YODA_BINESTIMATORS_H
3
6#include <cstdlib>
7
8namespace YODA {
9
14 struct BinEstimator {
15
17 virtual ~BinEstimator() {}
18
20 size_t estindex(double x) const {
21 if (_N == 0) return 0;
22 const int i = _est(x);
23 if (i < 0) return 0;
24 const size_t i2 = (size_t) i;
25 if (i2 >= _N) return _N+1;
26 return i2 + 1;
27 }
28
30 size_t operator() (double x) const {
31 return estindex(x);
32 }
33
34 protected:
35
38 virtual int _est(double x) const = 0;
39
41 size_t _N;
42 };
43
44
49 struct LinBinEstimator : public BinEstimator {
50
52 LinBinEstimator(size_t nbins, double xlow, double xhigh) {
53 _N = nbins;
54 _c = xlow;
55 _m = (double) nbins / (xhigh - xlow);
56 }
57
60 _N = other._N;
61 _c = other._c;
62 _m = other._m;
63 }
64
66 int _est(double x) const {
67 int res = (int) floor(_m * (x - _c));
68 return res;
69 }
70
71 protected:
72 double _c, _m;
73 };
74
75
83 public:
84
86 LogBinEstimator(size_t nbins, double xlow, double xhigh) {
87 _N = nbins;
88 _c = Utils::fastlog2(xlow);
89 _m = nbins / (Utils::fastlog2(xhigh) - _c);
90 }
91
93 int _est(double x) const {
94 if (x <= 0.) return -1;
95 int res = (int) floor(_m * (Utils::fastlog2(x) - _c));
96 return res;
97
98 }
99
100 protected:
101 double _c, _m;
102 };
103}
104
105#endif
Logarithmic bin estimator.
LogBinEstimator(size_t nbins, double xlow, double xhigh)
Constructor.
Anonymous namespace to limit visibility.
Bin estimator.
size_t operator()(double x) const
Return offset bin index estimate, with 0 = underflow and Nbins+1 = overflow.
size_t estindex(double x) const
Return offset bin index estimate, with 0 = underflow and Nbins+1 = overflow.
virtual ~BinEstimator()
Virtual destructor needed for inheritance.
Linear bin estimator.
LinBinEstimator(size_t nbins, double xlow, double xhigh)
Constructor.
LinBinEstimator(const LinBinEstimator &other)
Copy constructor.