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/concept_check.h"
00031 #include "yat/utility/iterator_traits.h"
00032
00033 #include <boost/concept_check.hpp>
00034
00035 #include <iosfwd>
00036 #include <string>
00037 #include <vector>
00038
00039 namespace theplu {
00040 namespace yat {
00041 namespace statistics {
00042
00052 class Histogram
00053 {
00054 public:
00055
00059 Histogram(void);
00060
00074 Histogram(std::istream&);
00075
00079 Histogram(const Histogram&);
00080
00085 Histogram(const double xmin, const double xmax, const size_t n);
00086
00087 virtual ~Histogram(void);
00088
00102 int add(const double x,const double weight=1.0);
00103
00112 const AveragerWeighted& averager_all(void) const;
00113
00123 const AveragerWeighted& averager_histogram(void) const;
00124
00128 size_t nof_bins(void) const;
00129
00156 void normalize(bool choice = true);
00157
00164 double observation_value(const size_t k) const;
00165
00171 void rescale(double factor);
00172
00177 void reset(void);
00178
00182 double spacing(void) const;
00183
00189 double xmax(void) const;
00190
00196 double xmin(void) const;
00197
00201 double operator[](size_t k) const;
00202
00206 const Histogram& operator=(const Histogram&);
00207
00216 const Histogram& operator+=(const Histogram& rhs);
00217
00218 private:
00219
00220 size_t bin(double d);
00221
00222 std::vector<double> histogram_;
00223 double xmax_;
00224 double xmin_;
00225 statistics::AveragerWeighted sum_all_;
00226 statistics::AveragerWeighted sum_histogram_;
00227 };
00228
00236 template<typename ForwardIterator>
00237 void add(Histogram& h,
00238 ForwardIterator first, ForwardIterator last)
00239 {
00240 BOOST_CONCEPT_ASSERT((boost::ForwardIterator<ForwardIterator>));
00241 BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<ForwardIterator>));
00242 utility::iterator_traits<ForwardIterator> traits;
00243 while (first!=last) {
00244 h.add(traits.data(first), traits.weight(first));
00245 ++first;
00246 }
00247 }
00248
00254 std::ostream& operator<<(std::ostream& s,const Histogram&);
00255
00256 }}}
00257
00258 #endif