CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
cbl::glob::Histogram2D Class Reference

The class Histogram2D. More...

#include "Headers/Histogram.h"

Inheritance diagram for cbl::glob::Histogram2D:
Collaboration diagram for cbl::glob::Histogram2D:

Public Member Functions

Constructors/destructors
 Histogram2D ()=default
 default constructor
 
 Histogram2D (const std::vector< double > var1, const std::vector< double > var2, const std::vector< double > weight, const size_t nbins1, const size_t nbins2, const double minVar1=par::defaultDouble, const double maxVar1=par::defaultDouble, const double minVar2=par::defaultDouble, const double maxVar2=par::defaultDouble, const double shift1=0.5, const double shift2=0.5, const BinType bin_type1=BinType::_linear_, const BinType bin_type2=BinType::_linear_)
 constructor More...
 
 ~Histogram2D ()=default
 default destructor
 
Functions to set the private members of the class
void set (const size_t nbins1, const size_t nbins2, const double minVar1=par::defaultDouble, const double maxVar1=par::defaultDouble, const double minVar2=par::defaultDouble, const double maxVar2=par::defaultDouble, const double shift1=0.5, const double shift2=0.5, const BinType bin_type1=BinType::_linear_, const BinType bin_type2=BinType::_linear_, const std::vector< double > vec_edges1={}, const std::vector< double > vec_edges2={}) override
 set the histogram variables More...
 
std::vector< int > digitize (const double var1, const double var2) override
 get the histogram index More...
 
std::vector< std::vector< int > > digitize (const std::vector< double > var1, const std::vector< double > var2) override
 get the histogram indeces More...
 
void put (const double var1, const double var2, const double weight) override
 bin the data More...
 
void put (const std::vector< double > var1, const std::vector< double > var2, const std::vector< double > weight) override
 bin the data More...
 
void put (const int bin1, const int bin2, const double weight, const double var1, const double var2) override
 bin the data More...
 
void put (const std::vector< std::vector< int >> bins, const std::vector< double > weight, const std::vector< double > var1, const std::vector< double > var2) override
 bin the data More...
 
Functions to get the private members of the class
size_t nbins1 () const override
 return the number of bins for the first variable More...
 
double binSize1 () const override
 return the bin size for the first variable More...
 
double minVar1 () const override
 return the lower limit of the histogram for the first variable More...
 
double maxVar1 () const override
 return the upper limit of the histogram for the first variable More...
 
double shift1 () const override
 return the bin shift for the first variable More...
 
BinType bin_type1 () const override
 return the bin type for the first variable More...
 
size_t nbins2 () const override
 return the number of bins for the second variable More...
 
double binSize2 () const override
 return the bin size for the second variable More...
 
double minVar2 () const override
 return the lower limit of the histogram for the second variable More...
 
double maxVar2 () const override
 return the upper limit of the histogram for the second variable More...
 
double shift2 () const override
 return the bin shift for the second variable More...
 
BinType bin_type2 () const override
 return the bin type for the second variable More...
 
double bin1 (const size_t i) const override
 return the i-th bin of the first variable More...
 
std::vector< double > bins1 () const override
 return the first variable bins More...
 
std::vector< std::vector< double > > averaged_bins1 () const
 return the averaged bins More...
 
std::vector< std::vector< double > > averaged_bins2 () const
 return the averaged bins More...
 
std::vector< std::vector< double > > error_bins1 () const
 return the averaged bins More...
 
std::vector< std::vector< double > > error_bins2 () const
 return the averaged bins More...
 
double edge1 (const size_t i) const override
 return the i-th edge of the first variable More...
 
std::vector< double > edges1 () const override
 return the histogram edges of the first variable More...
 
double bin2 (const size_t i) const override
 return the i-th bin of the second variable More...
 
std::vector< double > bins2 () const override
 return the second variable bins More...
 
double edge2 (const size_t i) const override
 return the i-th edge of the second variable More...
 
std::vector< double > edges2 () const override
 return the histogram edges of the second variable More...
 
double normalization (const int i, const int j, const HistogramType hist_type, const double fact=1.) const override
 return the bin normalization More...
 
int unweighted_counts (const int i, const int j) const override
 return the bin unweighted counts More...
 
double operator() (const int i, const int j, const HistogramType hist_type, const double fact=1.) const override
 return the histogram at (i,j) More...
 
