| [c4fd03] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2012 University of Bonn. All rights reserved.
 | 
|---|
| [5aaa43] | 5 |  * Copyright (C)  2013 Frederik Heber. All rights reserved.
 | 
|---|
| [c4fd03] | 6 |  * 
 | 
|---|
 | 7 |  *
 | 
|---|
 | 8 |  *   This file is part of MoleCuilder.
 | 
|---|
 | 9 |  *
 | 
|---|
 | 10 |  *    MoleCuilder is free software: you can redistribute it and/or modify
 | 
|---|
 | 11 |  *    it under the terms of the GNU General Public License as published by
 | 
|---|
 | 12 |  *    the Free Software Foundation, either version 2 of the License, or
 | 
|---|
 | 13 |  *    (at your option) any later version.
 | 
|---|
 | 14 |  *
 | 
|---|
 | 15 |  *    MoleCuilder is distributed in the hope that it will be useful,
 | 
|---|
 | 16 |  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
 | 17 |  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
 | 18 |  *    GNU General Public License for more details.
 | 
|---|
 | 19 |  *
 | 
|---|
 | 20 |  *    You should have received a copy of the GNU General Public License
 | 
|---|
 | 21 |  *    along with MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
 | 
|---|
 | 22 |  */
 | 
|---|
 | 23 | 
 | 
|---|
 | 24 | /*
 | 
|---|
 | 25 |  * Histogram.cpp
 | 
|---|
 | 26 |  *
 | 
|---|
 | 27 |  *  Created on: Jul 26, 2012
 | 
|---|
 | 28 |  *      Author: heber
 | 
|---|
 | 29 |  */
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | // include config.h
 | 
|---|
 | 33 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 34 | #include <config.h>
 | 
|---|
 | 35 | #endif
 | 
|---|
 | 36 | 
 | 
|---|
| [9eb71b3] | 37 | //#include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [c4fd03] | 38 | 
 | 
|---|
 | 39 | #include "Histogram.hpp"
 | 
|---|
 | 40 | 
 | 
|---|
 | 41 | #include <algorithm>
 | 
|---|
 | 42 | #include <cmath>
 | 
|---|
| [3f6bbb] | 43 | #include <iostream>
 | 
|---|
| [c4fd03] | 44 | #include <sstream>
 | 
|---|
| [3f6bbb] | 45 | #include <string>
 | 
|---|
| [c4fd03] | 46 | 
 | 
|---|
 | 47 | #include <boost/bind.hpp>
 | 
|---|
 | 48 | #include <boost/foreach.hpp>
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 51 | #include "CodePatterns/Log.hpp"
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | /** Tiny helper struct to create equally spaced bins with count of zero.
 | 
|---|
 | 54 |  *
 | 
|---|
 | 55 |  */
 | 
|---|
 | 56 | struct BinCreator_t {
 | 
|---|
 | 57 |   BinCreator_t( const double lowerend, const double _width ) :
 | 
|---|
 | 58 |     currentstart(lowerend),
 | 
|---|
 | 59 |     width(_width)
 | 
|---|
 | 60 |   {}
 | 
|---|
 | 61 |   Histogram::Bin_t operator()() {
 | 
|---|
 | 62 |     Histogram::Bin_t bin( make_pair( currentstart, 0.) );
 | 
|---|
 | 63 |     currentstart+=width;
 | 
|---|
 | 64 |     return bin;
 | 
|---|
 | 65 |   }
 | 
|---|
 | 66 | private:
 | 
|---|
 | 67 |   double currentstart;
 | 
|---|
 | 68 |   const double width;
 | 
|---|
 | 69 | };
 | 
|---|
 | 70 | 
 | 
|---|
| [3f6bbb] | 71 | 
 | 
|---|
| [c4fd03] | 72 | // see http://stackoverflow.com/questions/634087/stdcopy-to-stdcout-for-stdpair
 | 
|---|
 | 73 | // printing a pair is not easy, especially so with ostream_iterator as it cannot find
 | 
|---|
 | 74 | // overload operator<<() as it is not in namespace std.
 | 
|---|
 | 75 | template <class T>
 | 
|---|
 | 76 | struct PrintPair : public std::unary_function<T, void>
 | 
