BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
IHistogram Class Referenceabstract

Base class for 1D and 2D histograms holding values of double type. More...

+ Inheritance diagram for IHistogram:

Public Types

enum  DataType { INTEGRAL , AVERAGE , STANDARD_ERROR , NENTRIES }
 

Public Member Functions

 IHistogram (const IHistogram &other)
 
 IHistogram (const IAxis &axis_x)
 
 IHistogram (const IAxis &axis_x, const IAxis &axis_y)
 
virtual IHistogramclone () const =0
 
virtual size_t getRank () const =0
 Returns number of histogram dimensions.
 
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.
 

Static Public Member Functions

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 Member Functions

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.
 

Protected Attributes

OutputData< CumulativeValuem_data
 

Detailed Description

Base class for 1D and 2D histograms holding values of double type.

Definition at line 26 of file IHistogram.h.

Member Function Documentation

◆ getTotalNumberOfBins()

size_t IHistogram::getTotalNumberOfBins ( ) const

Returns total number of histogram bins.

For 2D histograms the result will be the product of bin numbers along X and Y axes.

Definition at line 39 of file IHistogram.cpp.

◆ getArray()

PyObject * IHistogram::getArray ( DataType  dataType = DataType::INTEGRAL) const
Deprecated:
Use array() instead.

Definition at line 222 of file IHistogram.cpp.

◆ createOutputData()

OutputData< double > * IHistogram::createOutputData ( IHistogram::DataType  dataType = DataType::INTEGRAL) const

creates new OutputData with histogram's shape and values corresponding to DataType

creates new OutputData with histogram's shape and put there values corresponding to DataType

Definition at line 334 of file IHistogram.cpp.


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