double error (const int i, const int j, const HistogramType hist_type, const double fact=1.) const override
 return the poisson error of the histogram at (i,j) More...
 
input/output member functions (customized in all the derived classes)
void write (const std::string dir, const std::string file, const HistogramType hist_type, const double fact=1.) const override
 write the histogram More...
 
- Public Member Functions inherited from cbl::glob::Histogram
 Histogram ()=default
 default constructor
 
 ~Histogram ()=default
 default destructor
 
virtual void set (const size_t nbins, const double minVar=par::defaultDouble, const double maxVar=par::defaultDouble, const double shift=0.5, const BinType bin_type=BinType::_linear_, const std::vector< double > vec_edges={})
 set the histogram variables More...
 
virtual int digitize (const double var)
 get the histogram index More...
 
virtual std::vector< int > digitize (const std::vector< double > var)
 get the histogram indeces More...
 
virtual void put (const double var, const double weight)
 bin the data More...
 
virtual void put (const std::vector< double > var, const std::vector< double > weight)
 bin the data More...
 
virtual void put (const int bin, const double weight, const double var)
 bin the data More...
 
virtual void put (const std::vector< int > bins, const std::vector< double > weight, const std::vector< double > var)
 bin the data More...
 
virtual size_t nbins () const
 return the number of bins More...
 
virtual double binSize () const
 return the bin size More...
 
virtual double minVar () const
 return the lower limit of the histogram More...
 
virtual double maxVar () const
 return the upper limit of the histogram More...
 
virtual double shift () const
 return the bin shift More...
 
virtual BinType bin_type () const
 return the bin type More...
 
virtual double bin (const size_t i) const
 return the i-th bin More...
 
virtual std::vector< double > bins () const
 return the bins More...
 
virtual std::vector< double > averaged_bins () const
 return the averaged bins More...
 
virtual std::vector< double > error_bins () const
 return the bin errors More...
 
virtual double edge (const size_t i) const
 return the i-th edge More...
 
virtual std::vector< double > edges () const
 return the histogram edges More...
 
virtual double operator() (const int i, const HistogramType hist_type, const double fact=1.) const
 return the histogram More...
 
virtual std::vector< double > operator() (const HistogramType hist_type, const double fact=1.) const
 return the histogram More...
 
virtual double normalization (const int i, const HistogramType hist_type, const double fact=1.) const
 return the bin normalization More...
 
virtual int unweighted_counts (const int i) const
 return the unweighted bin counts More...
 
virtual std::vector< int > unweighted_counts () const
 return the weights More...
 
virtual double error (const int i, const HistogramType hist_type, const double fact=1.) const
 return the poisson error of the histogram More...
 
virtual std::vector< double > error (const HistogramType hist_type, const double fact=1.) const
 return the error of the histogram More...
 

Private Attributes

std::shared_ptr< gsl_histogram2d > m_histo
 GSL histogram.
 
std::shared_ptr< gsl_histogram2d > m_histo_error
 GSL histogram error.
 
std::vector< std::vector< int > > m_counts
 histogram weights
 
std::vector< std::vector< double > > m_var1
 bin-weighted first variable
 
std::vector< std::vector< double > > m_var1_err
 bin-weighted first variable error
 
std::vector< std::vector< double > > m_var2
 bin-weighted second variable
 
std::vector< std::vector< double > > m_var2_err
 bin-weighted second variable error
 
std::vector< double > m_bins1
 first variable bins
 
std::vector< double > m_edges1
 first variable edges
 
size_t m_nbins1
 the number of bins for the first variable
 
double m_binSize1
 the binSize for the first variable
 
double m_shift1
 the bin shift for the first variable
 
double m_minVar1
 minimum first variable value
 
double m_maxVar1
 maximum first variable value
 
BinType m_binType1
 first variable bin type
 
std::vector< double > m_bins2
 variable bins
 
std::vector< double > m_edges2
 variable edges
 
size_t m_nbins2
 the number of bins
 
double m_binSize2
 the binSize for the second variable
 
double m_shift2
 the bin shift for the second variable
 
double m_minVar2
 minimum second variable value
 
double m_maxVar2
 maximum second variable value
 
BinType m_binType2
 second variable bin type
 

Detailed Description

The class Histogram2D.

This class is used to bin 2D variables.

Definition at line 1209 of file Histogram.h.

Constructor & Destructor Documentation

◆ Histogram2D()