|---|
 | 77 | {
 | 
|---|
 | 78 |     std::ostream& os;
 | 
|---|
 | 79 |     PrintPair(std::ostream& strm) : os(strm) {}
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 |     void operator()(const T& elem) const
 | 
|---|
 | 82 |     {
 | 
|---|
 | 83 |       os << "(" << elem.first << "," << elem.second << ") ";
 | 
|---|
 | 84 |     }
 | 
|---|
 | 85 | };
 | 
|---|
 | 86 | 
 | 
|---|
| [3f6bbb] | 87 | std::ostream & operator<<(std::ostream &ost, const Histogram::Bin_t &elem)
 | 
|---|
 | 88 | {
 | 
|---|
 | 89 |   ost << "(" << elem.first << "," << elem.second << ") ";
 | 
|---|
 | 90 |   return ost;
 | 
|---|
 | 91 | }
 | 
|---|
 | 92 | 
 | 
|---|
| [cf18c5] | 93 | std::ostream & operator<<(std::ostream &ost, const Histogram &histogram)
 | 
|---|
 | 94 | {
 | 
|---|
 | 95 |   for (Histogram::Bins_t::const_iterator iter = histogram.bins.begin();
 | 
|---|
 | 96 |       iter != histogram.bins.end(); ++iter)
 | 
|---|
| [4b8ab7] | 97 |     ost << std::make_pair(iter->first, iter->second);
 | 
|---|
| [cf18c5] | 98 |   return ost;
 | 
|---|
 | 99 | }
 | 
|---|
 | 100 | 
 | 
|---|
| [dde8ec] | 101 | Histogram::Histogram(const samples_t &samples) :
 | 
|---|
 | 102 |   binwidth(0.5),
 | 
|---|
 | 103 |   offset(0.)
 | 
|---|
 | 104 | {
 | 
|---|
 | 105 |   if (!samples.empty()) {
 | 
|---|
 | 106 |     // set offset to first value
 | 
|---|
 | 107 |     const_cast<BinLowerEnd &>(offset) = *samples.begin();
 | 
|---|
 | 108 |     // set binwidth to statistical sensible value
 | 
|---|
| [955051] | 109 | //    MinMax_t MinMax = getMinMaxFromSamples(samples);
 | 
|---|
| [658485] | 110 | //    const_cast<double &>(binwidth) = (*(MinMax.second) - *(MinMax.first))/pow(samples.size(), 1./3.);
 | 
|---|
| [dde8ec] | 111 |     // and add all samples to these histogram bins
 | 
|---|
 | 112 |   }
 | 
|---|
| [955051] | 113 |   addSamples(samples);
 | 
|---|
| [dde8ec] | 114 | }
 | 
|---|
| [9fd889] | 115 | 
 | 
|---|
| [6bed1f] | 116 | Histogram::Histogram(const samples_t &samples, const BinLowerEnd _offset, const double _binwidth) :
 | 
|---|
 | 117 |     binwidth(_binwidth),
 | 
|---|
 | 118 |     offset(_offset)
 | 
|---|
| [9fd889] | 119 | {
 | 
|---|
 | 120 |   addSamples(samples);
 | 
|---|
 | 121 | }
 | 
|---|
 | 122 | 
 | 
|---|
| [dde8ec] | 123 | Histogram::MinMax_t Histogram::getMinMaxFromSamples(const samples_t &samples) const
 | 
|---|
 | 124 | {
 | 
|---|
 | 125 |   std::pair<samples_t::const_iterator, samples_t::const_iterator> returnpair;
 | 
|---|
 | 126 |   returnpair.first = min_element(samples.begin(), samples.end());
 | 
|---|
 | 127 |   returnpair.second = max_element(samples.begin(), samples.end());
 | 
|---|
 | 128 |   ASSERT((returnpair.second != samples.end()) || (returnpair.first != samples.end()),
 | 
|---|
 | 129 |       "Histogram::Histogram() - cannot find min/max despite non-empty range.");
 | 
|---|
 | 130 |   return returnpair;
 | 
|---|
 | 131 | }
 | 
|---|
 | 132 | 
 | 
|---|
| [9fd889] | 133 | void Histogram::addSamples(const samples_t &samples)
 | 
