source: trunk/src/histogram.cc @ 13

Last change on this file since 13 was 13, checked in by daniel, 20 years ago

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.3 KB
Line 
1#include "histogram.h"
2
3
4using namespace std;
5using namespace thep_cpp_tools;
6
7
8// Constructors and destructors
9////////////////////////////////
10histogram::histogram( const size_t& nbins, const double& min, const double& max )
11{
12  h_ = gsl_histogram_alloc( nbins );
13  gsl_histogram_set_ranges_uniform( h_, min, max );
14}
15
16
17histogram::~histogram()
18{
19  gsl_histogram_free( h_ );
20  if( p_ != NULL ) gsl_histogram_pdf_free( p_ );
21}
22
23
24// Functions (A-Z)
25//////////////////
26void histogram::init_probabilities()
27{
28  p_ = gsl_histogram_pdf_alloc( get_bins() );
29  gsl_histogram_pdf_init( p_, h_ );
30}
31
32
33void histogram::load_from_text_file( const string& filename )
34{
35  ifstream fin( filename.c_str() );
36  if( !fin ) { cerr << "No such file: " << filename << endl; exit( -1 ); }
37  while( fin.peek() != EOF )
38    {
39     double val, intensity;
40     fin >> val >> intensity;
41     assert( intensity >= 0 );
42     gsl_histogram_accumulate( h_, val, intensity );//intensity );
43    }
44}
45
46
47// Operators
48////////////
49std::ostream& 
50thep_cpp_tools::operator<< ( std::ostream& s_out, 
51           const thep_cpp_tools::histogram& hist )
52{
53  for( size_t i = 0; i < hist.get_bins(); ++i )
54    {
55     double low, high;
56     cout << i << endl;
57     hist.get_range( i, low, high );
58     s_out << "[ " << low << ", " << high << " ]\t=\t" 
59     << hist.get_intensity( i ) << endl;
60    }
61  return s_out;
62}
63
64
65
66
67
Note: See TracBrowser for help on using the repository browser.