cbl::glob::Histogram2D::Histogram2D ( const std::vector< double >  var1,
const std::vector< double >  var2,
const std::vector< double >  weight,
const size_t  nbins1,
const size_t  nbins2,
const double  minVar1 = par::defaultDouble,
const double  maxVar1 = par::defaultDouble,
const double  minVar2 = par::defaultDouble,
const double  maxVar2 = par::defaultDouble,
const double  shift1 = 0.5,
const double  shift2 = 0.5,
const BinType  bin_type1 = BinType::_linear_,
const BinType  bin_type2 = BinType::_linear_ 
)

constructor

Parameters
var1values of the first var
var2values of the second var
weightweights of the var
nbins1the number of bins for the first variable
nbins2the number of bins for the second variable
minVar1minimum range for the first variable
maxVar1maximmum range for the first variable
minVar2minimum range for the second variable
maxVar2maximmum range for the second variable
shift1bin shift for the first variable
shift2bin shift for the second variable
bin_type1the binning type for the first variable
bin_type2the binning type for the second variable

Definition at line 321 of file Histogram.cpp.

Member Function Documentation

◆ averaged_bins1()

std::vector<std::vector<double> > cbl::glob::Histogram2D::averaged_bins1 ( ) const
inlinevirtual

return the averaged bins

Returns
the histogram averaged bins

Reimplemented from cbl::glob::Histogram.

Definition at line 1575 of file Histogram.h.

◆ averaged_bins2()

std::vector<std::vector<double> > cbl::glob::Histogram2D::averaged_bins2 ( ) const
inlinevirtual

return the averaged bins

Returns
the histogram averaged bins

Reimplemented from cbl::glob::Histogram.

Definition at line 1582 of file Histogram.h.

◆ bin1()

double cbl::glob::Histogram2D::bin1 ( const size_t  i) const
inlineoverridevirtual

return the i-th bin of the first variable

Parameters
ithe i-th index
Returns
the i-th bin of the first variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1561 of file Histogram.h.

◆ bin2()

double cbl::glob::Histogram2D::bin2 ( const size_t  i) const
inlineoverridevirtual

return the i-th bin of the second variable

Parameters
ithe i-th index
Returns
the i-th bin of the second variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1621 of file Histogram.h.

◆ bin_type1()

BinType cbl::glob::Histogram2D::bin_type1 ( ) const
inlineoverridevirtual

return the bin type for the first variable

Returns
the bin type for the first variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1502 of file Histogram.h.

◆ bin_type2()

BinType cbl::glob::Histogram2D::bin_type2 ( ) const
inlineoverridevirtual

return the bin type for the second variable

Returns
the bin type for the second variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1552 of file Histogram.h.

◆ bins1()

std::vector<double> cbl::glob::Histogram2D::bins1 ( ) const
inlineoverridevirtual

return the first variable bins

Returns
the first variable bins

Reimplemented from cbl::glob::Histogram.

Definition at line 1568 of file Histogram.h.

◆ bins2()

std::vector<double> cbl::glob::Histogram2D::bins2 ( ) const
inlineoverridevirtual

return the second variable bins

Returns
the second variable bins

Reimplemented from cbl::glob::Histogram.

Definition at line 1628 of file Histogram.h.

◆ binSize1()

double cbl::glob::Histogram2D::binSize1 ( ) const
inlineoverridevirtual

return the bin size for the first variable

Returns
the bin size for the first variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1468 of file Histogram.h.

◆ binSize2()

double cbl::glob::Histogram2D::binSize2 ( ) const
inlineoverridevirtual

return the bin size for the second variable

Returns
the bin size for the second variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1518 of file Histogram.h.

◆ digitize() [1/2]

std::vector< int > cbl::glob::Histogram2D::digitize ( const double  var1,
const double  var2 
)
overridevirtual

get the histogram index

Parameters
var1value of the first var
var2value of the second var
Returns
the histogram index

Reimplemented from cbl::glob::Histogram.

Definition at line 460 of file Histogram.cpp.

◆ digitize() [2/2]

std::vector< std::vector< int > > cbl::glob::Histogram2D::digitize ( const std::vector< double >  var1,
const std::vector< double >  var2 
)
overridevirtual

get the histogram indeces

Parameters
var1values of the first var
var2values of the second var
Returns
the histogram indeces

Reimplemented from cbl::glob::Histogram.