|---|
| [c4fd03] | 134 | {
 | 
|---|
 | 135 |   // build histogram from samples
 | 
|---|
 | 136 |   if (!samples.empty()) {
 | 
|---|
| [6bed1f] | 137 |     // 1. get min and max and determine width
 | 
|---|
| [dde8ec] | 138 |     MinMax_t MinMax = getMinMaxFromSamples(samples);
 | 
|---|
 | 139 | //    LOG(1, "DEBUG: min is " << *(MinMax.first) << " and max is " << *(MinMax.second) << ".");
 | 
|---|
| [6bed1f] | 140 | 
 | 
|---|
 | 141 |     // 2. create each bin
 | 
|---|
 | 142 |     {
 | 
|---|
 | 143 |       std::vector<Bin_t> vectorbins;
 | 
|---|
| [dde8ec] | 144 |       const BinLowerEnd HistogramStart = getLowerEnd(*(MinMax.first));
 | 
|---|
 | 145 |       BinCreator_t BinCreator( HistogramStart, binwidth );
 | 
|---|
| [6bed1f] | 146 |       // we need one extra bin for get...Bin()'s find to work properly
 | 
|---|
| [dde8ec] | 147 |       const int CountBins = ceil((*(MinMax.second) - HistogramStart)/binwidth)+1;
 | 
|---|
| [6bed1f] | 148 |       vectorbins.resize(CountBins+1, Bin_t( make_pair(0., 0.) ) );
 | 
|---|
 | 149 |       std::generate( vectorbins.begin(), vectorbins.end(), BinCreator );
 | 
|---|
 | 150 |       bins.insert(vectorbins.begin(), vectorbins.end());
 | 
|---|
 | 151 |     }
 | 
|---|
 | 152 | 
 | 
|---|
 | 153 |     // 3. place each sample into bin
 | 
|---|
| [c4fd03] | 154 |     BOOST_FOREACH( double value, samples) {
 | 
|---|
| [1c365e] | 155 |       const Bins_t::iterator biniter = getLowerEndBin(value);
 | 
|---|
| [c4fd03] | 156 |       ASSERT( biniter != bins.end(),
 | 
|---|
 | 157 |           "Histogram::Histogram() - cannot find bin for value from given samples.");
 | 
|---|
| [6bed1f] | 158 |       // (make bin count normalized, i.e. always equal to surface area of 1)
 | 
|---|
| [45f4f96] | 159 |       biniter->second += 1./binwidth;
 | 
|---|
| [c4fd03] | 160 |     }
 | 
|---|
| [e5dbd5] | 161 |     LOG(2, "DEBUG: Bins are " << printBins() << ".");
 | 
|---|
| [c4fd03] | 162 |   } else {
 | 
|---|
| [e11e23] | 163 | //    LOG(1, "INFO: Given vector of samples is empty.");
 | 
|---|
| [c4fd03] | 164 |   }
 | 
|---|
 | 165 | }
 | 
|---|
 | 166 | 
 | 
|---|
| [e5dbd5] | 167 | std::string Histogram::printBins() const
 | 
|---|
 | 168 | {
 | 
|---|
 | 169 |   std::stringstream output;
 | 
|---|
 | 170 |   std::for_each( bins.begin(), bins.end(), PrintPair<Bin_t>(output));
 | 
|---|
 | 171 |   return output.str();
 | 
|---|
 | 172 | }
 | 
|---|
 | 173 | 
 | 
|---|
| [e4048f] | 174 | void Histogram::extendMissingBins(const BinLowerEnd LowerEnd, const BinLowerEnd NextLowerEnd)
 | 
