88 std::vector<unsigned> axes_indices;
89 axes_indices.push_back(
static_cast<unsigned>(binx));
91 axes_indices.push_back(
static_cast<unsigned>(biny));
97 std::vector<double> coordinates;
98 coordinates.push_back(x);
100 coordinates.push_back(y);
138 return m_data[i].getContent();
148 m_data[i].setContent(value);
158 return m_data[i].getRMS();
168 return m_data[i].getAverage();
178 return m_data[i].getNumberOfEntries();
189 return it->getContent();
201 return it->getContent();
212 m_data[index].setContent(value *
m_data[index].getContent());
220 result +=
m_data[index].getContent();
225 #ifdef BORNAGAIN_PYTHON
229 return data->getArray();
234 return array(dataType);
245 if (source.
rank() == 1) {
247 }
else if (source.
rank() == 2) {
250 std::ostringstream message;
251 message <<
"IHistogram::createHistogram(const OutputData<double>& source) -> Error. ";
252 message <<
"The rank of source " << source.
rank() <<
" ";
253 message <<
"is not suitable for creation neither 1-dim nor 2-dim histograms.";
254 throw std::runtime_error(message.str());
271 std::ostringstream message;
272 message <<
"IHistogram::check_x_axis() -> Error. X-xis does not exist. ";
273 message <<
"Rank of histogram " <<
rank() <<
"." << std::endl;
274 throw std::runtime_error(message.str());
281 std::ostringstream message;
282 message <<
"IHistogram::check_y_axis() -> Error. Y-axis does not exist. ";
283 message <<
"Rank of histogram " <<
rank() <<
"." << std::endl;
284 throw std::runtime_error(message.str());
291 std::ostringstream message;
292 message <<
"IHistogram::IHistogram(const OutputData<double>& data) -> Error. ";
293 message <<
"The dimension of this histogram " <<
rank() <<
" ";
294 message <<
"is differ from the dimension of source " <<
m_data.
rank() << std::endl;
295 throw std::runtime_error(message.str());
307 if (dataType == DataType::INTEGRAL) {
309 }
else if (dataType == DataType::AVERAGE) {
311 }
else if (dataType == DataType::STANDARD_ERROR) {
313 }
else if (dataType == DataType::NENTRIES) {
316 throw std::runtime_error(
"IHistogram::binData() -> Error. Unknown data type.");
322 std::vector<double> result;
325 result[index] =
binData(index, dataType);
334 throw std::runtime_error(
335 "IHistogram::copyContentFrom() -> Error. Can't copy the data of different shape.");
348 (*result)[i] =
binData(i, dataType);
366 throw std::runtime_error(
367 "IHistogram::operator+=() -> Error. Histograms have different dimension");
376 throw std::runtime_error(
"IHistogram::relativeDifferenceHistogram() -> Error. "
377 "Histograms have different dimensions");
Defines class Histogram1D.
Defines class Histogram2D.
Defines class IntensityDataIOFactory.
Defines constants and "almost equal" in namespace Numeric.
The cumulative value with average and rms on-the-flight calculations.
One dimensional histogram.
Two dimensional histogram.
Interface for one-dimensional axes.
virtual double upperBound() const =0
Returns value of last point of axis.
virtual size_t size() const =0
retrieve the number of bins
virtual double lowerBound() const =0
Returns value of first point of axis.
Base class for 1D and 2D histograms holding values of double type.
double getYmin() const
Returns y-axis min (lower edge of first bin) for 2D histograms.
void addBinContent(size_t i, double value)
Add the value to the bin.
double getYmax() const
Returns y-axis max (upper edge of last bin) for 2D histograms.
void scale(double value)
Multiply this histogram (every bin content value) by a constant.
size_t findGlobalBin(double x, double y) const
Returns closest global bin index for given axes coordinates.
size_t getNbinsY() const
Returns number of bins on y-axis.
size_t getNbinsX() const
Returns number of bins on x-axis.
double binError(size_t i) const
Returns error of the bin with given index.
const IAxis & yAxis() const
returns y-axis for 2D histograms
double yAxisValue(size_t i)
Returns the center of bin i of the y axis.
PyObject * getArray(DataType dataType=DataType::INTEGRAL) const
PyObject * array(DataType dataType=DataType::INTEGRAL) const
Returns numpy array with bin content (accumulated values).
size_t getGlobalBin(size_t binx, size_t biny=0) const
Returns global bin index for given axes indices. For 1D, just returns binx.
const IAxis & xAxis() const
returns x-axis
double binData(size_t i, DataType dataType) const
returns data of requested type for globalbin number
double getMinimum() const
Returns histogram minimum value (minimum of binContent() over all bins)
virtual size_t rank() const =0
Returns number of histogram dimensions.
const OutputData< CumulativeValue > & getData() const
size_t getMinimumBinIndex() const
Returns globalbin index with minimum content.
void load(const std::string &filename)
Loads histogram from file, the shape of array in file should match Following formats are available: *...
void check_x_axis() const
double getXmin() const
Returns x-axis min (lower edge of first bin).
OutputData< double > * createOutputData(DataType dataType=DataType::INTEGRAL) const
creates new OutputData with histogram's shape and values corresponding to DataType
std::vector< double > getDataVector(DataType dataType) const
returns vector of values of requested DataType
OutputData< CumulativeValue > m_data
static IHistogram * createFrom(const std::string &filename)
create new histogram from file content
void setBinContent(size_t i, double value)
Sets content of the bin corresponding to the globalbin number.
double integral() const
Returns integral of bins content (computed as a sum of all bin content).
size_t yAxisIndex(size_t i) const
Returns y-axis index for global bin index i.
IHistogram * relativeDifferenceHistogram(const IHistogram &rhs)
returns histogram representing relative difference of two histograms.
double xAxisValue(size_t i)
Returns the center of bin i of the x axis.
void check_y_axis() const
double binContent(size_t i) const
Returns content (accumulated value) of bin i.
size_t getTotalNumberOfBins() const
Returns total number of histogram bins.
size_t getMaximumBinIndex() const
Returns globalbin index with maximum content.
void copyContentFrom(const IHistogram &other)
Copy content (but not the axes) from other histogram. Dimensions should be the same.
double getMaximum() const
Returns histogram maximum value (maximum of binContent() over all bins)
void save(const std::string &filename)
Saves histogram in file Following formats are available: *.txt, *.tif, *.int (*.txt....
double binAverage(size_t i) const
Returns average value in the bin with given index.
int binNumberOfEntries(size_t i) const
Returns number of entries in the bin with given index.
virtual IHistogram * clone() const =0
void reset()
Reset histogram content (axes remains)
static IHistogram * createHistogram(const OutputData< double > &source)
double getXmax() const
Returns x-axis max (upper edge of last bin).
bool hasSameDimensions(const IHistogram &other) const
Returns true if object have same rank and number of axes bins.
bool hasSameShape(const IHistogram &other) const
Returns true if objects a) have same dimensions b) bin boundaries of axes coincide.
const IHistogram & operator+=(const IHistogram &right)
addition-assignment operator for two histograms
void init_from_data(const OutputData< double > &source)
size_t xAxisIndex(size_t i) const
Returns x-axis index for global bin index i.
static IHistogram * readIntensityData(const std::string &file_name)
Reads file and returns newly created Histogram object.
static void writeIntensityData(const IHistogram &histogram, const std::string &file_name)
Writes histogram in file.
void copyFrom(const OutputData< T > &x)
size_t getAxisBinIndex(size_t global_index, size_t i_selected_axis) const
Returns axis bin index for given global index.
iterator end()
Returns read/write iterator that points to the one past last element.
size_t toGlobalIndex(const std::vector< unsigned > &axes_indices) const
Returns global index for specified indices of axes.
bool hasSameShape(const OutputData< U > &right) const
Returns true if objects a) have same dimensions b) bin boundaries of axes coincide.
size_t rank() const
Returns number of dimensions.
void setAllTo(const T &value)
Sets content of output data to specific value.
size_t findGlobalIndex(const std::vector< double > &coordinates) const
Returns global index for specified axes values.
const IAxis & axis(size_t serial_number) const
returns axis with given serial number
void copyShapeFrom(const OutputData< U > &other)
void addAxis(const IAxis &new_axis)
bool hasSameDimensions(const OutputData< U > &right) const
Returns true if object have same dimensions and number of axes bins.
iterator begin()
Returns read/write iterator that points to the first element.
size_t getAllocatedSize() const
Returns total size of data buffer (product of bin number in every dimension).
double getAxisValue(size_t global_index, size_t i_selected_axis) const
Returns the value of selected axis for given global_index.
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")
double GetRelativeDifference(double a, double b)
Returns the safe relative difference, which is 2(|a-b|)/(|a|+|b|) except in special cases.