Changeset 215 for trunk/src/Histogram.cc
 Timestamp:
 Nov 7, 2004, 12:07:03 AM (18 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/Histogram.cc
r199 r215 25 25 26 26 27 Histogram::Histogram(const double min, const double max, const size_t) 28 : xmax_(max), xmin_(min), sum_all_(), sum_histogram_() 27 Histogram::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_() 29 31 { 30 // Peter, fix me31 32 } 32 33 34 /*35 Histogram::Histogram(const u_int nof_bins, const double min, const double max)36 : spacing_((maxmin)/nof_bins), xmax_(max), xmin_(min), sum_all_(),37 sum_histogram_()38 {39 histogram_=vector<statistics::WeightedAverager>(nof_bins);40 }41 */42 33 43 34 … … 51 42 int Histogram::add(const double x, const double w) 52 43 { 44 std::cout << "Histogram::add Jari, check me!" << std::endl; 45 53 46 sum_all_.add(x,w); 54 47 if (x<xmin_) … … 64 57 65 58 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 /*75 59 void Histogram::normalize(double scale_factor) 76 60 { 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; 79 63 } 80 */81 64 82 65 … … 89 72 sum_histogram_.reset(); 90 73 } 91 92 93 94 /*95 const statistics::WeightedAverager& Histogram::operator[](double d) const96 {97 if ((d<xmin_)  (d>xmax_))98 return statistics::WeightedAverager();// requested bin not within boundaries99 return histogram_[static_cast<u_int>(floor((dxmin_) /100 spacing_))];101 }102 */103 74 104 75 … … 118 89 119 90 120 std::ostream& operator<<(std::ostream& s,const Histogram& b)91 std::ostream& operator<<(std::ostream& s,const Histogram& histogram) 121 92 { 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'; 131 98 132 99 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"; 137 101 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++) { 140 103 s.width(12); 141 s << observation;104 s << histogram.xmin()+(i+0.5)*histogram.spacing(); 142 105 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'; 153 107 } 154 108
Note: See TracChangeset
for help on using the changeset viewer.