00001
00002
00003 #ifndef HISTOGRAM_H
00004 #define HISTOGRAM_H
00005
00006 #include "smplstat.h"
00007
00008 #include <string>
00009 #include <iostream>
00010 #include <vector>
00011
00012
00013 class Histogram : public SampleStatistic
00014 {
00015 public:
00016
00017 Histogram(std::string title="default", double from=0, double to=1, double step=0.1);
00018
00019
00020 ~Histogram();
00021
00022 void fill(double x, double w=1.0);
00023 void operator+=(double x){fill(x, 1.0);}
00024
00025
00026 virtual void clear();
00027
00028
00029 void setRange(double from=0, double to=1, double step=0.1);
00030
00031 void print(std::ostream& out=std::cout);
00032
00033
00034 float operator[](int n)const{return m_hist[n];}
00035
00036
00037 float step()const{return m_step;}
00038 float to()const{return m_to;}
00039 float from()const{return m_from;}
00040
00041
00042 float total()const{return m_total;}
00043 float under()const{return m_under;}
00044 float over()const {return m_over;}
00045
00046
00047 typedef std::vector<float>::const_iterator const_iterator;
00048 const_iterator begin()const{return m_hist.begin();}
00049 const_iterator end()const{return m_hist.end();}
00050
00051 Histogram* next() { return m_next;}
00052
00053 void setTitle ( std::string& s ) { m_title = s; }
00054
00055 private:
00056
00057 std::string m_title;
00058 double m_from, m_to, m_step;
00059 unsigned m_bins;
00060 std::vector <float> m_hist;
00061 double m_total, m_under, m_over;
00062
00063 Histogram * m_next;
00064 };
00065
00066 Histogram* firstHist();
00067 void printAllHists(std::ostream& out =std::cout);
00068 void clearAllHists();
00069
00070 #endif