Definition at line 474 of file Histogram.cpp.

◆ edge1()

double cbl::glob::Histogram2D::edge1 ( const size_t  i) const
inlineoverridevirtual

return the i-th edge of the first variable

Parameters
ithe i-th index
Returns
the i-th edge of the first variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1605 of file Histogram.h.

◆ edge2()

double cbl::glob::Histogram2D::edge2 ( const size_t  i) const
inlineoverridevirtual

return the i-th edge of the second variable

Parameters
ithe i-th index
Returns
the i-th edge of the second variabl

Reimplemented from cbl::glob::Histogram.

Definition at line 1637 of file Histogram.h.

◆ edges1()

std::vector<double> cbl::glob::Histogram2D::edges1 ( ) const
inlineoverridevirtual

return the histogram edges of the first variable

Returns
the histogram edges of the first variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1612 of file Histogram.h.

◆ edges2()

std::vector<double> cbl::glob::Histogram2D::edges2 ( ) const
inlineoverridevirtual

return the histogram edges of the second variable

Returns
the histogram edges of the second variabl

Reimplemented from cbl::glob::Histogram.

Definition at line 1644 of file Histogram.h.

◆ error()

double cbl::glob::Histogram2D::error ( const int  i,
const int  j,
const HistogramType  hist_type,
const double  fact = 1. 
) const
overridevirtual

return the poisson error of the histogram at (i,j)

Parameters
ithe i-th first variable bin
jthe j-th second variable bin
hist_typethe type of histogram
factthe factor used to normalized the histogram
Returns
the histogram error at (i,j)

Reimplemented from cbl::glob::Histogram.

Definition at line 616 of file Histogram.cpp.

◆ error_bins1()

vector< vector< double > > cbl::glob::Histogram2D::error_bins1 ( ) const
virtual

return the averaged bins

Returns
the histogram averaged bins

Reimplemented from cbl::glob::Histogram.

Definition at line 590 of file Histogram.cpp.

◆ error_bins2()

vector< vector< double > > cbl::glob::Histogram2D::error_bins2 ( ) const
virtual

return the averaged bins

Returns
the histogram averaged bins

Reimplemented from cbl::glob::Histogram.

Definition at line 603 of file Histogram.cpp.

◆ maxVar1()

double cbl::glob::Histogram2D::maxVar1 ( ) const
inlineoverridevirtual

return the upper limit of the histogram for the first variable

Returns
the upper limit of the histogram for the first variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1486 of file Histogram.h.

◆ maxVar2()

double cbl::glob::Histogram2D::maxVar2 ( ) const
inlineoverridevirtual

return the upper limit of the histogram for the second variable

Returns
the upper limit of the histogram for the second variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1536 of file Histogram.h.

◆ minVar1()

double cbl::glob::Histogram2D::minVar1 ( ) const
inlineoverridevirtual

return the lower limit of the histogram for the first variable

Returns
the lower limit of the histogram for the first variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1477 of file Histogram.h.

◆ minVar2()

double cbl::glob::Histogram2D::minVar2 ( ) const
inlineoverridevirtual

return the lower limit of the histogram for the second variable

Returns
the lower limit of the histogram for the second variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1527 of file Histogram.h.

◆ nbins1()

size_t cbl::glob::Histogram2D::nbins1 ( ) const
inlineoverridevirtual

return the number of bins for the first variable

Returns
the number of bins for the first variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1460 of file Histogram.h.

◆ nbins2()

size_t cbl::glob::Histogram2D::nbins2 ( ) const
inlineoverridevirtual

return the number of bins for the second variable

Returns
the number of bins for the second variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1510 of file Histogram.h.

◆ normalization()

double cbl::glob::Histogram2D::normalization ( const int  i,
const int  j,
const HistogramType  hist_type,
const double  fact = 1. 
) const
overridevirtual

return the bin normalization

Parameters
ii-th bin
jj-th bin
hist_typethe type of histogram
factthe factor used to normalized the histogram
Returns
the bin normalization

Reimplemented from cbl::glob::Histogram.

Definition at line 544 of file Histogram.cpp.

◆ operator()()

double cbl::glob::Histogram2D::operator() ( const int  i,
const int  j,
const HistogramType  hist_type,
const double  fact = 1. 
) const
overridevirtual

return the histogram at (i,j)

