BornAgain
1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
|
Base class for 1D and 2D histograms holding values of double type. More...
Public Types | |
enum | DataType { INTEGRAL , AVERAGE , STANDARD_ERROR , NENTRIES } |
Public Member Functions | |
IHistogram () | |
IHistogram (const IAxis &axis_x) | |
IHistogram (const IAxis &axis_x, const IAxis &axis_y) | |
IHistogram (const IHistogram &other) | |
virtual | ~IHistogram ()=default |
void | addBinContent (size_t i, double value) |
Add the value to the bin. More... | |
PyObject * | array (DataType dataType=DataType::INTEGRAL) const |
Returns numpy array with bin content (accumulated values). More... | |
double | binAverage (size_t binx, size_t biny) const |
Returns average value of the bin with given indices (for 2D histograms). More... | |
double | binAverage (size_t i) const |
Returns average value in the bin with given index. More... | |
double | binContent (size_t binx, size_t biny) const |
Returns content (accumulated value) of the 2D histogram bin. More... | |
double | binContent (size_t i) const |
Returns content (accumulated value) of bin i. More... | |
double | binError (size_t binx, size_t biny) const |
Returns error of the bin with given indices (for 2D histograms). More... | |
double | binError (size_t i) const |
Returns error of the bin with given index. More... | |
int | binNumberOfEntries (size_t binx, size_t biny) const |
Returns number of entries in the bin with given indices (for 2D histograms). More... | |
int | binNumberOfEntries (size_t i) const |
Returns number of entries in the bin with given index. More... | |
virtual IHistogram * | clone () const =0 |
OutputData< double > * | createOutputData (DataType dataType=DataType::INTEGRAL) const |
creates new OutputData with histogram's shape and values corresponding to DataType More... | |
size_t | findGlobalBin (double x, double y) const |
Returns closest global bin index for given axes coordinates. More... | |
PyObject * | getArray (DataType dataType=DataType::INTEGRAL) const |
OutputData< CumulativeValue > & | getData () |
const OutputData< CumulativeValue > & | getData () const |
size_t | getGlobalBin (size_t binx, size_t biny=0) const |
Returns global bin index for given axes indices. For 1D, just returns binx. More... | |
double | getMaximum () const |
Returns histogram maximum value (maximum of binContent() over all bins) More... | |
size_t | getMaximumBinIndex () const |
Returns globalbin index with maximum content. More... | |
double | getMinimum () const |
Returns histogram minimum value (minimum of binContent() over all bins) More... | |
size_t | getMinimumBinIndex () const |
Returns globalbin index with minimum content. More... | |
size_t | getNbinsX () const |
Returns number of bins on x-axis. More... | |
size_t | getNbinsY () const |
Returns number of bins on y-axis. More... | |
size_t | getTotalNumberOfBins () const |
Returns total number of histogram bins. More... | |
double | getXmax () const |
Returns x-axis max (upper edge of last bin). More... | |
double | getXmin () const |
Returns x-axis min (lower edge of first bin). More... | |
double | getYmax () const |
Returns y-axis max (upper edge of last bin) for 2D histograms. More... | |
double | getYmin () const |
Returns y-axis min (lower edge of first bin) for 2D histograms. More... | |
bool | hasSameDimensions (const IHistogram &other) const |
Returns true if object have same rank and number of axes bins. More... | |
bool | hasSameShape (const IHistogram &other) const |
Returns true if objects a) have same dimensions b) bin boundaries of axes coincide. More... | |
double | integral () const |
Returns integral of bins content (computed as a sum of all bin content). More... | |
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. More... | |
const IHistogram & | operator+= (const IHistogram &right) |
addition-assignment operator for two histograms More... | |
virtual size_t | rank () const =0 |
Returns number of histogram dimensions. More... | |
IHistogram * | relativeDifferenceHistogram (const IHistogram &rhs) |
returns histogram representing relative difference of two histograms. More... | |
void | reset () |
Reset histogram content (axes remains) More... | |
void | save (const std::string &filename) |
Saves histogram in file Following formats are available: *.txt, *.tif, *.int (*.txt.gz, *.tif.gz, *.int.gz) More... | |
void | scale (double value) |
Multiply this histogram (every bin content value) by a constant. More... | |
void | setBinContent (size_t i, double value) |
Sets content of the bin corresponding to the globalbin number. More... | |
const IAxis & | xAxis () const |
returns x-axis More... | |
size_t | xAxisIndex (size_t i) const |
Returns x-axis index for global bin index i. More... | |
double | xAxisValue (size_t i) |
Returns the center of bin i of the x axis. More... | |
const IAxis & | yAxis () const |
returns y-axis for 2D histograms More... | |
size_t | yAxisIndex (size_t i) const |
Returns y-axis index for global bin index i. More... | |
double | yAxisValue (size_t i) |
Returns the center of bin i of the y axis. More... | |
Static Public Member Functions | |
static IHistogram * | createFrom (const std::string &filename) |
create new histogram from file content More... | |
static IHistogram * | createFrom (const std::vector< std::vector< double >> &data) |
create new histogram from numpy array More... | |
static IHistogram * | createHistogram (const OutputData< double > &source) |
Protected Member Functions | |
double | binData (size_t i, DataType dataType) const |
returns data of requested type for globalbin number More... | |
void | check_x_axis () const |
void | check_y_axis () const |
void | copyContentFrom (const IHistogram &other) |
Copy content (but not the axes) from other histogram. Dimensions should be the same. More... | |
std::vector< double > | getDataVector (DataType dataType) const |
returns vector of values of requested DataType More... | |
void | init_from_data (const OutputData< double > &source) |
Protected Attributes | |
OutputData< CumulativeValue > | m_data |
Base class for 1D and 2D histograms holding values of double type.
Definition at line 27 of file IHistogram.h.
enum IHistogram::DataType |
|
default |
IHistogram::IHistogram | ( | const IHistogram & | other | ) |
Definition at line 23 of file IHistogram.cpp.
References OutputData< T >::copyFrom(), and m_data.
|
virtualdefault |
IHistogram::IHistogram | ( | const IAxis & | axis_x | ) |
Definition at line 28 of file IHistogram.cpp.
References OutputData< T >::addAxis(), and m_data.
Definition at line 33 of file IHistogram.cpp.
References OutputData< T >::addAxis(), and m_data.
void IHistogram::addBinContent | ( | size_t | i, |
double | value | ||
) |
Add the value to the bin.
Definition at line 151 of file IHistogram.cpp.
References m_data.
Referenced by operator+=().
Returns numpy array with bin content (accumulated values).
Definition at line 226 of file IHistogram.cpp.
References createOutputData().
Referenced by getArray().
double IHistogram::binAverage | ( | size_t | binx, |
size_t | biny | ||
) | const |
Returns average value of the bin with given indices (for 2D histograms).
Definition at line 171 of file IHistogram.cpp.
References binAverage(), and getGlobalBin().
double IHistogram::binAverage | ( | size_t | i | ) | const |
Returns average value in the bin with given index.
Definition at line 166 of file IHistogram.cpp.
References m_data.
Referenced by binAverage(), and binData().
double IHistogram::binContent | ( | size_t | binx, |
size_t | biny | ||
) | const |
Returns content (accumulated value) of the 2D histogram bin.
Definition at line 141 of file IHistogram.cpp.
References binContent(), and getGlobalBin().
double IHistogram::binContent | ( | size_t | i | ) | const |
Returns content (accumulated value) of bin i.
Definition at line 136 of file IHistogram.cpp.
References m_data.
Referenced by binContent(), binData(), Histogram2D::create_projectionX(), Histogram2D::create_projectionY(), operator+=(), and relativeDifferenceHistogram().
|
protected |
returns data of requested type for globalbin number
Definition at line 305 of file IHistogram.cpp.
References binAverage(), binContent(), binError(), and binNumberOfEntries().
Referenced by createOutputData(), and getDataVector().
double IHistogram::binError | ( | size_t | binx, |
size_t | biny | ||
) | const |
Returns error of the bin with given indices (for 2D histograms).
Definition at line 161 of file IHistogram.cpp.
References binError(), and getGlobalBin().
double IHistogram::binError | ( | size_t | i | ) | const |
Returns error of the bin with given index.
Definition at line 156 of file IHistogram.cpp.
References m_data.
Referenced by binData(), and binError().
int IHistogram::binNumberOfEntries | ( | size_t | binx, |
size_t | biny | ||
) | const |
Returns number of entries in the bin with given indices (for 2D histograms).
Definition at line 181 of file IHistogram.cpp.
References binNumberOfEntries(), and getGlobalBin().
int IHistogram::binNumberOfEntries | ( | size_t | i | ) | const |
Returns number of entries in the bin with given index.
Definition at line 176 of file IHistogram.cpp.
References m_data.
Referenced by binData(), and binNumberOfEntries().
|
protected |
Definition at line 268 of file IHistogram.cpp.
References rank().
Referenced by xAxis(), and xAxisValue().
|
protected |
Definition at line 278 of file IHistogram.cpp.
References rank().
Referenced by yAxis(), and yAxisValue().
|
pure virtual |
Implemented in Histogram2D, and Histogram1D.
Referenced by relativeDifferenceHistogram().
|
protected |
Copy content (but not the axes) from other histogram. Dimensions should be the same.
Definition at line 331 of file IHistogram.cpp.
References getTotalNumberOfBins(), hasSameDimensions(), m_data, and reset().
Referenced by load().
|
static |
create new histogram from file content
Definition at line 258 of file IHistogram.cpp.
References FileSystemUtils::filename(), and IntensityDataIOFactory::readIntensityData().
|
static |
|
static |
Definition at line 243 of file IHistogram.cpp.
References OutputData< T >::rank().
Referenced by DetectorMask::createHistogram(), and IntensityDataIOFactory::readIntensityData().
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 343 of file IHistogram.cpp.
References binData(), OutputData< T >::copyShapeFrom(), getTotalNumberOfBins(), and m_data.
Referenced by array(), HistoUtils::FindPeaks(), and IntensityDataIOFactory::writeIntensityData().
size_t IHistogram::findGlobalBin | ( | double | x, |
double | y | ||
) | const |
Returns closest global bin index for given axes coordinates.
Definition at line 95 of file IHistogram.cpp.
References OutputData< T >::findGlobalIndex(), m_data, and rank().
Definition at line 232 of file IHistogram.cpp.
References array().
OutputData< CumulativeValue > & IHistogram::getData | ( | ) |
const OutputData< CumulativeValue > & IHistogram::getData | ( | ) | const |
Definition at line 126 of file IHistogram.cpp.
References m_data.
Referenced by HistoUtils::getRelativeDifference().
|
protected |
returns vector of values of requested DataType
Definition at line 320 of file IHistogram.cpp.
References binData(), and getTotalNumberOfBins().
Referenced by Histogram1D::binErrors(), and Histogram1D::binValues().
size_t IHistogram::getGlobalBin | ( | size_t | binx, |
size_t | biny = 0 |
||
) | const |
Returns global bin index for given axes indices. For 1D, just returns binx.
Definition at line 86 of file IHistogram.cpp.
References m_data, rank(), and OutputData< T >::toGlobalIndex().
Referenced by binAverage(), binContent(), binError(), and binNumberOfEntries().
double IHistogram::getMaximum | ( | ) | const |
Returns histogram maximum value (maximum of binContent() over all bins)
Definition at line 186 of file IHistogram.cpp.
References OutputData< T >::begin(), OutputData< T >::end(), and m_data.
size_t IHistogram::getMaximumBinIndex | ( | ) | const |
Returns globalbin index with maximum content.
Definition at line 192 of file IHistogram.cpp.
References OutputData< T >::begin(), OutputData< T >::end(), and m_data.
double IHistogram::getMinimum | ( | ) | const |
Returns histogram minimum value (minimum of binContent() over all bins)
Definition at line 198 of file IHistogram.cpp.
References OutputData< T >::begin(), OutputData< T >::end(), and m_data.
size_t IHistogram::getMinimumBinIndex | ( | ) | const |
Returns globalbin index with minimum content.
Definition at line 204 of file IHistogram.cpp.
References OutputData< T >::begin(), OutputData< T >::end(), and m_data.
size_t IHistogram::getNbinsX | ( | ) | const |
Returns number of bins on x-axis.
Definition at line 66 of file IHistogram.cpp.
References IAxis::size(), and xAxis().
size_t IHistogram::getNbinsY | ( | ) | const |
Returns number of bins on y-axis.
Definition at line 81 of file IHistogram.cpp.
References IAxis::size(), and yAxis().
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.
References OutputData< T >::getAllocatedSize(), and m_data.
Referenced by copyContentFrom(), Histogram2D::create_projectionX(), Histogram2D::create_projectionY(), createOutputData(), getDataVector(), integral(), operator+=(), relativeDifferenceHistogram(), and scale().
double IHistogram::getXmax | ( | ) | const |
Returns x-axis max (upper edge of last bin).
Definition at line 61 of file IHistogram.cpp.
References IAxis::upperBound(), and xAxis().
double IHistogram::getXmin | ( | ) | const |
Returns x-axis min (lower edge of first bin).
Definition at line 56 of file IHistogram.cpp.
References IAxis::lowerBound(), and xAxis().
double IHistogram::getYmax | ( | ) | const |
Returns y-axis max (upper edge of last bin) for 2D histograms.
Definition at line 76 of file IHistogram.cpp.
References IAxis::upperBound(), and yAxis().
double IHistogram::getYmin | ( | ) | const |
Returns y-axis min (lower edge of first bin) for 2D histograms.
Definition at line 71 of file IHistogram.cpp.
References IAxis::lowerBound(), and yAxis().
bool IHistogram::hasSameDimensions | ( | const IHistogram & | other | ) | const |
Returns true if object have same rank and number of axes bins.
Definition at line 358 of file IHistogram.cpp.
References OutputData< T >::hasSameDimensions(), and m_data.
Referenced by copyContentFrom(), operator+=(), and relativeDifferenceHistogram().
bool IHistogram::hasSameShape | ( | const IHistogram & | other | ) | const |
Returns true if objects a) have same dimensions b) bin boundaries of axes coincide.
Definition at line 353 of file IHistogram.cpp.
References OutputData< T >::hasSameShape(), and m_data.
|
protected |
Definition at line 288 of file IHistogram.cpp.
References OutputData< T >::copyShapeFrom(), OutputData< T >::getAllocatedSize(), m_data, OutputData< T >::rank(), and rank().
Referenced by Histogram1D::Histogram1D(), and Histogram2D::Histogram2D().
double IHistogram::integral | ( | ) | const |
Returns integral of bins content (computed as a sum of all bin content).
Definition at line 216 of file IHistogram.cpp.
References getTotalNumberOfBins(), and m_data.
void IHistogram::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.
Definition at line 394 of file IHistogram.cpp.
References copyContentFrom(), FileSystemUtils::filename(), and IntensityDataIOFactory::readIntensityData().
const IHistogram & IHistogram::operator+= | ( | const IHistogram & | right | ) |
addition-assignment operator for two histograms
Definition at line 363 of file IHistogram.cpp.
References addBinContent(), binContent(), getTotalNumberOfBins(), and hasSameDimensions().
|
pure virtual |
Returns number of histogram dimensions.
Implemented in Histogram2D, and Histogram1D.
Referenced by check_x_axis(), check_y_axis(), findGlobalBin(), getGlobalBin(), and init_from_data().
IHistogram * IHistogram::relativeDifferenceHistogram | ( | const IHistogram & | rhs | ) |
returns histogram representing relative difference of two histograms.
Definition at line 373 of file IHistogram.cpp.
References binContent(), clone(), Numeric::GetRelativeDifference(), getTotalNumberOfBins(), hasSameDimensions(), reset(), and setBinContent().
void IHistogram::reset | ( | ) |
Reset histogram content (axes remains)
Definition at line 238 of file IHistogram.cpp.
References m_data, and OutputData< T >::setAllTo().
Referenced by copyContentFrom(), relativeDifferenceHistogram(), and Histogram2D::setContent().
void IHistogram::save | ( | const std::string & | filename | ) |
Saves histogram in file Following formats are available: *.txt, *.tif, *.int (*.txt.gz, *.tif.gz, *.int.gz)
Definition at line 389 of file IHistogram.cpp.
References FileSystemUtils::filename(), and IntensityDataIOFactory::writeIntensityData().
void IHistogram::scale | ( | double | value | ) |
Multiply this histogram (every bin content value) by a constant.
Definition at line 209 of file IHistogram.cpp.
References getTotalNumberOfBins(), and m_data.
void IHistogram::setBinContent | ( | size_t | i, |
double | value | ||
) |
Sets content of the bin corresponding to the globalbin number.
Definition at line 146 of file IHistogram.cpp.
References m_data.
Referenced by relativeDifferenceHistogram().
const IAxis & IHistogram::xAxis | ( | ) | const |
returns x-axis
Definition at line 44 of file IHistogram.cpp.
References OutputData< T >::axis(), check_x_axis(), and m_data.
Referenced by Histogram1D::binCenters(), Histogram2D::create_projectionX(), Histogram1D::crop(), Histogram2D::crop(), Histogram1D::fill(), Histogram2D::fill(), HistoUtils::FindPeaks(), getNbinsX(), getXmax(), getXmin(), Histogram2D::projectionX(), and Histogram2D::projectionY().
size_t IHistogram::xAxisIndex | ( | size_t | i | ) | const |
Returns x-axis index for global bin index i.
Definition at line 104 of file IHistogram.cpp.
References OutputData< T >::getAxisBinIndex(), and m_data.
Referenced by Histogram2D::create_projectionY().
double IHistogram::xAxisValue | ( | size_t | i | ) |
Returns the center of bin i of the x axis.
Definition at line 114 of file IHistogram.cpp.
References check_x_axis(), OutputData< T >::getAxisValue(), and m_data.
Referenced by Histogram2D::create_projectionX().
const IAxis & IHistogram::yAxis | ( | ) | const |
returns y-axis for 2D histograms
Definition at line 50 of file IHistogram.cpp.
References OutputData< T >::axis(), check_y_axis(), and m_data.
Referenced by Histogram2D::create_projectionY(), Histogram2D::crop(), Histogram2D::fill(), HistoUtils::FindPeaks(), getNbinsY(), getYmax(), getYmin(), and Histogram2D::projectionX().
size_t IHistogram::yAxisIndex | ( | size_t | i | ) | const |
Returns y-axis index for global bin index i.
Definition at line 109 of file IHistogram.cpp.
References OutputData< T >::getAxisBinIndex(), and m_data.
Referenced by Histogram2D::create_projectionX().
double IHistogram::yAxisValue | ( | size_t | i | ) |
Returns the center of bin i of the y axis.
Definition at line 120 of file IHistogram.cpp.
References check_y_axis(), OutputData< T >::getAxisValue(), and m_data.
Referenced by Histogram2D::create_projectionY().
|
protected |
Definition at line 193 of file IHistogram.h.
Referenced by Histogram1D::Histogram1D(), Histogram2D::Histogram2D(), IHistogram(), addBinContent(), Histogram2D::addContent(), binAverage(), binContent(), binError(), binNumberOfEntries(), copyContentFrom(), createOutputData(), Histogram1D::crop(), Histogram2D::crop(), Histogram1D::fill(), Histogram2D::fill(), findGlobalBin(), getData(), getGlobalBin(), getMaximum(), getMaximumBinIndex(), getMinimum(), getMinimumBinIndex(), getTotalNumberOfBins(), hasSameDimensions(), hasSameShape(), init_from_data(), Histogram2D::initFromShape(), integral(), reset(), scale(), setBinContent(), xAxis(), xAxisIndex(), xAxisValue(), yAxis(), yAxisIndex(), and yAxisValue().