yat  0.21pre
Histogram.h
1 #ifndef _theplu_yat_statistics_histogram_
2 #define _theplu_yat_statistics_histogram_
3 
4 // $Id: Histogram.h 4207 2022-08-26 04:36:28Z 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, 2016, 2022 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 #include <boost/iterator/iterator_concepts.hpp>
35 
36 #include <iosfwd>
37 #include <string>
38 #include <vector>
39 
40 namespace theplu {
41 namespace yat {
42 namespace statistics {
43 
53  class Histogram
54  {
55  public:
56 
60  Histogram(void);
61 
75  Histogram(std::istream&);
76 
80  Histogram(const Histogram&);
81 
86  Histogram(const double xmin, const double xmax, const size_t n);
87 
88  virtual ~Histogram(void);
89 
103  int add(const double x,const double weight=1.0);
104 
113  const AveragerWeighted& averager_all(void) const;
114 
124  const AveragerWeighted& averager_histogram(void) const;
125 
129  size_t nof_bins(void) const;
130 
157  void normalize(bool choice = true);
158 
165  double observation_value(const size_t k) const;
166 
172  void rescale(double factor);
173 
178  void reset(void);
179 
183  double spacing(void) const;
184 
190  double xmax(void) const;
191 
197  double xmin(void) const;
198 
202  double operator[](size_t k) const;
203 
207  const Histogram& operator=(const Histogram&);
208 
217  const Histogram& operator+=(const Histogram& rhs);
218 
219  private:
220  // Returns zero if outside boundaries
221  size_t bin(double d);
222 
223  std::vector<double> histogram_;
224  double xmax_;
225  double xmin_;
226  statistics::AveragerWeighted sum_all_; // average of all data
227  statistics::AveragerWeighted sum_histogram_;// average of data in histogram
228  };
229 
239  template<typename Iterator>
240  void add(Histogram& h, Iterator first, Iterator last)
241  {
242  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<Iterator>));
243  BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<Iterator>));
245  while (first!=last) {
246  h.add(traits.data(first), traits.weight(first));
247  ++first;
248  }
249  }
250 
256  std::ostream& operator<<(std::ostream& s,const Histogram&);
257 
258 }}} // of namespace statistics, yat, and theplu
259 
260 #endif
void add(Histogram &h, Iterator first, Iterator last)
Definition: Histogram.h:240
void normalize(bool choice=true)
Normalizing the histogram.
Concept check for Data Iterator.
Definition: concept_check.h:240
data_reference data(Iter iter) const
Definition: iterator_traits.h:440
Definition: iterator_traits.h:412
The Department of Theoretical Physics namespace as we define it.
double operator[](size_t k) const
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:66
const Histogram & operator=(const Histogram &)
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.
Histograms provide a convenient way of presenting the distribution of a set of data.
Definition: Histogram.h:53
const Histogram & operator+=(const Histogram &rhs)
Addition operator.
double observation_value(const size_t k) const
weight_reference weight(Iter iter) const
Definition: iterator_traits.h:446

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14