BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Histogram2D Class Reference

Two dimensional histogram. More...

+ Inheritance diagram for Histogram2D:

Public Member Functions

 Histogram2D (int nbinsx, double xlow, double xup, int nbinsy, double ylow, double yup)
 Constructor for fix bin size histograms. More...
 
 Histogram2D (int nbinsx, const std::vector< double > &xbins, int nbinsy, const std::vector< double > &ybins)
 Constructor for variable bin size histograms. More...
 
 Histogram2D (const IAxis &axis_x, const IAxis &axis_y)
 Constructor for 2D histogram with custom axes.
 
 Histogram2D (const OutputData< double > &data)
 Constructor for 2D histograms from basic OutputData object.
 
 Histogram2D (std::vector< std::vector< double >> data)
 Constructor for 2D histograms from numpy array (thanks to swig)
 
Histogram2Dclone () const
 Returns clone of other histogram.
 
size_t getRank () const
 Returns the number of histogram dimensions.
 
int fill (double x, double y, double weight=1.0)
 Increment bin with abscissa x and ordinate y with a weight.
 
Histogram1DprojectionX ()
 Project a 2D histogram into 1D histogram along X. More...
 
Histogram1DprojectionX (double yvalue)
 Project a 2D histogram into 1D histogram along X. More...
 
Histogram1DprojectionX (double ylow, double yup)
 Project a 2D histogram into 1D histogram along X. More...
 
Histogram1DprojectionY ()
 Project a 2D histogram into 1D histogram along Y. More...
 
Histogram1DprojectionY (double xvalue)
 Project a 2D histogram into 1D histogram along Y. More...
 
Histogram1DprojectionY (double xlow, double xup)
 Project a 2D histogram into 1D histogram along Y. More...
 
Histogram2Dcrop (double xmin, double ymin, double xmax, double ymax)
 Creates new histogram by applying rectangular clip.
 
void setContent (const std::vector< std::vector< double >> &data)
 Sets the values in histograms channels from numpy array,.
 
void addContent (const std::vector< std::vector< double >> &data)
 Add to values in histograms channels from numpy array,.
 
- Public Member Functions inherited from IHistogram
 IHistogram (const IHistogram &other)
 
 IHistogram (const IAxis &axis_x)
 
 IHistogram (const IAxis &axis_x, const IAxis &axis_y)
 
size_t getTotalNumberOfBins () const
 Returns total number of histogram bins. More...
 
const IAxisgetXaxis () const
 returns x-axis
 
const IAxisgetYaxis () const
 returns y-axis for 2D histograms
 
double getXmin () const
 Returns x-axis min (lower edge of first bin).
 
double getXmax () const
 Returns x-axis max (upper edge of last bin).
 
size_t getNbinsX () const
 Returns number of bins on x-axis.
 
double getYmin () const
 Returns y-axis min (lower edge of first bin) for 2D histograms.
 
double getYmax () const
 Returns y-axis max (upper edge of last bin) for 2D histograms.
 
size_t getNbinsY () const
 Returns number of bins on y-axis.
 
size_t getGlobalBin (size_t binx, size_t biny=0) const
 Returns global bin index for given axes indices. For 1D, just returns binx.
 
size_t findGlobalBin (double x, double y) const
 Returns closest global bin index for given axes coordinates.
 
size_t getXaxisIndex (size_t i) const
 Returns x-axis index for global bin index i.
 
size_t getYaxisIndex (size_t i) const
 Returns y-axis index for global bin index i.
 
double getXaxisValue (size_t i)
 Returns the center of bin i of the x axis.
 
double getYaxisValue (size_t i)
 Returns the center of bin i of the y axis.
 
double getBinContent (size_t i) const
 Returns content (accumulated value) of bin i.
 
const OutputData< CumulativeValue > & getData () const
 
OutputData< CumulativeValue > & getData ()
 
double getBinContent (size_t binx, size_t biny) const
 Returns content (accumulated value) of the 2D histogram bin.
 