|---|
 | 175 | {
 | 
|---|
 | 176 |   Bins_t::const_iterator loweriter = getLowerEndBin(LowerEnd);
 | 
|---|
 | 177 |   Bins_t::const_iterator upperiter = getHigherEndBin(NextLowerEnd);
 | 
|---|
 | 178 |   if (loweriter == bins.end()) {
 | 
|---|
 | 179 |     // we need bins beneath our first, add them
 | 
|---|
 | 180 |     for(BinLowerEnd offset = getLowerEnd(LowerEnd);
 | 
|---|
 | 181 |         offset < getLowerEnd(NextLowerEnd);
 | 
|---|
| [7f8525] | 182 |         offset += binwidth) {
 | 
|---|
 | 183 |       LOG(4, "DEBUG: Extending below at offset " << offset << ".");
 | 
|---|
| [e4048f] | 184 |       bins.insert( std::make_pair (offset, 0. ) );
 | 
|---|
| [7f8525] | 185 |     }
 | 
|---|
 | 186 |     LOG(3, "DEBUG: Bins after adding empties before start are " << printBins() << ".");
 | 
|---|
| [e4048f] | 187 |   }
 | 
|---|
 | 188 |   if (upperiter == bins.end()) {
 | 
|---|
 | 189 |     // we need bins after our last, add them
 | 
|---|
 | 190 |     for(BinLowerEnd offset = getLowerEnd(LowerEnd);
 | 
|---|
| [7f8525] | 191 |         offset <= getLowerEnd(NextLowerEnd)+(1.5*binwidth); /* for safety we go a little further */
 | 
|---|
 | 192 |         offset += binwidth) {
 | 
|---|
 | 193 |       LOG(4, "DEBUG: Extending above at offset " << offset << ".");
 | 
|---|
| [e4048f] | 194 |       bins.insert( std::make_pair (offset, 0. ) );
 | 
|---|
| [7f8525] | 195 |     }
 | 
|---|
 | 196 |     LOG(3, "DEBUG: Bins after adding empties after end are " << printBins() << ".");
 | 
|---|
| [e4048f] | 197 |   }
 | 
|---|
| [955051] | 198 |   loweriter = getLowerEndBin(LowerEnd);
 | 
|---|
 | 199 |   ASSERT( loweriter != bins.end(),
 | 
|---|
 | 200 |       "Histogram::extendMissingBins() - still no lower bound after adding empties.");
 | 
|---|
 | 201 |   upperiter = getHigherEndBin(NextLowerEnd);
 | 
|---|
 | 202 |   ASSERT( upperiter != bins.end(),
 | 
|---|
 | 203 |       "Histogram::extendMissingBins() - still no upper bound after adding empties.");
 | 
|---|
| [e4048f] | 204 | }
 | 
|---|
 | 205 | 
 | 
|---|
| [22c4f57] | 206 | void Histogram::superposeOtherHistogram(const Histogram &other, const double prefactor)
 | 
|---|
 | 207 | {
 | 
|---|
| [f856ec] | 208 |   // check whether we just copy into an empty histogram
 | 
|---|
 | 209 |   if ((bins.empty()) && (prefactor == +1.)) {
 | 
|---|
 | 210 |     *this = other;
 | 
|---|
 | 211 |   } else {
 | 
|---|
 | 212 |     // go through each of the other histogram's bins
 | 
|---|
 | 213 |     if (!other.bins.empty()) {
 | 
|---|
 | 214 |       Bins_t::const_iterator enditer = --other.bins.end(); // (except internal last one)
 | 
|---|
 | 215 |       for (Bins_t::const_iterator biniter = other.bins.begin();
 | 
|---|
 | 216 |           biniter != enditer; /* we advance ourselves in loop */) {
 | 
|---|
 | 217 |         const Bin_t &bin = *biniter;
 | 
|---|
 | 218 |         ++biniter;
 | 
|---|
 | 219 |         const Bin_t &nextbin = *biniter;
 | 
|---|
 | 220 | 
 | 
|---|
 | 221 |         LOG(4, "DEBUG: Current bin is " << bin << ", next bin is " << nextbin << ".");
 | 
|---|
 | 222 | 
 | 
|---|
 | 223 |         // Check first whether start or end actually fit into our histogram, if not extend.
 | 
|---|
 | 224 |         extendMissingBins(bin.first, nextbin.first);
 | 
|---|
 | 225 | 
 | 
|---|
 | 226 |         // The bin will in general not fit into one bin in this histogram, but overlap.
 | 
|---|
 | 227 |         // Hence, we determine the contribution of the bin to each bin in this histogram
 | 
|---|
 | 228 |         // its overlaps into and add this weight to the bin.
 | 
|---|
 | 229 |         Bins_t::const_iterator loweriter = getLowerEndBin(bin.first);
 | 
|---|
 | 230 |         Bins_t::const_iterator upperiter = getHigherEndBin(nextbin.first);
 | 
|---|
 | 231 | 
 | 
|---|
 | 232 |         ASSERT( loweriter->first < upperiter->first,
 | 
|---|
 | 233 |             "Histogram::superposeOtherHistogram() - the bin range is invalid.");
 | 
|---|
 | 234 |         LOG(5, "DEBUG: bin range here is ["
 | 
|---|
 | 235 |             << loweriter->first << ","  << upperiter->first << ").");
 | 
|---|
 | 236 | 
 | 
|---|
 | 237 |         // Next, we create a vector of offsets
 | 
|---|
 | 238 |         typedef std::vector< BinLowerEnd > offsets_t;
 | 
|---|
 | 239 |         offsets_t offsets;
 | 
|---|
 | 240 |         {
 | 
|---|
 | 241 |           offsets.push_back(bin.first);
 | 
|---|
 | 242 |           Bins_t::const_iterator iter = loweriter;
 | 
|---|
 | 243 |           for (++iter; iter != upperiter; ++iter)
 | 
|---|
 | 244 |             if (offsets.back() != iter->first)
 | 
|---|
 | 245 |               offsets.push_back(iter->first);
 | 
|---|
 | 246 |           if (offsets.back() != nextbin.first)
 | 
|---|
 | 247 |             offsets.push_back(nextbin.first);
 | 
|---|
 | 248 |           LOG(4, "DEBUG: Offsets are " << offsets << ".");
 | 
|---|
 | 249 |         }
 | 
|---|
| [22c4f57] | 250 | 
 | 
|---|
| [f856ec] | 251 |         // then, we go through the offsets but the last one and add the respective area
 | 
|---|
 | 252 |         {
 | 
|---|
 | 253 |           offsets_t::const_iterator iter = offsets.begin();
 | 
|---|
 | 254 |           offsets_t::const_iterator nextiter = ++offsets.begin();
 | 
|---|
 | 255 |           for (; iter != --offsets.end(); ++iter, ++nextiter) {
 | 
|---|
 | 256 |             const double length = *nextiter - *iter;
 | 
|---|
 | 257 |             const double weight = bin.second * (length/binwidth);
 | 
|---|
 | 258 |             Bins_t::iterator filliter = getLowerEndBin(*iter);
 | 
|---|
 | 259 |             filliter->second += prefactor * weight;
 | 
|---|
 | 260 |           }
 | 
|---|
| [7d507c] | 261 |         }
 | 
|---|
| [22c4f57] | 262 | 
 | 
|---|
| [f856ec] | 263 |         LOG(4, "DEBUG: Bins are after summation " << printBins() << ".");
 | 
|---|
 | 264 |       }
 | 
|---|
| [22c4f57] | 265 |     }
 | 
|---|
 | 266 |   }
 | 
|---|
 | 267 | }
 | 
