Bayeux  3.4.1
Core Foundation library for SuperNEMO
histogram_2d.h
Go to the documentation of this file.
1 
3 #ifndef MYGSL_HISTOGRAM_2D_H
4 #define MYGSL_HISTOGRAM_2D_H 1
5 
6 // Standard library:
7 #include <iostream>
8 #include <vector>
9 
10 // Third party:
11 // - GSL:
12 #include <gsl/gsl_histogram2d.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  class histogram;
27 
30  {
31  public:
32 
33  friend class histogram;
34 
35  const datatools::properties & get_auxiliaries () const;
36 
38 
39  double get_x_binning_info () const;
40 
41  double get_y_binning_info () const;
42 
43  bool is_uniform_x_binning () const;
44 
45  bool is_logarithmic_x_binning () const;
46 
47  bool is_any_x_binning () const;
48 
49  double get_uniform_x_binning () const;
50 
51  double get_logarithmic_x_binning () const;
52 
53  bool is_uniform_y_binning () const;
54 
55  bool is_logarithmic_y_binning () const;
56 
57  bool is_any_y_binning () const;
58 
59  double get_uniform_y_binning () const;
60 
61  double get_logarithmic_y_binning () const;
62 
63  bool is_initialized () const;
64 
65  void initialize (size_t nx_, double xmin_, double xmax_,
66  size_t ny_, double ymin_, double ymax_,
67  unsigned int xmode_ = BIN_MODE_LINEAR,
68  unsigned int ymode_ = BIN_MODE_LINEAR);
69 
70  void initialize (const std::vector<double> & xranges_,
71  const std::vector<double> & yranges_);
72 
73  void initialize (const histogram & hx_, const histogram & hy_,
74  const std::vector<std::string> & imported_aux_prefixes_);
75 
76  void initialize (const histogram_2d & h_,
77  const std::vector<std::string> & imported_aux_prefixes_);
78 
79  void init (size_t nx_, double xmin_, double xmax_,
80  size_t ny_, double ymin_, double ymax_,
81  unsigned int xmode_ = BIN_MODE_LINEAR,
82  unsigned int ymode_ = BIN_MODE_LINEAR);
83 
84  void init (const std::vector<double> & xranges_,
85  const std::vector<double> & yranges_);
86 
88  void destroy ();
89 
91 
93 
95 
96  void increment_x_underflow (double weight_);
97 
98  void increment_x_overflow (double weight_);
99 
100  void increment_y_underflow (double weight_);
101 
102  void increment_y_overflow (double weight_);
103 
104  void invalidate_counters ();
105 
106  void reset_counters ();
107 
108  bool is_counts_available () const;
109 
110  int32_t counts () const;
111 
112  void reset_counts ();
113 
114  void increment_counts ();
115 
116  void invalidate_counts ();
117 
118  histogram_2d ();
119 
120  histogram_2d (size_t nx_, double xmin_, double xmax_,
121  size_t ny_, double ymin_, double ymax_,
122  unsigned int xmode_ = BIN_MODE_LINEAR,
123  unsigned int ymode_ = BIN_MODE_LINEAR);
124 
125  histogram_2d (const std::vector<double> & xranges_,
126  const std::vector<double> & yranges_);
127 
128  virtual ~histogram_2d ();
129 
130  histogram_2d (const histogram_2d &);
131 
133 
134  bool is_inside (double x_, double y_) const;
135 
136  void accumulate (double x_, double y_, double weight_ = 1.0);
137 
138  void fill (double x_, double y_, double weight_ = 1.0);
139 
140  void fill (int i_ , double y_, double safe_x_delta_ = 1e-7, double weight_ = 1.0);
141 
142  void fill (double x_, int j_, double safe_y_delta_ = 1e-7, double weight_ = 1.0);
143 
144  void fill (int i_, int j_,
145  double safe_x_delta_ = 1e-7, double safe_y_delta_ = 1e-7,
146  double weight_ = 1.0);
147 
148  double underflow_x () const;
149 
150  double overflow_x () const;
151 
152  double underflow_y () const;
153 
154  double overflow_y () const;
155 
156  double xmin () const;
157 
158  double xmax () const;
159 
160  double ymin () const;
161 
162  double ymax () const;
163 
164  size_t xbins () const;
165 
166  size_t ybins () const;
167 
168  void set (size_t ix_, size_t iy_, double value_);
169 
170  double get (size_t ix_, size_t iy_) const;
171 
172  double at (size_t ix_, size_t iy_) const;
173 
174  bool find (double x_, double y_, size_t & i_, size_t & j_) const;
175 
177  void reset ();
178 
179  double min_val () const;
180 
181  double max_val () const;
182 
183  void min_bin (size_t & i_, size_t & j_) const;
184 
185  void max_bin (size_t & i_, size_t & j_) const;
186 
187  double xmean () const;
188 
189  double xsigma () const;
190 
191  double ymean () const;
192 
193  double ysigma () const;
194 
195  double sum () const;
196 
197  double cov () const;
198 
199  void to_stream (std::ostream &) const;
200 
201  void from_stream (std::istream &);
202 
203  void print (std::ostream & ,
204  int precision_ = 9,
205  bool x_skip_line_ = true) const;
206 
207  void dump (std::ostream & , int precision_ = 9) const;
208 
209  bool has_size (size_t xbins_, size_t ybins_) const;
210 
211  bool has_xsize (size_t xbins_) const;
212 
213  bool has_ysize (size_t ybins_) const;
214 
215  std::pair<double,double> get_xrange (size_t i_) const;
216 
217  std::pair<double,double> get_yrange (size_t j_) const;
218 
219  void shift (double s_);
220 
221  void scale (double s_);
222 
223  void negate ();
224 
225  void zero ();
226 
227  bool same (const histogram_2d &) const;
228 
229  void add (const histogram_2d &);
230 
231  void sub (const histogram_2d &);
232 
233  void mul (const histogram_2d &);
234 
235  void div (const histogram_2d &);
236 
238 
240 
242 
244 
245  histogram_2d & operator+= (double);
246 
247  histogram_2d & operator-= (double);
248 
250 
251  histogram_2d & operator*= (double);
252 
253  histogram_2d & operator/= (double);
254 
255  friend histogram_2d operator+ (const histogram_2d & ,
256  const histogram_2d &);
257 
258  friend histogram_2d operator- (const histogram_2d & ,
259  const histogram_2d &);
260 
261  friend histogram_2d operator* (const histogram_2d & ,
262  const histogram_2d &);
263 
264  friend histogram_2d operator/ (const histogram_2d & ,
265  const histogram_2d &);
266 
267  friend histogram_2d operator* (double ,
268  const histogram_2d &);
269 
270  friend histogram_2d operator/ (double ,
271  const histogram_2d &);
272 
273  friend histogram_2d operator* (const histogram_2d & ,
274  double);
275 
276  friend histogram_2d operator/ (const histogram_2d & ,
277  double);
278 
280  virtual void tree_dump (std::ostream & out = std::clog,
281  const std::string & title = "",
282  const std::string & indent = "",
283  bool inherit = false) const;
284 
285  private:
286 
287  double _x_binning_info_;
288  double _y_binning_info_;
289  int32_t _counts_;
290  double _x_underflow_;
291  double _x_overflow_;
292  double _y_underflow_;
293  double _y_overflow_;
294  gsl_histogram2d * _h_; // bin(i,j) = bin[i * ny + j].
295  datatools::properties _auxiliaries_;
296 
298 
299  public:
300 
301  class pdf
302  {
303 
304  public:
305 
306  pdf ();
307 
308  pdf (const histogram_2d & h_);
309 
310  virtual ~pdf ();
311 
312  bool is_initialized () const;
313 
314  void initialize (const histogram_2d & h_);
315 
316  void init (const histogram_2d & h_);
317 
318  void reset ();
319 
320  void sample (double r1_, double r2_, double & x_, double & y_);
321 
322  template<class _ran_functor_t>
323  void sample (_ran_functor_t & ran_, double & x_, double & y_)
324  {
325  return gsl_histogram_pdf_sample (_pdf_, ran_(), ran_(), &x_, &y_);
326  }
327 
328  private:
329 
330  gsl_histogram2d_pdf * _pdf_;
331 
332  };
333 
334  };
335 
336 } // end of namespace mygsl
337 
338 #endif // MYGSL_HISTOGRAM_2D_H
339 
340 /* Local Variables: */
341 /* mode: c++ */
342 /* coding: utf-8 */
343 /* End: */
void increment_x_overflow(double weight_)
void add(const histogram_2d &)
void sub(const histogram_2d &)
Base abstract class of all serializable (and possibly introspectable) classes.
Definition: i_serializable.h:51
bool same(const histogram_2d &) const
double get_y_binning_info() const
bool are_underflow_overflow_available() const
double overflow_y() const
void print(std::ostream &, int precision_=9, bool x_skip_line_=true) const
friend histogram_2d operator+(const histogram_2d &, const histogram_2d &)
bool is_logarithmic_y_binning() const
double ysigma() const
void invalidate_underflow_overflow()
void max_bin(size_t &i_, size_t &j_) const
datatools::properties & grab_auxiliaries()
double get_x_binning_info() const
double xmin() const
void initialize(size_t nx_, double xmin_, double xmax_, size_t ny_, double ymin_, double ymax_, unsigned int xmode_=BIN_MODE_LINEAR, unsigned int ymode_=BIN_MODE_LINEAR)
bool is_inside(double x_, double y_) const
void shift(double s_)
const datatools::properties & get_auxiliaries() const
void div(const histogram_2d &)
void init(size_t nx_, double xmin_, double xmax_, size_t ny_, double ymin_, double ymax_, unsigned int xmode_=BIN_MODE_LINEAR, unsigned int ymode_=BIN_MODE_LINEAR)
double xsigma() const
histogram_2d & operator+=(const histogram_2d &)
#define DATATOOLS_SERIALIZATION_DECLARATION()
Definition: i_serializable.h:266
double get_uniform_y_binning() const
double get_uniform_x_binning() const
double xmax() const
void reset()
Reset the bin contents to zero.
std::pair< double, double > get_yrange(size_t j_) const
void scale(double s_)
size_t ybins() const
histogram_2d & operator-=(const histogram_2d &)
void min_bin(size_t &i_, size_t &j_) const
double cov() const
histogram_2d & operator *=(const histogram_2d &)
bool is_uniform_y_binning() const
double overflow_x() const
bool is_any_y_binning() const
friend histogram_2d operator *(const histogram_2d &, const histogram_2d &)
void reset_underflow_overflow()
double max_val() const
bool has_xsize(size_t xbins_) const
virtual ~histogram_2d()
std::pair< double, double > get_xrange(size_t i_) const
void dump(std::ostream &, int precision_=9) const
void increment_y_underflow(double weight_)
double get_logarithmic_y_binning() const
histogram_2d & operator=(const histogram_2d &)
void set(size_t ix_, size_t iy_, double value_)
bool is_any_x_binning() const
void destroy()
Destroy the histogram structure, making the histogram invalid.
void increment_x_underflow(double weight_)
bool is_logarithmic_x_binning() const
One dimensional histogram.
Definition: histogram.h:30
double at(size_t ix_, size_t iy_) const
size_t xbins() const
void to_stream(std::ostream &) const
void increment_y_overflow(double weight_)
void accumulate(double x_, double y_, double weight_=1.0)
double ymax() const
void fill(double x_, double y_, double weight_=1.0)
histogram_2d & operator/=(const histogram_2d &)
Top-level namespace of the Bayeux/mygsl module library.
Definition: base_decay_driver.h:47
bool has_size(size_t xbins_, size_t ybins_) const
double ymin() const
bool find(double x_, double y_, size_t &i_, size_t &j_) const
bool is_counts_available() const
double get(size_t ix_, size_t iy_) const
Linear.
Definition: histogram_utils.h:11
int32_t counts() const
double ymean() const
double sum() const
double underflow_x() const
double min_val() const
bool has_ysize(size_t ybins_) 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.
Definition: histogram_2d.h:301
double get_logarithmic_x_binning() const
double xmean() const
void mul(const histogram_2d &)
histogram_2d & operator-()
friend histogram_2d operator/(const histogram_2d &, const histogram_2d &)
double underflow_y() const
void sample(_ran_functor_t &ran_, double &x_, double &y_)
Definition: histogram_2d.h:323
void from_stream(std::istream &)
bool is_initialized() const
bool is_uniform_x_binning() const
A dictionary of arbitrary properties.
Definition: properties.h:125
Two dimensional histogram.
Definition: histogram_2d.h:29