void setBinContent (size_t i, double value)
 Sets content of the bin corresponding to the globalbin number.
 
void addBinContent (size_t i, double value)
 Add the value to the bin.
 
double getBinError (size_t i) const
 Returns error of the bin with given index.
 
double getBinError (size_t binx, size_t biny) const
 Returns error of the bin with given indices (for 2D histograms).
 
double getBinAverage (size_t i) const
 Returns average value in the bin with given index.
 
double getBinAverage (size_t binx, size_t biny) const
 Returns average value of the bin with given indices (for 2D histograms).
 
int getBinNumberOfEntries (size_t i) const
 Returns number of entries in the bin with given index.
 
int getBinNumberOfEntries (size_t binx, size_t biny) const
 Returns number of entries in the bin with given indices (for 2D histograms).
 
double getMaximum () const
 Returns histogram maximum value (maximum of getBinContent() over all bins)
 
size_t getMaximumBinIndex () const
 Returns globalbin index with maximum content.
 
double getMinimum () const
 Returns histogram minimum value (minimum of getBinContent() over all bins)
 
size_t getMinimumBinIndex () const
 Returns globalbin index with minimum content.
 
void scale (double value)
 Multiply this histogram (every bin content value) by a constant.
 
double integral () const
 Returns integral of bins content (computed as a sum of all bin content).
 
PyObject * array (DataType dataType=DataType::INTEGRAL) const
 Returns numpy array with bin content (accumulated values).
 
PyObject * getArray (DataType dataType=DataType::INTEGRAL) const
 
void reset ()
 Reset histogram content (axes remains)
 
OutputData< double > * createOutputData (DataType dataType=DataType::INTEGRAL) const
 creates new OutputData with histogram's shape and values corresponding to DataType More...
 
bool hasSameShape (const IHistogram &other) const
 Returns true if objects a) have same dimensions b) bin boundaries of axes coincide.
 
bool hasSameDimensions (const IHistogram &other) const
 Returns true if object have same rank and number of axes bins.
 
const IHistogramoperator+= (const IHistogram &right)
 addition-assignment operator for two histograms
 
IHistogramrelativeDifferenceHistogram (const IHistogram &rhs)
 returns histogram representing relative difference of two histograms.
 
void save (const std::string &filename)
 Saves histogram in file Following formats are available: *.txt, *.tif, *.int (*.txt.gz, *.tif.gz, *.int.gz)
 
void load (const std::string &filename)
 Loads histogram from file, the shape of array in file should match Following formats are available: *.txt, *.tif, *.int (*.txt.gz, *.tif.gz, *.int.gz) Only bin content will be loaded, histogram axes remain the same.
 

Protected Member Functions

template<typename T >
void initFromShape (const T &data)
 
Histogram1Dcreate_projectionX (int ybinlow, int ybinup)
 Creates projection along X. More...
 
Histogram1Dcreate_projectionY (int xbinlow, int xbinup)
 Creates projection along Y. More...
 
- Protected Member Functions inherited from IHistogram
void check_x_axis () const
 
void check_y_axis () const
 
void init_from_data (const OutputData< double > &source)
 
double getBinData (size_t i, DataType dataType) const
 returns data of requested type for globalbin number
 
std::vector< double > getDataVector (DataType dataType) const
 returns vector of values of requested DataType
 
void copyContentFrom (const IHistogram &other)
 Copy content (but not the axes) from other histogram. Dimensions should be the same.
 

Additional Inherited Members

- Public Types inherited from IHistogram
enum  DataType { INTEGRAL , AVERAGE , STANDARD_ERROR , NENTRIES }
 
- Static Public Member Functions inherited from IHistogram
static IHistogramcreateHistogram (const OutputData< double > &source)
 
static IHistogramcreateFrom (const std::string &filename)
 create new histogram from file content
 
static IHistogramcreateFrom (const std::vector< std::vector< double >> &data)
 create new histogram from numpy array
 
