yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
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 const int i = _est(x);
22 if (i < 0) return 0;
23 const size_t i2 = (size_t) i;
24 if (i2 >= _N) return _N+1;
25 return i2 + 1;
26 }
27
29 size_t operator() (double x) const {
30 return estindex(x);
31 }
32
33 protected:
34
37 virtual int _est(double x) const = 0;
38
40 size_t _N;
41 };
42
43
48 struct LinBinEstimator : public BinEstimator {
49
51 LinBinEstimator(size_t nbins, double xlow, double xhigh) {
52 _N = nbins;
53 _c = xlow;
54 _m = (double) nbins / (xhigh - xlow);
55 }
56
59 _N = other._N;
60 _c = other._c;
61 _m = other._m;
62 }
63
65 int _est(double x) const {
66 int res =(int) floor(_m * (x - _c));
67 return res;
68 }
69
70 protected:
71 double _c, _m;
72 };
73
74
82 public:
83
85 LogBinEstimator(size_t nbins, double xlow, double xhigh) {
86 _N = nbins;
87 _c = log2(xlow);
88 _m = nbins / (log2(xhigh) - _c);
89 }
90
93 _N = other._N;
94 _c = other._c;
95 _m = other._m;
96 }
97
99 int _est(double x) const {
100 int res =(int) floor(_m * (Utils::fastlog2(x) - _c));
101 return res;
102
103 }
104
105 protected:
106 double _c, _m;
107 };
108}
109
110#endif
Logarithmic bin estimator.
LogBinEstimator(const LogBinEstimator &other)
Copy constructor.
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.