BornAgain
1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
|
Public Types | |
enum | DataType { INTEGRAL , AVERAGE , STANDARD_ERROR , NENTRIES } |
Public Member Functions | |
IHistogram () | |
IHistogram (const IHistogram &other) | |
virtual | ~IHistogram () |
IHistogram (const IAxis &axis_x) | |
IHistogram (const IAxis &axis_x, const IAxis &axis_y) | |
virtual IHistogram * | clone () const =0 |
virtual size_t | getRank () const =0 |
size_t | getTotalNumberOfBins () const |
const IAxis & | getXaxis () const |
const IAxis & | getYaxis () const |
double | getXmin () const |
double | getXmax () const |
size_t | getNbinsX () const |
double | getYmin () const |
double | getYmax () const |
size_t | getNbinsY () const |
size_t | getGlobalBin (size_t binx, size_t biny=0) const |
size_t | findGlobalBin (double x, double y) const |
size_t | getXaxisIndex (size_t i) const |
size_t | getYaxisIndex (size_t i) const |
double | getXaxisValue (size_t i) |
double | getYaxisValue (size_t i) |
double | getBinContent (size_t i) const |
const OutputData< CumulativeValue > & | getData () const |
OutputData< CumulativeValue > & | getData () |
double | getBinContent (size_t binx, size_t biny) const |
void | setBinContent (size_t i, double value) |
void | addBinContent (size_t i, double value) |
double | getBinError (size_t i) const |
double | getBinError (size_t binx, size_t biny) const |
double | getBinAverage (size_t i) const |
double | getBinAverage (size_t binx, size_t biny) const |
int | getBinNumberOfEntries (size_t i) const |
int | getBinNumberOfEntries (size_t binx, size_t biny) const |
double | getMaximum () const |
size_t | getMaximumBinIndex () const |
double | getMinimum () const |
size_t | getMinimumBinIndex () const |
void | scale (double value) |
double | integral () const |
PyObject * | array (DataType dataType=DataType::INTEGRAL) const |
PyObject * | getArray (DataType dataType=DataType::INTEGRAL) const |
void | reset () |
OutputData< double > * | createOutputData (DataType dataType=DataType::INTEGRAL) const |
bool | hasSameShape (const IHistogram &other) const |
bool | hasSameDimensions (const IHistogram &other) const |
const IHistogram & | operator+= (const IHistogram &right) |
IHistogram * | relativeDifferenceHistogram (const IHistogram &rhs) |
void | save (const std::string &filename) |
void | load (const std::string &filename) |
Static Public Member Functions | |
static IHistogram * | createHistogram (const OutputData< double > &source) |
static IHistogram * | createFrom (const std::string &filename) |
static IHistogram * | createFrom (const std::vector< std::vector< double >> &data) |
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 |
std::vector< double > | getDataVector (DataType dataType) const |
void | copyContentFrom (const IHistogram &other) |
Protected Attributes | |
OutputData< CumulativeValue > | m_data |
Base class for 1D and 2D histograms holding values of double type.
Definition at line 26 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.
|
inlinevirtual |
Definition at line 33 of file IHistogram.h.
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.
|
pure virtual |
Implemented in Histogram2D, and Histogram1D.
Referenced by relativeDifferenceHistogram().
|
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().
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().
const IAxis & IHistogram::getXaxis | ( | ) | const |
returns x-axis
Definition at line 44 of file IHistogram.cpp.
References check_x_axis(), OutputData< T >::getAxis(), and m_data.
Referenced by Histogram2D::create_projectionX(), Histogram1D::crop(), Histogram2D::crop(), Histogram1D::fill(), Histogram2D::fill(), SpectrumUtils::FindPeaks(), Histogram1D::getBinCenters(), getNbinsX(), getXmax(), getXmin(), Histogram2D::projectionX(), and Histogram2D::projectionY().
const IAxis & IHistogram::getYaxis | ( | ) | const |
returns y-axis for 2D histograms
Definition at line 50 of file IHistogram.cpp.
References check_y_axis(), OutputData< T >::getAxis(), and m_data.
Referenced by Histogram2D::create_projectionY(), Histogram2D::crop(), Histogram2D::fill(), SpectrumUtils::FindPeaks(), getNbinsY(), getYmax(), getYmin(), and Histogram2D::projectionX().
double IHistogram::getXmin | ( | ) | const |
Returns x-axis min (lower edge of first bin).
Definition at line 56 of file IHistogram.cpp.
References IAxis::getMin(), and getXaxis().
double IHistogram::getXmax | ( | ) | const |
Returns x-axis max (upper edge of last bin).
Definition at line 61 of file IHistogram.cpp.
References IAxis::getMax(), and getXaxis().
size_t IHistogram::getNbinsX | ( | ) | const |
Returns number of bins on x-axis.
Definition at line 66 of file IHistogram.cpp.
References getXaxis(), and IAxis::size().
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::getMin(), and getYaxis().
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::getMax(), and getYaxis().
size_t IHistogram::getNbinsY | ( | ) | const |
Returns number of bins on y-axis.
Definition at line 81 of file IHistogram.cpp.
References getYaxis(), and IAxis::size().
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 getRank(), m_data, and OutputData< T >::toGlobalIndex().
Referenced by getBinAverage(), getBinContent(), getBinError(), and getBinNumberOfEntries().
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(), getRank(), and m_data.
size_t IHistogram::getXaxisIndex | ( | 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().
size_t IHistogram::getYaxisIndex | ( | 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::getXaxisValue | ( | 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().
double IHistogram::getYaxisValue | ( | 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().
double IHistogram::getBinContent | ( | size_t | i | ) | const |
Returns content (accumulated value) of bin i.
Definition at line 126 of file IHistogram.cpp.
References m_data.
Referenced by Histogram2D::create_projectionX(), Histogram2D::create_projectionY(), getBinContent(), getBinData(), operator+=(), and relativeDifferenceHistogram().
|
inline |
Definition at line 92 of file IHistogram.h.
References m_data.
Referenced by IntensityDataFunctions::getRelativeDifference().
|
inline |
double IHistogram::getBinContent | ( | size_t | binx, |
size_t | biny | ||
) | const |
Returns content (accumulated value) of the 2D histogram bin.
Definition at line 131 of file IHistogram.cpp.
References getBinContent(), and getGlobalBin().
void IHistogram::setBinContent | ( | size_t | i, |
double | value | ||
) |
Sets content of the bin corresponding to the globalbin number.
Definition at line 136 of file IHistogram.cpp.
References m_data.
Referenced by relativeDifferenceHistogram().
void IHistogram::addBinContent | ( | size_t | i, |
double | value | ||
) |
Add the value to the bin.
Definition at line 141 of file IHistogram.cpp.
References m_data.
Referenced by operator+=().
double IHistogram::getBinError | ( | size_t | i | ) | const |
Returns error of the bin with given index.
Definition at line 146 of file IHistogram.cpp.
References m_data.
Referenced by getBinData(), and getBinError().
double IHistogram::getBinError | ( | size_t | binx, |
size_t | biny | ||
) | const |
Returns error of the bin with given indices (for 2D histograms).
Definition at line 151 of file IHistogram.cpp.
References getBinError(), and getGlobalBin().
double IHistogram::getBinAverage | ( | size_t | i | ) | const |
Returns average value in the bin with given index.
Definition at line 156 of file IHistogram.cpp.
References m_data.
Referenced by getBinAverage(), and getBinData().
double IHistogram::getBinAverage | ( | size_t | binx, |
size_t | biny | ||
) | const |
Returns average value of the bin with given indices (for 2D histograms).
Definition at line 161 of file IHistogram.cpp.
References getBinAverage(), and getGlobalBin().
int IHistogram::getBinNumberOfEntries | ( | size_t | i | ) | const |
Returns number of entries in the bin with given index.
Definition at line 166 of file IHistogram.cpp.
References m_data.
Referenced by getBinData(), and getBinNumberOfEntries().
int IHistogram::getBinNumberOfEntries | ( | size_t | binx, |
size_t | biny | ||
) | const |
Returns number of entries in the bin with given indices (for 2D histograms).
Definition at line 171 of file IHistogram.cpp.
References getBinNumberOfEntries(), and getGlobalBin().
double IHistogram::getMaximum | ( | ) | const |
Returns histogram maximum value (maximum of getBinContent() over all bins)
Definition at line 176 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 182 of file IHistogram.cpp.
References OutputData< T >::begin(), OutputData< T >::end(), and m_data.
double IHistogram::getMinimum | ( | ) | const |
Returns histogram minimum value (minimum of getBinContent() over all bins)
Definition at line 188 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 194 of file IHistogram.cpp.
References OutputData< T >::begin(), OutputData< T >::end(), and m_data.
void IHistogram::scale | ( | double | value | ) |
Multiply this histogram (every bin content value) by a constant.
Definition at line 199 of file IHistogram.cpp.
References getTotalNumberOfBins(), and m_data.
double IHistogram::integral | ( | ) | const |
Returns integral of bins content (computed as a sum of all bin content).
Definition at line 206 of file IHistogram.cpp.
References getTotalNumberOfBins(), and m_data.
Returns numpy array with bin content (accumulated values).
Definition at line 216 of file IHistogram.cpp.
References createOutputData().
Referenced by getArray().
Definition at line 222 of file IHistogram.cpp.
References array().
void IHistogram::reset | ( | ) |
Reset histogram content (axes remains)
Definition at line 228 of file IHistogram.cpp.
References m_data, and OutputData< T >::setAllTo().
Referenced by copyContentFrom(), relativeDifferenceHistogram(), and Histogram2D::setContent().
|
static |
Definition at line 233 of file IHistogram.cpp.
References OutputData< T >::getRank().
Referenced by DetectorMask::createHistogram(), and IntensityDataIOFactory::readIntensityData().
|
static |
create new histogram from file content
Definition at line 248 of file IHistogram.cpp.
References FileSystemUtils::filename(), and IntensityDataIOFactory::readIntensityData().
|
static |
create new histogram from numpy array
Definition at line 253 of file IHistogram.cpp.
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.
References OutputData< T >::copyShapeFrom(), getBinData(), getTotalNumberOfBins(), and m_data.
Referenced by array(), SpectrumUtils::FindPeaks(), and IntensityDataIOFactory::writeIntensityData().
bool IHistogram::hasSameShape | ( | const IHistogram & | other | ) | const |
Returns true if objects a) have same dimensions b) bin boundaries of axes coincide.
Definition at line 344 of file IHistogram.cpp.
References OutputData< T >::hasSameShape(), and m_data.
bool IHistogram::hasSameDimensions | ( | const IHistogram & | other | ) | const |
Returns true if object have same rank and number of axes bins.
Definition at line 349 of file IHistogram.cpp.
References OutputData< T >::hasSameDimensions(), and m_data.
Referenced by copyContentFrom(), operator+=(), and relativeDifferenceHistogram().
const IHistogram & IHistogram::operator+= | ( | const IHistogram & | right | ) |
addition-assignment operator for two histograms
Definition at line 354 of file IHistogram.cpp.
References addBinContent(), getBinContent(), getTotalNumberOfBins(), and hasSameDimensions().
IHistogram * IHistogram::relativeDifferenceHistogram | ( | const IHistogram & | rhs | ) |
returns histogram representing relative difference of two histograms.
Definition at line 364 of file IHistogram.cpp.
References clone(), getBinContent(), Numeric::GetRelativeDifference(), getTotalNumberOfBins(), hasSameDimensions(), reset(), and setBinContent().
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 380 of file IHistogram.cpp.
References FileSystemUtils::filename(), and IntensityDataIOFactory::writeIntensityData().
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 385 of file IHistogram.cpp.
References copyContentFrom(), FileSystemUtils::filename(), and IntensityDataIOFactory::readIntensityData().
|
protected |
Definition at line 258 of file IHistogram.cpp.
References getRank().
Referenced by getXaxis(), and getXaxisValue().
|
protected |
Definition at line 268 of file IHistogram.cpp.
References getRank().
Referenced by getYaxis(), and getYaxisValue().
|
protected |
Definition at line 278 of file IHistogram.cpp.
References OutputData< T >::copyShapeFrom(), OutputData< T >::getAllocatedSize(), OutputData< T >::getRank(), getRank(), and m_data.
Referenced by Histogram1D::Histogram1D(), and Histogram2D::Histogram2D().
|
protected |
returns data of requested type for globalbin number
Definition at line 295 of file IHistogram.cpp.
References getBinAverage(), getBinContent(), getBinError(), and getBinNumberOfEntries().
Referenced by createOutputData(), and getDataVector().
|
protected |
returns vector of values of requested DataType
Definition at line 311 of file IHistogram.cpp.
References getBinData(), and getTotalNumberOfBins().
Referenced by Histogram1D::getBinErrors(), and Histogram1D::getBinValues().
|
protected |
Copy content (but not the axes) from other histogram. Dimensions should be the same.
Definition at line 322 of file IHistogram.cpp.
References getTotalNumberOfBins(), hasSameDimensions(), m_data, and reset().
Referenced by load().
|
protected |
Definition at line 193 of file IHistogram.h.
Referenced by addBinContent(), Histogram2D::addContent(), copyContentFrom(), createOutputData(), Histogram1D::crop(), Histogram2D::crop(), Histogram1D::fill(), Histogram2D::fill(), findGlobalBin(), getBinAverage(), getBinContent(), getBinError(), getBinNumberOfEntries(), getData(), getGlobalBin(), getMaximum(), getMaximumBinIndex(), getMinimum(), getMinimumBinIndex(), getTotalNumberOfBins(), getXaxis(), getXaxisIndex(), getXaxisValue(), getYaxis(), getYaxisIndex(), getYaxisValue(), hasSameDimensions(), hasSameShape(), Histogram1D::Histogram1D(), Histogram2D::Histogram2D(), IHistogram(), init_from_data(), Histogram2D::initFromShape(), integral(), reset(), scale(), and setBinContent().