|---|
 | 268 | 
 | 
|---|
| [e561ff] | 269 | Histogram& Histogram::operator=(const Histogram &other)
 | 
|---|
 | 270 | {
 | 
|---|
 | 271 |   // check for self-assigment
 | 
|---|
 | 272 |   if (&other != this) {
 | 
|---|
 | 273 |     bins.clear();
 | 
|---|
 | 274 |     const_cast<BinLowerEnd &>(offset) = other.offset;
 | 
|---|
 | 275 |     const_cast<double &>(binwidth) = other.binwidth;
 | 
|---|
 | 276 |     bins.insert(other.bins.begin(), other.bins.end());
 | 
|---|
 | 277 |   }
 | 
|---|
 | 278 |   return *this;
 | 
|---|
 | 279 | }
 | 
|---|
 | 280 | 
 | 
|---|
| [c4fd03] | 281 | Histogram& Histogram::operator+=(const Histogram &other)
 | 
|---|
 | 282 | {
 | 
|---|
| [22c4f57] | 283 |   superposeOtherHistogram(other, +1.);
 | 
|---|
| [1b5a40] | 284 |   LOG(3, "DEBUG: Bins after addition are " << printBins() << ".");
 | 
|---|
| [c4fd03] | 285 |   return *this;
 | 
|---|
 | 286 | }
 | 
|---|
 | 287 | 
 | 
|---|
 | 288 | Histogram& Histogram::operator-=(const Histogram &other)
 | 
|---|
 | 289 | {
 | 
|---|
| [22c4f57] | 290 |   superposeOtherHistogram(other, -1.);
 | 
|---|
| [1b5a40] | 291 |   LOG(3, "DEBUG: Bins after subtraction are " << printBins() << ".");
 | 
|---|
| [c4fd03] | 292 |   return *this;
 | 
|---|
 | 293 | }
 | 
|---|
 | 294 | 
 | 
|---|
 | 295 | bool Histogram::isEmpty() const
 | 
|---|
 | 296 | {
 | 
|---|
 | 297 |   bool status = true;
 | 
|---|
 | 298 |   for (Bins_t::const_iterator iter = bins.begin(); iter != bins.end(); ++iter)
 | 
|---|
 | 299 |     status &= iter->second == 0;
 | 
|---|
 | 300 |   return status;
 | 
|---|
 | 301 | }
 | 
