Changeset 215 for trunk/src/Histogram.cc


Ignore:
Timestamp:
Nov 7, 2004, 12:07:03 AM (18 years ago)
Author:
Jari Häkkinen
Message:

Continued work on new Histogram.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Histogram.cc

    r199 r215  
    2525
    2626
    27 Histogram::Histogram(const double min, const double max, const size_t)
    28   : xmax_(max), xmin_(min), sum_all_(), sum_histogram_()
     27Histogram::Histogram(const double min, const double max, const size_t n)
     28  : histogram_(std::vector<double>(n,0.0)),
     29    xmax_(max), xmin_(min),
     30    sum_all_(), sum_histogram_()
    2931{
    30   // Peter, fix me
    3132}
    32 
    33 
    34 /*
    35 Histogram::Histogram(const u_int nof_bins, const double min, const double max)
    36   : spacing_((max-min)/nof_bins), xmax_(max), xmin_(min), sum_all_(),
    37     sum_histogram_()
    38 {
    39   histogram_=vector<statistics::WeightedAverager>(nof_bins);
    40 }
    41 */
    4233
    4334
     
    5142int Histogram::add(const double x, const double w)
    5243{
     44  std::cout << "Histogram::add Jari, check me!" << std::endl;
     45
    5346  sum_all_.add(x,w);
    5447  if (x<xmin_)
     
    6457
    6558
    66 void Histogram::normalize(double factor)
    67 {
    68   for (u_int i=0; i<histogram_.size(); i++)
    69     histogram_[i]/=factor;
    70 }
    71 
    72 
    73 
    74 /*
    7559void Histogram::normalize(double scale_factor)
    7660{
    77   for (u_int i=0; i<histogram_.size(); i++)
    78     histogram_[i]/=_sum_histogram.nof_entries()*spacing_*scale_factor;
     61  for (size_t i=0; i<histogram_.size(); i++)
     62    histogram_[i]/=scale_factor;
    7963}
    80 */
    8164
    8265
     
    8972  sum_histogram_.reset();
    9073}
    91 
    92 
    93 
    94 /*
    95 const statistics::WeightedAverager& Histogram::operator[](double d) const
    96 {
    97   if ((d<xmin_) || (d>xmax_))
    98     return statistics::WeightedAverager();// requested bin not within boundaries
    99   return histogram_[static_cast<u_int>(floor((d-xmin_) /
    100                spacing_))];
    101 }
    102 */
    10374
    10475
     
    11889
    11990
    120 std::ostream& operator<<(std::ostream& s,const Histogram& b)
     91std::ostream& operator<<(std::ostream& s,const Histogram& histogram)
    12192{
    122   s << "# min           : " << b.xmin() << '\n';
    123   s << "# max           : " << b.xmax() << '\n';
    124   s << "# spacing       : " << b.spacing() << '\n';
    125   s << "# number of bins: " << b.nof_bins() << '\n';
    126 
    127 //   s << "# histogram averager: " << b.averager_histogram() << '\n';
    128   s << "#            entries: " << b.averager_histogram().sum_w() << '\n';
    129 //   s << "# all averager      : " << b.averager_all() << '\n';
    130   s << "#            entries: " << b.averager_all().sum_w() << '\n';
     93  s << "# histogram min : " << histogram.xmin() << '\n';
     94  s << "# histogram max : " << histogram.xmax() << '\n';
     95  s << "# number of bins: " << histogram.nof_bins() << '\n';
     96  s << "# histogram averager: " << histogram.averager_histogram() << '\n';
     97  s << "#       all averager: " << histogram.averager_all() << '\n';
    13198
    13299  s << "# column 1: center of observation bin\n"
    133     << "# column 2: frequency\n"
    134     << "# column 3: relative frequency\n"
    135     << "# column 4: average of observations in bin\n"
    136     << "# column 5: stddev of frequency\n";
     100    << "# column 2: frequency\n";
    137101
    138   double observation=b.xmin()+b.spacing()/2;
    139   for (u_int i=0; i<b.nof_bins(); i++) {
     102  for (u_int i=0; i<histogram.nof_bins(); i++) {
    140103    s.width(12);
    141     s << observation;
     104    s << histogram.xmin()+(i+0.5)*histogram.spacing();
    142105    s.width(12);
    143     s << b[i];
    144     s.width(12);
    145 // Peter, fix me
    146 //     if (b.nof_entries_all())
    147 //       s << b[i].sum_w()/b.nof_entries_all();
    148 //     else
    149 //       s << 0;
    150     s.width(12);
    151 //     s << b[i] << "\n";
    152     observation+=b.spacing();
     106    s << histogram[i] << '\n';
    153107  }
    154108
Note: See TracChangeset for help on using the changeset viewer.