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
00029 #include "AveragerWeighted.h"
00030 #include "yat/utility/iterator_traits.h"
00031
00032 #include <boost/concept_check.hpp>
00033
00034 #include <string>
00035 #include <vector>
00036
00037 namespace theplu {
00038 namespace yat {
00039 namespace statistics {
00040
00050 class Histogram
00051 {
00052 public:
00053
00057 Histogram(void);
00058
00062 Histogram(const Histogram&);
00063
00068 Histogram(const double xmin, const double xmax, const size_t n);
00069
00070 virtual ~Histogram(void);
00071
00085 int add(const double x,const double weight=1.0);
00086
00095 const AveragerWeighted& averager_all(void) const;
00096
00106 const AveragerWeighted& averager_histogram(void) const;
00107
00111 size_t nof_bins(void) const;
00112
00139 void normalize(bool choice = true);
00140
00147 double observation_value(const size_t k) const;
00148
00154 void rescale(double factor);
00155
00160 void reset(void);
00161
00165 double spacing(void) const;
00166
00172 double xmax(void) const;
00173
00179 double xmin(void) const;
00180
00184 double operator[](size_t k) const;
00185
00189 const Histogram& operator=(const Histogram&);
00190
00199 const Histogram& operator+=(const Histogram& rhs);
00200
00201 private:
00202
00203 size_t bin(double d);
00204
00205 std::vector<double> histogram_;
00206 double xmax_;
00207 double xmin_;
00208 statistics::AveragerWeighted sum_all_;
00209 statistics::AveragerWeighted sum_histogram_;
00210 };
00211
00219 template<typename ForwardIterator>
00220 void add(Histogram& h,
00221 ForwardIterator first, ForwardIterator last)
00222 {
00223 BOOST_CONCEPT_ASSERT((boost::ForwardIterator<ForwardIterator>));
00224 utility::iterator_traits<ForwardIterator> traits;
00225 while (first!=last) {
00226 h.add(traits.data(first), traits.weight(first));
00227 ++first;
00228 }
00229 }
00230
00236 std::ostream& operator<<(std::ostream& s,const Histogram&);
00237
00238 }}}
00239
00240 #endif