1 | /*
|
---|
2 | * Histogram.hpp
|
---|
3 | *
|
---|
4 | * Created on: Jul 26, 2012
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef HISTOGRAM_HPP_
|
---|
9 | #define HISTOGRAM_HPP_
|
---|
10 |
|
---|
11 |
|
---|
12 | // include config.h
|
---|
13 | #ifdef HAVE_CONFIG_H
|
---|
14 | #include <config.h>
|
---|
15 | #endif
|
---|
16 |
|
---|
17 | #include <map>
|
---|
18 | #include <vector>
|
---|
19 |
|
---|
20 | class HistogramTest;
|
---|
21 |
|
---|
22 | /** This class generates a histogram from a given vector of sampled values.
|
---|
23 | *
|
---|
24 | * Most importantly, it also contains operator+=() and operator-=() to perform
|
---|
25 | * sum on the \b histograms.
|
---|
26 | *
|
---|
27 | * This is to be used with the OrthogonalSummation which requires these specific
|
---|
28 | * operator implementations.
|
---|
29 | *
|
---|
30 | */
|
---|
31 | class Histogram
|
---|
32 | {
|
---|
33 | //!> grant unit test access to private parts
|
---|
34 | friend class HistogramTest;
|
---|
35 | public:
|
---|
36 | //!> named type for a vector of sample values
|
---|
37 | typedef std::vector<double> samples_t;
|
---|
38 | //!> named type for the start of a bin
|
---|
39 | typedef double BinLowerEnd;
|
---|
40 | //!> named type for the count of a bin, may be fractional
|
---|
41 | typedef double BinWeight;
|
---|
42 | //!> named type for the pair identifying a bin by its lower end and count
|
---|
43 | typedef std::pair< BinLowerEnd, BinWeight> Bin_t;
|
---|
44 | private:
|
---|
45 | //!> named type for a vector of bins
|
---|
46 | typedef std::map< BinLowerEnd, BinWeight > Bins_t;
|
---|
47 | public:
|
---|
48 | /** Constructor for class Histogram.
|
---|
49 | *
|
---|
50 | * @param samples samples to put in the histogram.
|
---|
51 | * @param CountBins number of bins (if negative, we choose number by statistical means)
|
---|
52 | */
|
---|
53 | Histogram(const samples_t &samples, const int _CountBins=-1);
|
---|
54 |
|
---|
55 | /** Adding another histogram onto this one.
|
---|
56 | *
|
---|
57 | * @param other other histogram
|
---|
58 | * @return ref to this instance
|
---|
59 | */
|
---|
60 | Histogram& operator+=(const Histogram &other);
|
---|
61 |
|
---|
62 | /** Subtracting another histogram from this one.
|
---|
63 | *
|
---|
64 | * @param other other histogram
|
---|
65 | * @return ref to this instance
|
---|
66 | */
|
---|
67 | Histogram& operator-=(const Histogram &other);
|
---|
68 |
|
---|
69 | /** States whether each bin of this histogram has count of zero.
|
---|
70 | *
|
---|
71 | * @return true - all bins are zero, false - else
|
---|
72 | */
|
---|
73 | bool isEmpty() const;
|
---|
74 |
|
---|
75 | private:
|
---|
76 | /** Returns the iterator to the bin into which the \a value fits.
|
---|
77 | *
|
---|
78 | * @param _value value to fit.
|
---|
79 | * @return iterator to bin or to bins.end() if not matching
|
---|
80 | */
|
---|
81 | Bins_t::iterator getBin(const double _value);
|
---|
82 |
|
---|
83 | private:
|
---|
84 | //!> vector of bins containing the histogram
|
---|
85 | Bins_t bins;
|
---|
86 | //!> width of bin
|
---|
87 | double binwidth;
|
---|
88 | //!> number of bins
|
---|
89 | int CountBins;
|
---|
90 | };
|
---|
91 |
|
---|
92 |
|
---|
93 | #endif /* HISTOGRAM_HPP_ */
|
---|