Go to the documentation of this file.00001
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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef HISTOGRAM_HPP
00044 #define HISTOGRAM_HPP 1
00045
00046
00047 #include <vector>
00048 #include <stdint.h>
00049
00050
00053 enum histogram_accumulation_e {
00054 HISTOGRAM_ACCUMULATION_CLOSEST = 0,
00055 HISTOGRAM_ACCUMULATION_LINEAR,
00056 };
00057
00058
00061 class Histogram
00062 {
00063
00064 public:
00065
00068 virtual ~Histogram() {}
00069
00070 };
00071
00072
00075 class Histogram1D : public Histogram
00076 {
00077 uint32_t _n;
00078 double _range[2];
00079 double _step;
00080 std::vector<double> _data;
00082 public:
00083
00086 Histogram1D( uint32_t n, const double range[2] );
00087
00092 Histogram1D( uint32_t n, const std::vector<double> &xdata,
00093 histogram_accumulation_e type = HISTOGRAM_ACCUMULATION_CLOSEST );
00094
00099 Histogram1D( uint32_t n, const std::vector<double> &xdata, const std::vector<double> &wdata,
00100 histogram_accumulation_e type = HISTOGRAM_ACCUMULATION_CLOSEST );
00101
00104 virtual ~Histogram1D();
00105
00108 uint32_t n( void ) const { return( _n ); }
00109
00112 double step( void ) const { return( _step ); }
00113
00116 double coord( uint32_t i ) const;
00117
00122 void accumulate( uint32_t i, double weight ) {
00123 _data[i] += weight;
00124 }
00125
00128 void accumulate_closest( double x, double weight );
00129
00139 void accumulate_linear( double x, double weight );
00140
00146 void convert_to_density( void );
00147
00150 void get_range( double range[2] ) const;
00151
00156 void get_bin_range( double &min, double &max ) const;
00157
00160 std::vector<double> &get_data( void ) { return( _data ); }
00161
00164 const std::vector<double> &get_data( void ) const { return( _data ); }
00165
00168 const double &operator()( uint32_t i ) const {
00169 return( _data[i] );
00170 }
00171
00174 double &operator()( uint32_t i ) {
00175 return( _data[i] );
00176 }
00177
00180 const Histogram1D &operator*=( double x );
00181 };
00182
00183
00186 class Histogram2D : public Histogram
00187 {
00188 uint32_t _n;
00189 uint32_t _m;
00190 double _range[4];
00191 double _nstep;
00192 double _mstep;
00193 std::vector<double> _data;
00195 public:
00196
00199 Histogram2D( uint32_t n, uint32_t m, const double range[4] );
00200
00205 Histogram2D( uint32_t n, uint32_t m,
00206 const std::vector<double> &xdata,
00207 const std::vector<double> &ydata,
00208 histogram_accumulation_e type = HISTOGRAM_ACCUMULATION_CLOSEST );
00209
00214 Histogram2D( uint32_t n, uint32_t m,
00215 const std::vector<double> &xdata,
00216 const std::vector<double> &ydata,
00217 const std::vector<double> &wdata,
00218 histogram_accumulation_e type = HISTOGRAM_ACCUMULATION_CLOSEST );
00219
00222 virtual ~Histogram2D();
00223
00226 uint32_t n( void ) const { return( _n ); }
00227
00230 uint32_t m( void ) const { return( _m ); }
00231
00234 double nstep( void ) const { return( _nstep ); }
00235
00238 double mstep( void ) const { return( _mstep ); }
00239
00242 double icoord( uint32_t i ) const;
00243
00246 double jcoord( uint32_t j ) const;
00247
00252 void accumulate( uint32_t i, uint32_t j, double weight ) {
00253 _data[i+j*_n] += weight;
00254 }
00255
00258 void accumulate_closest( double x, double y, double weight );
00259
00269 void accumulate_linear( double x, double y, double weight );
00270
00276 void convert_to_density( void );
00277
00280 void get_range( double range[4] ) const;
00281
00286 void get_bin_range( double &min, double &max ) const;
00287
00292 std::vector<double> &get_data( void ) { return( _data ); }
00293
00298 const std::vector<double> &get_data( void ) const { return( _data ); }
00299
00302 const double &operator()( uint32_t i, uint32_t j ) const {
00303 return( _data[i+j*_n] );
00304 }
00305
00308 double &operator()( uint32_t i, uint32_t j ) {
00309 return( _data[i+j*_n] );
00310 }
00311
00314 const Histogram2D &operator*=( double x );
00315 };
00316
00317
00318 #endif
00319