Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.6dev
      Class Index
      File List
   Version 1.0.6
   Version 1.0.5new_solver
   Version 1.0.5dev
   Version 1.0.5b
   Version 1.0.4dev
   Version 1.0.4
Publications


Hosted by Get Ion Beam Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads
histogram.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2005-2011,2014 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 #ifndef HISTOGRAM_HPP
44 #define HISTOGRAM_HPP 1
45 
46 
47 #include <vector>
48 #include <stdint.h>
49 
50 
56 };
57 
58 
61 class Histogram
62 {
63 
64 public:
65 
68  virtual ~Histogram() {}
69 
70 };
71 
72 
75 class Histogram1D : public Histogram
76 {
77  uint32_t _n;
78  double _range[2];
79  double _step;
80  std::vector<double> _data;
82 public:
83 
86  Histogram1D( uint32_t n, const double range[2] );
87 
92  Histogram1D( uint32_t n, const std::vector<double> &xdata,
94 
99  Histogram1D( uint32_t n, const std::vector<double> &xdata, const std::vector<double> &wdata,
101 
104  virtual ~Histogram1D();
105 
108  uint32_t n( void ) const { return( _n ); }
109 
112  double step( void ) const { return( _step ); }
113 
116  double coord( uint32_t i ) const;
117 
122  void accumulate( uint32_t i, double weight ) {
123  _data[i] += weight;
124  }
125 
130  void accumulate( uint32_t i ) {
131  _data[i] += 1.0;
132  }
133 
136  void accumulate_closest( double x, double weight = 1.0 );
137 
141  void accumulate_closest( const std::vector<double> &xdata );
142 
146  void accumulate_closest( const std::vector<double> &xdata,
147  const std::vector<double> &wdata );
148 
158  void accumulate_linear( double x, double weight = 1.0 );
159 
163  void accumulate_linear( const std::vector<double> &xdata );
164 
168  void accumulate_linear( const std::vector<double> &xdata,
169  const std::vector<double> &wdata );
170 
176  void convert_to_density( void );
177 
180  void get_range( double range[2] ) const;
181 
186  void get_bin_range( double &min, double &max ) const;
187 
190  std::vector<double> &get_data( void ) { return( _data ); }
191 
194  const std::vector<double> &get_data( void ) const { return( _data ); }
195 
198  const double &operator()( uint32_t i ) const {
199  return( _data[i] );
200  }
201 
204  double &operator()( uint32_t i ) {
205  return( _data[i] );
206  }
207 
210  const Histogram1D &operator*=( double x );
211 };
212 
213 
216 class Histogram2D : public Histogram
217 {
218  uint32_t _n;
219  uint32_t _m;
220  double _range[4];
221  double _nstep;
222  double _mstep;
223  std::vector<double> _data;
225 public:
226 
229  Histogram2D( uint32_t n, uint32_t m, const double range[4] );
230 
235  Histogram2D( uint32_t n, uint32_t m,
236  const std::vector<double> &xdata,
237  const std::vector<double> &ydata,
239 
244  Histogram2D( uint32_t n, uint32_t m,
245  const std::vector<double> &xdata,
246  const std::vector<double> &ydata,
247  const std::vector<double> &wdata,
249 
252  virtual ~Histogram2D();
253 
256  uint32_t n( void ) const { return( _n ); }
257 
260  uint32_t m( void ) const { return( _m ); }
261 
264  double nstep( void ) const { return( _nstep ); }
265 
268  double mstep( void ) const { return( _mstep ); }
269 
272  double icoord( uint32_t i ) const;
273 
276  double jcoord( uint32_t j ) const;
277 
282  void accumulate( uint32_t i, uint32_t j, double weight ) {
283  _data[i+j*_n] += weight;
284  }
285 
288  void accumulate_closest( double x, double y, double weight );
289 
299  void accumulate_linear( double x, double y, double weight );
300 
306  void convert_to_density( void );
307 
310  void get_range( double range[4] ) const;
311 
316  void get_bin_range( double &min, double &max ) const;
317 
322  std::vector<double> &get_data( void ) { return( _data ); }
323 
328  const std::vector<double> &get_data( void ) const { return( _data ); }
329 
332  const double &operator()( uint32_t i, uint32_t j ) const {
333  return( _data[i+j*_n] );
334  }
335 
338  double &operator()( uint32_t i, uint32_t j ) {
339  return( _data[i+j*_n] );
340  }
341 
344  const Histogram2D &operator*=( double x );
345 };
346 
347 
348 #endif
349 
Class for 1D histogram type representation of data.
Definition: histogram.hpp:76
double & operator()(uint32_t i)
Return a reference to the weight on bin i.
Definition: histogram.hpp:204
void get_bin_range(double &min, double &max) const
Return bin range.
Definition: histogram.cpp:185
virtual ~Histogram1D()
Destructor.
Definition: histogram.cpp:179
const std::vector< double > & get_data(void) const
Return a reference to the histogram data.
Definition: histogram.hpp:194
void accumulate_linear(double x, double weight=1.0)
Accumulate weight on bins around x linearly.
Definition: histogram.cpp:242
double step(void) const
Return the step size.
Definition: histogram.hpp:112
void get_range(double range[2]) const
Return data range.
Definition: histogram.cpp:271
void accumulate(uint32_t i)
Accumulate unity weight on bin i.
Definition: histogram.hpp:130
const Histogram1D & operator*=(double x)
Scale histogram.
Definition: histogram.cpp:287
double coord(uint32_t i) const
Return the coordinate on bin i.
Definition: histogram.cpp:265
void accumulate_closest(double x, double weight=1.0)
Accumulate weight to closest bin to x.
Definition: histogram.cpp:199
const double & operator()(uint32_t i) const
Return a const reference to the weight on bin i.
Definition: histogram.hpp:198
Histogram1D(uint32_t n, const double range[2])
Constructor for n bin histogram with ranges.
Definition: histogram.cpp:51
std::vector< double > & get_data(void)
Return a reference to the histogram data.
Definition: histogram.hpp:190
void accumulate(uint32_t i, double weight)
Accumulate weight on bin i.
Definition: histogram.hpp:122
uint32_t n(void) const
Return the number of bins.
Definition: histogram.hpp:108
void convert_to_density(void)
Convert histogram to density.
Definition: histogram.cpp:278
Class for 2d histogram type representation of data.
Definition: histogram.hpp:217
virtual ~Histogram2D()
Destructor.
Definition: histogram.cpp:485
void accumulate_closest(double x, double y, double weight)
Accumulate weight to closest bin to (x,y).
Definition: histogram.cpp:547
void get_bin_range(double &min, double &max) const
Return bin range.
Definition: histogram.cpp:532
double jcoord(uint32_t j) const
Return the coordinate along the second axis on bin j.
Definition: histogram.cpp:497
const Histogram2D & operator*=(double x)
Scale histogram.
Definition: histogram.cpp:521
uint32_t m(void) const
Return the number of bins along the second axis.
Definition: histogram.hpp:260
void accumulate(uint32_t i, uint32_t j, double weight)
Accumulate weight on bin (i,j).
Definition: histogram.hpp:282
double icoord(uint32_t i) const
Return the coordinate along the first axis on bin i.
Definition: histogram.cpp:491
const std::vector< double > & get_data(void) const
Return a reference to the histogram data.
Definition: histogram.hpp:328
Histogram2D(uint32_t n, uint32_t m, const double range[4])
Constructor for n x m histogram with ranges.
Definition: histogram.cpp:304
const double & operator()(uint32_t i, uint32_t j) const
Return a const reference to the weight on bin (i,j).
Definition: histogram.hpp:332
void convert_to_density(void)
Convert histogram to density.
Definition: histogram.cpp:512
double nstep(void) const
Return the step size along along the first axis.
Definition: histogram.hpp:264
double & operator()(uint32_t i, uint32_t j)
Return a reference to the weight on bin (i,j).
Definition: histogram.hpp:338
uint32_t n(void) const
Return the number of bins along the first axis.
Definition: histogram.hpp:256
double mstep(void) const
Return the step size along along the second axis.
Definition: histogram.hpp:268
void get_range(double range[4]) const
Return data range.
Definition: histogram.cpp:503
std::vector< double > & get_data(void)
Return a reference to the histogram data.
Definition: histogram.hpp:322
void accumulate_linear(double x, double y, double weight)
Accumulate weight on bins around (x,y) linearly.
Definition: histogram.cpp:558
Base histogram class.
Definition: histogram.hpp:62
virtual ~Histogram()
Destructor.
Definition: histogram.hpp:68
histogram_accumulation_e
Histogram accumulation type.
Definition: histogram.hpp:53
@ HISTOGRAM_ACCUMULATION_CLOSEST
Closest bin to point.
Definition: histogram.hpp:54
@ HISTOGRAM_ACCUMULATION_LINEAR
Linear accumulation around point.
Definition: histogram.hpp:55


Reference manual for Ion Beam Simulator 1.0.6dev
Generated by Doxygen 1.9.1 on Thu Sep 11 2025 09:37:24.