Bayeux  3.4.1
Core Foundation library for SuperNEMO
histogram.h
Go to the documentation of this file.
1 
3 #ifndef MYGSL_HISTOGRAM_H
4 #define MYGSL_HISTOGRAM_H 1
5 
6 // Standard library:
7 #include <iostream>
8 #include <vector>
9 
10 // Third party:
11 // - GSL:
12 #include <gsl/gsl_histogram.h>
13 #include <gsl/gsl_vector.h>
14 // - Boost:
15 #include <boost/cstdint.hpp>
16 // - Bayeux/datatools :
18 #include <datatools/properties.h>
19 #include <datatools/i_tree_dump.h>
20 
21 // This project:
22 #include <mygsl/histogram_utils.h>
23 
24 namespace mygsl {
25 
26  // Forward declaration:
27  class histogram_2d;
28 
30  class histogram :
33  {
34  public:
35 
36  const datatools::properties & get_auxiliaries () const;
37 
39 
40  double get_binning_info () const;
41 
42  bool is_uniform_binning () const;
43 
44  bool is_logarithmic_binning () const;
45 
46  bool is_any_binning () const;
47 
48  double get_uniform_binning () const;
49 
50  double get_logarithmic_binning () const;
51 
52  bool is_initialized () const;
53 
54  void initialize (size_t n_, double min_, double max_,
55  unsigned int mode_ = BIN_MODE_LINEAR);
56 
57  void init (const std::vector<double> & ranges_);
58 
59  void initialize (const std::vector<double> & ranges_);
60 
61  void initialize (const histogram & h_,
62  const std::vector<std::string> & imported_aux_prefixes_);
63 
64  void initialize (const histogram_2d & h_, int bin_axis_,
65  const std::vector<std::string> & imported_aux_prefixes_);
66 
67  void init (size_t n_, double min_, double max_,
68  unsigned int mode_ = BIN_MODE_LINEAR);
69 
71  void destroy ();
72 
73  histogram ();
74 
75  histogram (size_t n_, double min_, double max_,
76  unsigned int mode_ = BIN_MODE_LINEAR);
77 
78  histogram (const std::vector<double> & ranges_);
79 
80  virtual ~histogram ();
81 
82  histogram (const histogram &);
83 
84  histogram & operator= (const histogram &);
85 
86  bool is_inside (double x_) const;
87 
88  void accumulate (double x_ , double weight_ = 1.0);
89 
90  void fill (double x_ , double weight_ = 1.0);
91 
92  void fill (int i_ , double safe_delta_ = 1e-7, double weight_ = 1.0);
93 
94  void set (size_t i_, double value_);
95 
96  double underflow () const;
97 
98  double overflow () const;
99 
100  double min () const;
101 
102  double max () const;
103 
104  size_t bins () const;
105 
106  double get (size_t i_) const;
107 
108  double at (size_t i_) const;
109 
110  double operator[] (size_t i_) const;
111 
112  bool find (double x_ , size_t & i_) const;
113 
115  void reset ();
116 
117  bool can_rebin (size_t new_bins_) const;
118 
119  void rebin (size_t new_bins_);
120 
121  bool are_underflow_overflow_available () const;
122 
124 
125  void reset_underflow_overflow ();
126 
127  void increment_underflow (double weight_);
128 
129  void increment_overflow (double weight_);
130 
131  bool is_counts_available () const;
132 
133  int32_t counts () const;
134 
135  void invalidate_counters ();
136 
137  void reset_counters ();
138 
139  void reset_counts ();
140 
141  void increment_counts ();
142 
143  void invalidate_counts ();
144 
145  double min_val () const;
146 
147  double max_val () const;
148 
149  size_t min_bin () const;
150 
151  size_t max_bin () const;
152 
153  double mean () const;
154 
155  double sigma () const;
156 
157  double sum () const;
158 
159  double sum (size_t begin_, size_t end_) const;
160 
161  void to_stream (std::ostream &) const;
162 
163  void from_stream (std::istream &);
164 
165  void print (std::ostream & , int precision_ = 9) const;
166 
167  void print_ascii (std::ostream & , int mode_ = 0) const;
168 
169  void dump (std::ostream & , int precision_ = 9) const;
170 
171  bool has_size (size_t bins_) const;
172 
173  std::pair<double,double> get_range (size_t i_) const;
174 
175  void shift (double s_);
176 
177  void scale (double s_);
178 
179  void negate ();
180 
181  void zero ();
182 
183  bool same (const histogram &) const;
184 
185  void add (const histogram &);
186 
187  void sub (const histogram &);
188 
189  void mul (const histogram &);
190 
191  void div (const histogram &);
192 
193  histogram & operator+= (const histogram &);
194 
195  histogram & operator-= (const histogram &);
196 
197  histogram & operator*= (const histogram &);
198 
199  histogram & operator/= (const histogram &);
200 
201  histogram & operator+= (double);
202 
203  histogram & operator-= (double);
204 
205  histogram & operator- ();
206 
207  histogram & operator*= (double);
208 
209  histogram & operator/= (double);
210 
211  friend histogram operator+ (const histogram & ,
212  const histogram &);
213 
214  friend histogram operator- (const histogram & ,
215  const histogram &);
216 
217  friend histogram operator* (const histogram & ,
218  const histogram &);
219 
220  friend histogram operator/ (const histogram & ,
221  const histogram &);
222 
223  friend histogram operator* (double ,
224  const histogram &);
225 
226  friend histogram operator* (const histogram & ,
227  double);
228 
229  friend histogram operator/ (const histogram & ,
230  double);
231 
233  virtual void tree_dump (std::ostream& out = std::clog,
234  const std::string& title = "",
235  const std::string& indent = "",
236  bool inherit = false) const;
237 
238  private:
239 
240  double _binning_info_;
241  int32_t _counts_;
242  double _underflow_;
243  double _overflow_;
244  gsl_histogram * _h_;
245  datatools::properties _auxiliaries_;
246 
248 
249  public:
250 
252  class pdf
253  {
254 
255  public:
256 
257  pdf ();
258 
259  pdf (const histogram & h_);
260 
261  virtual ~pdf ();
262 
263  bool is_initialized () const;
264 
265  void initialize (const histogram & h_);
266 
267  void init (const histogram & h_);
268 
269  void reset ();
270 
271  double sample (double r_);
272 
273  void sample (double r_, double & x_);
274 
275  template<class _ran_functor_type>
276  double sample (_ran_functor_type & ran_)
277  {
278  return gsl_histogram_pdf_sample (_pdf_, ran_());
279  }
280 
281  private:
282 
283  gsl_histogram_pdf * _pdf_;
284 
285  };
286 
287  };
288 
290 
291 } // end of namespace mygsl
292 
293 #endif // MYGSL_HISTOGRAM_H
294 
295 /* Local Variables: */
296 /* mode: c++ */
297 /* coding: utf-8 */
298 /* End: */
void print_ascii(std::ostream &, int mode_=0) const
double sample(double r_)
virtual ~histogram()
double overflow() const
histogram & operator *=(const histogram &)
Base abstract class of all serializable (and possibly introspectable) classes.
Definition: i_serializable.h:51
histogram & operator/=(const histogram &)
double max() const
void reset()
Reset the bin contents to zero.
double at(size_t i_) const
datatools::properties & grab_auxiliaries()
void invalidate_counts()
double get_logarithmic_binning() const
friend histogram operator+(const histogram &, const histogram &)
void add(const histogram &)
void div(const histogram &)
histogram & operator=(const histogram &)
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
size_t max_bin() const
void reset_underflow_overflow()
bool is_logarithmic_binning() const
double underflow() const
friend histogram operator *(const histogram &, const histogram &)
bool find(double x_, size_t &i_) const
void mul(const histogram &)
bool has_size(size_t bins_) const
double mean() const
void dump(std::ostream &, int precision_=9) const
const datatools::properties & get_auxiliaries() const
#define DATATOOLS_SERIALIZATION_DECLARATION()
Definition: i_serializable.h:266
void set(size_t i_, double value_)
void rebin(size_t new_bins_)
histogram & operator+=(const histogram &)
double min_val() const
void to_stream(std::ostream &) const
void invalidate_underflow_overflow()
void sub(const histogram &)
int32_t counts() const
void fill(double x_, double weight_=1.0)
histogram histogram_1d
Definition: histogram.h:289
double sigma() const
double get_binning_info() const
bool can_rebin(size_t new_bins_) const
double min() const
double sum() const
void destroy()
Destroy the histogram structure, making the histogram invalid.
bool is_initialized() const
size_t min_bin() const
double sample(_ran_functor_type &ran_)
Definition: histogram.h:276
bool is_uniform_binning() const
histogram & operator-()
histogram & operator-=(const histogram &)
void init(const std::vector< double > &ranges_)
double get(size_t i_) const
double get_uniform_binning() const
virtual void tree_dump(std::ostream &out=std::clog, const std::string &title="", const std::string &indent="", bool inherit=false) const
Main interface method for smart dump.
void increment_underflow(double weight_)
friend histogram operator/(const histogram &, const histogram &)
void increment_counts()
One dimensional histogram.
Definition: histogram.h:30
double operator[](size_t i_) const
void scale(double s_)
void increment_overflow(double weight_)
bool is_any_binning() const
void invalidate_counters()
Top-level namespace of the Bayeux/mygsl module library.
Definition: base_decay_driver.h:47
PDF associated to a one dimensional histogram.
Definition: histogram.h:252
bool is_inside(double x_) const
void init(const histogram &h_)
void shift(double s_)
std::pair< double, double > get_range(size_t i_) const
bool is_counts_available() const
void initialize(size_t n_, double min_, double max_, unsigned int mode_=BIN_MODE_LINEAR)
Linear.
Definition: histogram_utils.h:11
void from_stream(std::istream &)
bool same(const histogram &) const
double max_val() const
void initialize(const histogram &h_)
bool are_underflow_overflow_available() const
void accumulate(double x_, double weight_=1.0)
bool is_initialized() const
void print(std::ostream &, int precision_=9) const
size_t bins() const
A dictionary of arbitrary properties.
Definition: properties.h:125
Two dimensional histogram.
Definition: histogram_2d.h:29