|---|
 | 302 | 
 | 
|---|
| [1c365e] | 303 | Histogram::Bins_t::iterator Histogram::getLowerEndBin(const double _value)
 | 
|---|
| [c4fd03] | 304 | {
 | 
|---|
| [1c365e] | 305 |   // lower bound returns key that is equal or greater
 | 
|---|
| [c4fd03] | 306 |   Bins_t::iterator iter = bins.lower_bound(_value);
 | 
|---|
 | 307 |   if (iter != bins.end()) {
 | 
|---|
| [1c365e] | 308 |     // if we are not on the boundary we always have to step back by one
 | 
|---|
 | 309 |     if (_value != iter->first) {
 | 
|---|
 | 310 |       if (iter != bins.begin()) {
 | 
|---|
 | 311 |           --iter;
 | 
|---|
 | 312 |       } else {
 | 
|---|
 | 313 |         iter = bins.end();
 | 
|---|
 | 314 |       }
 | 
|---|
 | 315 |     } else if (iter == --bins.end()) {
 | 
|---|
 | 316 |       // if we actually are on boundary of "last bin", set to end
 | 
|---|
| [c4fd03] | 317 |       iter = bins.end();
 | 
|---|
| [1c365e] | 318 |     }
 | 
|---|
 | 319 |   }
 | 
|---|
 | 320 |   return iter;
 | 
|---|
 | 321 | }
 | 
|---|
 | 322 | 
 | 
|---|
 | 323 | Histogram::Bins_t::iterator Histogram::getHigherEndBin(const double _value)
 | 
|---|
 | 324 | {
 | 
|---|
 | 325 |   // upper bound return key that is strictly greater
 | 
|---|
 | 326 |   Bins_t::iterator iter = bins.upper_bound(_value);
 | 
|---|
 | 327 |   // if we are on the boundary we have to step back by one
 | 
|---|
 | 328 |   if (iter != bins.end())
 | 
|---|
 | 329 |     if (_value == iter->first)
 | 
|---|
 | 330 |       if (iter != bins.begin())
 | 
|---|
 | 331 |           --iter;
 | 
|---|
| [c4fd03] | 332 | 
 | 
|---|
 | 333 |   return iter;
 | 
|---|
 | 334 | }
 | 
|---|
| [45f4f96] | 335 | 
 | 
|---|
| [1dd419] | 336 | Histogram::BinLowerEnd Histogram::getLowerEnd(const double _value) const
 | 
|---|
 | 337 | {
 | 
|---|
 | 338 |   BinLowerEnd start = _value - offset;
 | 
|---|
 | 339 |   // then divide by binwidth
 | 
|---|
 | 340 |   const int integral = floor(start/binwidth);
 | 
|---|
| [e11e23] | 341 |   //const double fraction = fmod(start,binwidth);
 | 
|---|
| [1dd419] | 342 |   start = offset + binwidth*integral;
 | 
|---|
 | 343 |   return start;
 | 
|---|
 | 344 | }
 | 
|---|
 | 345 | 
 | 
|---|
| [45f4f96] | 346 | double Histogram::area() const
 | 
|---|
 | 347 | {
 | 
|---|
 | 348 |   double area = 0.;
 | 
|---|
 | 349 |   for(Bins_t::const_iterator iter = bins.begin(); iter != bins.end(); ++iter)
 | 
|---|
 | 350 |     area += iter->second*binwidth;
 | 
|---|
 | 351 |   return area;
 | 
|---|
 | 352 | }
 | 
|---|
| [beb16e] | 353 | 
 | 
|---|
| [955051] | 354 | bool Histogram::operator==(const Histogram& other) const
 | 
|---|
 | 355 | {
 | 
|---|
 | 356 |   bool status = true;
 | 
|---|
 | 357 |   status &= binwidth == other.binwidth;
 | 
|---|
 | 358 |   status &= offset == other.offset;
 | 
|---|
 | 359 |   status &= bins == other.bins;
 | 
|---|
 | 360 |   return status;
 | 
|---|
 | 361 | }
 | 
|---|
 | 362 | 
 | 
|---|
| [beb16e] | 363 | template<> Histogram ZeroInstance<Histogram>()
 | 
|---|
 | 364 | {
 | 
|---|
 | 365 |   Histogram returnvalue;
 | 
|---|
 | 366 |   return returnvalue;
 | 
|---|
 | 367 | }
 | 
|---|