21 IHistogram::IHistogram() =
default;
23 IHistogram::IHistogram(
const IHistogram& other)
25 m_data.copyFrom(other.m_data);
28 IHistogram::IHistogram(
const IAxis& axis_x)
30 m_data.addAxis(axis_x);
33 IHistogram::IHistogram(
const IAxis& axis_x,
const IAxis& axis_y)
35 m_data.addAxis(axis_x);
36 m_data.addAxis(axis_y);
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);
128 return m_data[i].getContent();
138 m_data[i].setContent(value);
143 m_data[i].add(value);
148 return m_data[i].getRMS();
158 return m_data[i].getAverage();
168 return m_data[i].getNumberOfEntries();
179 return it->getContent();
185 return std::distance(m_data.
begin(), it);
191 return it->getContent();
196 return std::distance(m_data.
begin(), std::min_element(m_data.
begin(), m_data.
end()));
202 m_data[index].setContent(value * m_data[index].getContent());
210 result += m_data[index].getContent();
215 #ifdef BORNAGAIN_PYTHON
219 return data->getArray();
224 return array(dataType);
237 }
else if (source.
getRank() == 2) {
240 std::ostringstream message;
241 message <<
"IHistogram::createHistogram(const OutputData<double>& source) -> Error. ";
242 message <<
"The rank of source " << source.
getRank() <<
" ";
243 message <<
"is not suitable for creation neither 1-dim nor 2-dim histograms.";
258 void IHistogram::check_x_axis()
const
261 std::ostringstream message;
262 message <<
"IHistogram::check_x_axis() -> Error. X-xis does not exist. ";
263 message <<
"Rank of histogram " <<
getRank() <<
"." << std::endl;
268 void IHistogram::check_y_axis()
const
271 std::ostringstream message;
272 message <<
"IHistogram::check_y_axis() -> Error. Y-axis does not exist. ";
273 message <<
"Rank of histogram " <<
getRank() <<
"." << std::endl;
281 std::ostringstream message;
282 message <<
"IHistogram::IHistogram(const OutputData<double>& data) -> Error. ";
283 message <<
"The dimension of this histogram " <<
getRank() <<
" ";
284 message <<
"is differ from the dimension of source " << m_data.
getRank() << std::endl;
288 m_data.copyShapeFrom(source);
290 m_data[i].add(source[i]);
297 if (dataType == DataType::INTEGRAL) {
299 }
else if (dataType == DataType::AVERAGE) {
301 }
else if (dataType == DataType::STANDARD_ERROR) {
303 }
else if (dataType == DataType::NENTRIES) {
307 "IHistogram::getBinData() -> Error. Unknown data type.");
313 std::vector<double> result;
326 "IHistogram::copyContentFrom() -> Error. Can't copy the data of different shape.");
329 m_data[i] = other.m_data[i];
337 result->copyShapeFrom(m_data);
358 "IHistogram::operator+=() -> Error. Histograms have different dimension");
368 "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 getMin() const =0
Returns value of first point of axis.
virtual size_t size() const =0
retrieve the number of bins
virtual double getMax() const =0
Returns value of last 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.
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.
virtual size_t getRank() const =0
Returns number of histogram dimensions.
double getMinimum() const
Returns histogram minimum value (minimum of getBinContent() over all bins)
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: *...
double getBinData(size_t i, DataType dataType) const
returns data of requested type for globalbin number
double getXmin() const
Returns x-axis min (lower edge of first bin).
double getYaxisValue(size_t i)
Returns the center of bin i of the y axis.
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
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).
double getBinContent(size_t i) const
Returns content (accumulated value) of bin i.
IHistogram * relativeDifferenceHistogram(const IHistogram &rhs)
returns histogram representing relative difference of two histograms.
size_t getYaxisIndex(size_t i) const
Returns y-axis index for global bin index i.
size_t getTotalNumberOfBins() const
Returns total number of histogram bins.
size_t getMaximumBinIndex() const
Returns globalbin index with maximum content.
size_t getXaxisIndex(size_t i) const
Returns x-axis index for global bin index i.
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 getBinContent() over all bins)
void save(const std::string &filename)
Saves histogram in file Following formats are available: *.txt, *.tif, *.int (*.txt....
double getBinError(size_t i) const
Returns error of the bin with given index.
const IAxis & getYaxis() const
returns y-axis for 2D histograms
int getBinNumberOfEntries(size_t i) const
Returns number of entries in the bin with given index.
void reset()
Reset histogram content (axes remains)
double getBinAverage(size_t i) const
Returns average value in the bin with given index.
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.
double getXaxisValue(size_t i)
Returns the center of bin i of the x axis.
const IHistogram & operator+=(const IHistogram &right)
addition-assignment operator for two histograms
const IAxis & getXaxis() const
returns x-axis
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.
Template class to store data of any type in multi-dimensional space.
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.
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.
size_t getRank() const
Returns number of dimensions.
const IAxis & getAxis(size_t serial_number) const
returns axis with given serial number
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.