Parameters
ithe i-th first variable bin
jthe j-th second variable bin
hist_typethe type of histogram
factthe factor used to normalized the histogram
Returns
the histogram at (i,j)

Reimplemented from cbl::glob::Histogram.

Definition at line 581 of file Histogram.cpp.

◆ put() [1/4]

void cbl::glob::Histogram2D::put ( const double  var1,
const double  var2,
const double  weight 
)
overridevirtual

bin the data

Parameters
var1value of the first var
var2value of the second var
weightweight of the var

Reimplemented from cbl::glob::Histogram.

Definition at line 488 of file Histogram.cpp.

◆ put() [2/4]

void cbl::glob::Histogram2D::put ( const int  bin1,
const int  bin2,
const double  weight,
const double  var1,
const double  var2 
)
overridevirtual

bin the data

Parameters
bin1value of the first bin
bin2value of the second bin
weightweight of the var
var1value of the first var
var2value of the second var

Reimplemented from cbl::glob::Histogram.

Definition at line 510 of file Histogram.cpp.

◆ put() [3/4]

void cbl::glob::Histogram2D::put ( const std::vector< double >  var1,
const std::vector< double >  var2,
const std::vector< double >  weight 
)
overridevirtual

bin the data

Parameters
var1values of the first var
var2values of the second var
weightweights of the var

Reimplemented from cbl::glob::Histogram.

Definition at line 500 of file Histogram.cpp.

◆ put() [4/4]

void cbl::glob::Histogram2D::put ( const std::vector< std::vector< int >>  bins,
const std::vector< double >  weight,
const std::vector< double >  var1,
const std::vector< double >  var2 
)
overridevirtual

bin the data

Parameters
binsstd::vector containing the values of the bins
weightweights of the var
var1value of the first var
var2value of the second var

Reimplemented from cbl::glob::Histogram.

Definition at line 534 of file Histogram.cpp.

◆ set()

void cbl::glob::Histogram2D::set ( const size_t  nbins1,
const size_t  nbins2,
const double  minVar1 = par::defaultDouble,
const double  maxVar1 = par::defaultDouble,
const double  minVar2 = par::defaultDouble,
const double  maxVar2 = par::defaultDouble,
const double  shift1 = 0.5,
const double  shift2 = 0.5,
const BinType  bin_type1 = BinType::_linear_,
const BinType  bin_type2 = BinType::_linear_,
const std::vector< double >  vec_edges1 = {},
const std::vector< double >  vec_edges2 = {} 
)
overridevirtual

set the histogram variables

Parameters
nbins1the number of bins for the first variable
nbins2the number of bins for the second variable
minVar1minimum range for the first variable
maxVar1maximmum range for the first variable
minVar2minimum range for the second variable
maxVar2maximmum range for the second variable
shift1bin shift for the first variable
shift2bin shift for the second variable
bin_type1the binning type for the first variable
bin_type2the binning type for the second variable
vec_edges1the first variable bin edges, used only if bin_type is custom
vec_edges2the second variable bin edges, used only if bin_type is custom

Reimplemented from cbl::glob::Histogram.

Definition at line 337 of file Histogram.cpp.

◆ shift1()

double cbl::glob::Histogram2D::shift1 ( ) const
inlineoverridevirtual

return the bin shift for the first variable

Returns
the bin shift for the first variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1494 of file Histogram.h.

◆ shift2()

double cbl::glob::Histogram2D::shift2 ( ) const
inlineoverridevirtual

return the bin shift for the second variable

Returns
the bin shift for the second variable

Reimplemented from cbl::glob::Histogram.

Definition at line 1544 of file Histogram.h.

◆ unweighted_counts()

int cbl::glob::Histogram2D::unweighted_counts ( const int  i,
const int  j 
) const
inlineoverridevirtual

return the bin unweighted counts

Parameters
ii-th bin
jj-th bin
Returns
the bin unweighteighted counts

Reimplemented from cbl::glob::Histogram.

Definition at line 1671 of file Histogram.h.

◆ write()

void cbl::glob::Histogram2D::write ( const std::string  dir,
const std::string  file,
const HistogramType  hist_type,
const double  fact = 1. 
) const
overridevirtual

write the histogram

Parameters
diroutput directory
fileoutput file
hist_typethe type of histogram
factthe factor used to normalized the histogram

Reimplemented from cbl::glob::Histogram.

Definition at line 625 of file Histogram.cpp.


The documentation for this class was generated from the following files: