00001 #ifndef _theplu_yat_statistics_histogram_
00002 #define _theplu_yat_statistics_histogram_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "AveragerWeighted.h"
00029 #include "yat/utility/iterator_traits.h"
00030
00031 #include <string>
00032 #include <vector>
00033
00034 namespace theplu {
00035 namespace yat {
00036 namespace statistics {
00037
00047 class Histogram
00048 {
00049 public:
00050
00054 Histogram(void);
00055
00059 Histogram(const Histogram&);
00060
00065 Histogram(const double xmin, const double xmax, const size_t n);
00066
00067 virtual ~Histogram(void);
00068
00082 int add(const double x,const double weight=1.0);
00083
00092 const AveragerWeighted& averager_all(void) const;
00093
00103 const AveragerWeighted& averager_histogram(void) const;
00104
00108 size_t nof_bins(void) const;
00109
00136 void normalize(bool choice = true);
00137
00144 double observation_value(const size_t k) const;
00145
00150 void reset(void);
00151
00155 double spacing(void) const;
00156
00162 double xmax(void) const;
00163
00169 double xmin(void) const;
00170
00174 double operator[](size_t k) const;
00175
00179 const Histogram& operator=(const Histogram&);
00180
00181 private:
00182
00183 size_t bin(double d);
00184
00185 std::vector<double> histogram_;
00186 double xmax_;
00187 double xmin_;
00188 statistics::AveragerWeighted sum_all_;
00189 statistics::AveragerWeighted sum_histogram_;
00190 };
00191
00195 template<typename ForwardIterator>
00196 void add(Histogram& h,
00197 ForwardIterator first, ForwardIterator last)
00198 {
00199 while (first!=last) {
00200 h.add(utility::iterator_traits<ForwardIterator>().data(),
00201 utility::iterator_traits<ForwardIterator>().weight());
00202 ++first;
00203 }
00204 }
00205
00209 std::ostream& operator<<(std::ostream& s,const Histogram&);
00210
00211 }}}
00212
00213 #endif