yat  0.12.3pre
Histogram.h
1 #ifndef _theplu_yat_statistics_histogram_
2 #define _theplu_yat_statistics_histogram_
3 
4 // $Id: Histogram.h 2333 2010-10-15 00:44:23Z peter $
5 
6 /*
7  Copyright (C) 2004 Jari Häkkinen
8  Copyright (C) 2005 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2006 Jari Häkkinen
10  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
11  Copyright (C) 2009, 2010 Peter Johansson
12 
13  This file is part of the yat library, http://dev.thep.lu.se/yat
14 
15  The yat library is free software; you can redistribute it and/or
16  modify it under the terms of the GNU General Public License as
17  published by the Free Software Foundation; either version 3 of the
18  License, or (at your option) any later version.
19 
20  The yat library is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  General Public License for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with yat. If not, see <http://www.gnu.org/licenses/>.
27 */
28 
29 #include "AveragerWeighted.h"
30 #include "yat/utility/concept_check.h"
31 #include "yat/utility/iterator_traits.h"
32 
33 #include <boost/concept_check.hpp>
34 
35 #include <iosfwd>
36 #include <string>
37 #include <vector>
38 
39 namespace theplu {
40 namespace yat {
41 namespace statistics {
42 
52  class Histogram
53  {
54  public:
55 
59  Histogram(void);
60 
74  Histogram(std::istream&);
75 
79  Histogram(const Histogram&);
80 
85  Histogram(const double xmin, const double xmax, const size_t n);
86 
87  virtual ~Histogram(void);
88 
102  int add(const double x,const double weight=1.0);
103 
112  const AveragerWeighted& averager_all(void) const;
113 
123  const AveragerWeighted& averager_histogram(void) const;
124 
128  size_t nof_bins(void) const;
129 
156  void normalize(bool choice = true);
157 
164  double observation_value(const size_t k) const;
165 
171  void rescale(double factor);
172 
177  void reset(void);
178 
182  double spacing(void) const;
183 
189  double xmax(void) const;
190 
196  double xmin(void) const;
197 
201  double operator[](size_t k) const;
202 
206  const Histogram& operator=(const Histogram&);
207 
216  const Histogram& operator+=(const Histogram& rhs);
217 
218  private:
219  // Returns zero if outside boundaries
220  size_t bin(double d);
221 
222  std::vector<double> histogram_;
223  double xmax_;
224  double xmin_;
225  statistics::AveragerWeighted sum_all_; // average of all data
226  statistics::AveragerWeighted sum_histogram_;// average of data in histogram
227  };
228 
236  template<typename ForwardIterator>
237  void add(Histogram& h,
238  ForwardIterator first, ForwardIterator last)
239  {
240  BOOST_CONCEPT_ASSERT((boost::ForwardIterator<ForwardIterator>));
241  BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<ForwardIterator>));
243  while (first!=last) {
244  h.add(traits.data(first), traits.weight(first));
245  ++first;
246  }
247  }
248 
254  std::ostream& operator<<(std::ostream& s,const Histogram&);
255 
256 }}} // of namespace statistics, yat, and theplu
257 
258 #endif
void normalize(bool choice=true)
Normalizing the histogram.
data_reference data(Iter iter) const
Definition: iterator_traits.h:434
Concept check for Data Iterator.
Definition: concept_check.h:224
Definition: iterator_traits.h:406
int add(const double x, const double weight=1.0)
Add a data point to the histogram.
Class to calulate averages with weights.
Definition: AveragerWeighted.h:65
const Histogram & operator=(const Histogram &)
double operator[](size_t k) const
void add(Histogram &h, ForwardIterator first, ForwardIterator last)
Definition: Histogram.h:237
double observation_value(const size_t k) const
Histograms provide a convenient way of presenting the distribution of a set of data.
Definition: Histogram.h:52
weight_reference weight(Iter iter) const
Definition: iterator_traits.h:440
const Histogram & operator+=(const Histogram &rhs)
Addition operator.
const AveragerWeighted & averager_histogram(void) const
Average of events fitting within histogram.
const AveragerWeighted & averager_all(void) const
Average of all events presented to the histogram.

Generated on Mon Jun 1 2015 12:29:52 for yat by  doxygen 1.8.5