- Protected Attributes inherited from IHistogram
OutputData< CumulativeValuem_data
 

Detailed Description

Two dimensional histogram.

Definition at line 24 of file Histogram2D.h.

Constructor & Destructor Documentation

◆ Histogram2D() [1/2]

Histogram2D::Histogram2D ( int  nbinsx,
double  xlow,
double  xup,
int  nbinsy,
double  ylow,
double  yup 
)

Constructor for fix bin size histograms.

Parameters
nbinsxnumber of bins on X-axis
xlowlow edge of the first bin of X-axis
xupupper edge of the last bin of X-axis
nbinsynumber of bins on Y axis
ylowlow edge of the first bin of Y-axis
yupupper edge of the last bin of Y-axis

Definition at line 20 of file Histogram2D.cpp.

◆ Histogram2D() [2/2]

Histogram2D::Histogram2D ( int  nbinsx,
const std::vector< double > &  xbins,
int  nbinsy,
const std::vector< double > &  ybins 
)

Constructor for variable bin size histograms.

Parameters
nbinsxnumber of bins on X-axis
xbinsArray of size nbins+1 containing low-edges for each bin and upper edge of last bin.
nbinsynumber of bins on Y-axis
ybinsArray of size nbins+1 containing low-edges for each bin and upper edge of last bin.

Definition at line 26 of file Histogram2D.cpp.

Member Function Documentation

◆ projectionX() [1/3]

Histogram1D * Histogram2D::projectionX ( )

Project a 2D histogram into 1D histogram along X.

The projection is made from all bins along y-axis.

Definition at line 63 of file Histogram2D.cpp.

◆ projectionX() [2/3]

Histogram1D * Histogram2D::projectionX ( double  yvalue)

Project a 2D histogram into 1D histogram along X.

The projection is made from the y-bin closest to given ordinate yvalue.

Parameters
yvaluethe value on y-axis at which projection is taken

Definition at line 68 of file Histogram2D.cpp.

◆ projectionX() [3/3]

Histogram1D * Histogram2D::projectionX ( double  ylow,
double  yup 
)

Project a 2D histogram into 1D histogram along X.

The projection is made from all y-bins corresponding to ordinate between ylow and yup.

Parameters
ylowlower edje on y-axis
yupupper edje on y-axis

Definition at line 74 of file Histogram2D.cpp.

◆ projectionY() [1/3]

Histogram1D * Histogram2D::projectionY ( )

Project a 2D histogram into 1D histogram along Y.

The projection is made from all bins along x-axis.

Definition at line 81 of file Histogram2D.cpp.

◆ projectionY() [2/3]

Histogram1D * Histogram2D::projectionY ( double  xvalue)

Project a 2D histogram into 1D histogram along Y.

The projection is made from the x-bin closest to given abscissa xvalue.

Parameters
xvaluethe value on x-axis at which projection is taken

Definition at line 86 of file Histogram2D.cpp.

◆ projectionY() [3/3]

Histogram1D * Histogram2D::projectionY ( double  xlow,
double  xup 
)

Project a 2D histogram into 1D histogram along Y.

The projection is made from all x-bins corresponding to abscissa between xlow and xup.

Parameters
xlowlower edje on x-axis
xupupper edje on x-axis

Definition at line 92 of file Histogram2D.cpp.

◆ create_projectionX()

Histogram1D * Histogram2D::create_projectionX ( int  ybinlow,
int  ybinup 
)
protected

Creates projection along X.

The projections is made by collecting the data in the range between [ybinlow, ybinup].

Definition at line 148 of file Histogram2D.cpp.

◆ create_projectionY()

Histogram1D * Histogram2D::create_projectionY ( int  xbinlow,
int  xbinup 
)
protected

Creates projection along Y.

The projections is made by collecting the data in the range between [xbinlow, xbinup].

Definition at line 163 of file Histogram2D.cpp.


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