BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
Histogram1D Class Reference
Inheritance diagram for Histogram1D:
Collaboration diagram for Histogram1D:

Public Types

enum  DataType { INTEGRAL , AVERAGE , STANDARD_ERROR , NENTRIES }
 

Public Member Functions

 Histogram1D (int nbinsx, double xlow, double xup)
 
 Histogram1D (int nbinsx, const std::vector< double > &xbins)
 
 Histogram1D (const IAxis &axis)
 
 Histogram1D (const OutputData< double > &data)
 
Histogram1Dclone () const
 
size_t getRank () const
 
int fill (double x, double weight=1.0)
 
std::vector< double > getBinCenters () const
 
std::vector< double > getBinValues () const
 
std::vector< double > getBinErrors () const
 
PyObjectgetBinCentersNumpy () const
 
PyObjectgetBinValuesNumpy () const
 
PyObjectgetBinErrorsNumpy () const
 
Histogram1Dcrop (double xmin, double xmax)
 
size_t getTotalNumberOfBins () const
 
const IAxisgetXaxis () const
 
const IAxisgetYaxis () 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
 
double getBinContent (size_t binx, size_t biny) const
 
const OutputData< CumulativeValue > & getData () const
 
OutputData< CumulativeValue > & getData ()
 
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
 
PyObjectarray (DataType dataType=DataType::INTEGRAL) const
 
PyObjectgetArray (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 IHistogramoperator+= (const IHistogram &right)
 
IHistogramrelativeDifferenceHistogram (const IHistogram &rhs)
 
void save (const std::string &filename)
 
void load (const std::string &filename)
 

Static Public Member Functions

static IHistogramcreateHistogram (const OutputData< double > &source)
 
static IHistogramcreateFrom (const std::string &filename)
 
static IHistogramcreateFrom (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< CumulativeValuem_data
 

Detailed Description

One dimensional histogram.

Definition at line 23 of file Histogram1D.h.

Member Enumeration Documentation

◆ DataType

enum IHistogram::DataType
inherited
Enumerator
INTEGRAL 
AVERAGE 
STANDARD_ERROR 
NENTRIES 

Definition at line 29 of file IHistogram.h.

Constructor & Destructor Documentation

◆ Histogram1D() [1/4]

Histogram1D::Histogram1D ( int  nbinsx,
double  xlow,
double  xup 
)

Constructor for fix bin size histograms.

Parameters
nbinsxnumber of bins
xlowlow edge of the first bin
xupupper edge of the last bin

Definition at line 20 of file Histogram1D.cpp.

21 {
22  m_data.addAxis(FixedBinAxis("x-axis", nbinsx, xlow, xup));
23 }
Axis with fixed bin size.
Definition: FixedBinAxis.h:24
OutputData< CumulativeValue > m_data
Definition: IHistogram.h:193
void addAxis(const IAxis &new_axis)
Definition: OutputData.h:289

References OutputData< T >::addAxis(), and IHistogram::m_data.

Referenced by clone(), and crop().

Here is the call graph for this function:

◆ Histogram1D() [2/4]

Histogram1D::Histogram1D ( int  nbinsx,
const std::vector< double > &  xbins 
)

Constructor for variable bin size histograms.

Parameters
nbinsxnumber of bins
xbinsArray of size nbins+1 containing low-edges for each bin and upper edge of last bin.

Definition at line 25 of file Histogram1D.cpp.

26 {
27  m_data.addAxis(VariableBinAxis("x-axis", nbinsx, xbins));
28 }
Axis with variable bin size.

References OutputData< T >::addAxis(), and IHistogram::m_data.

Here is the call graph for this function:

◆ Histogram1D() [3/4]

Histogram1D::Histogram1D ( const IAxis axis)

Constructor for 1D histogram with custom axis.

Definition at line 30 of file Histogram1D.cpp.

30 : IHistogram(axis) {}

◆ Histogram1D() [4/4]

Histogram1D::Histogram1D ( const OutputData< double > &  data)

Constructor for 1D histograms from basic OutputData object.

Definition at line 32 of file Histogram1D.cpp.

33 {
34  init_from_data(data);
35 }
void init_from_data(const OutputData< double > &source)
Definition: IHistogram.cpp:278

References IHistogram::init_from_data().

Here is the call graph for this function:

Member Function Documentation

◆ clone()

Histogram1D * Histogram1D::clone ( ) const
virtual

Returns clone of other histogram.

Implements IHistogram.

Definition at line 37 of file Histogram1D.cpp.

38 {
39  return new Histogram1D(*this);
40 }
Histogram1D(int nbinsx, double xlow, double xup)
Constructor for fix bin size histograms.
Definition: Histogram1D.cpp:20

References Histogram1D().

Here is the call graph for this function:

◆ getRank()

size_t Histogram1D::getRank ( ) const
inlinevirtual

Returns the number of histogram dimensions.

Implements IHistogram.

Definition at line 48 of file Histogram1D.h.

48 { return 1; }

◆ fill()

int Histogram1D::fill ( double  x,
double  weight = 1.0 
)

Increment bin with abscissa x with a weight.

Definition at line 42 of file Histogram1D.cpp.

43 {
44  const IAxis& axis = getXaxis();
45  if (x < axis.getMin() || x >= axis.getMax())
46  return -1;
47  size_t index = axis.findClosestIndex(x);
48  m_data[index].add(weight);
49  return (int)index;
50 }
Interface for one-dimensional axes.
Definition: IAxis.h:25
virtual size_t findClosestIndex(double value) const =0
find bin index which is best match for given value
virtual double getMin() const =0
Returns value of first point of axis.
virtual double getMax() const =0
Returns value of last point of axis.
const IAxis & getXaxis() const
returns x-axis
Definition: IHistogram.cpp:44

References IAxis::findClosestIndex(), IAxis::getMax(), IAxis::getMin(), IHistogram::getXaxis(), and IHistogram::m_data.

Referenced by Histogram2D::create_projectionX(), and Histogram2D::create_projectionY().

Here is the call graph for this function:

◆ getBinCenters()

std::vector< double > Histogram1D::getBinCenters ( ) const

returns vector of histogram bin centers

Definition at line 52 of file Histogram1D.cpp.

53 {
54  return getXaxis().getBinCenters();
55 }
virtual std::vector< double > getBinCenters() const
Definition: IAxis.cpp:23

References IAxis::getBinCenters(), and IHistogram::getXaxis().

Referenced by getBinCentersNumpy().

Here is the call graph for this function:

◆ getBinValues()

std::vector< double > Histogram1D::getBinValues ( ) const

returns vector of bin content (the value accumulated by bins)

Definition at line 57 of file Histogram1D.cpp.

58 {
59  return IHistogram::getDataVector(IHistogram::DataType::INTEGRAL);
60 }
std::vector< double > getDataVector(DataType dataType) const
returns vector of values of requested DataType
Definition: IHistogram.cpp:311

References IHistogram::getDataVector().

Referenced by getBinValuesNumpy().

Here is the call graph for this function:

◆ getBinErrors()

std::vector< double > Histogram1D::getBinErrors ( ) const

returns vector of bin errors

Definition at line 62 of file Histogram1D.cpp.

63 {
64  return IHistogram::getDataVector(IHistogram::DataType::STANDARD_ERROR);
65 }

References IHistogram::getDataVector().

Referenced by getBinErrorsNumpy().

Here is the call graph for this function:

◆ getBinCentersNumpy()

PyObject * Histogram1D::getBinCentersNumpy ( ) const

Definition at line 69 of file Histogram1D.cpp.

70 {
72 }
std::vector< double > getBinCenters() const
returns vector of histogram bin centers
Definition: Histogram1D.cpp:52
PyObject * createNumpyArray(const std::vector< double > &data)
Definition: ArrayUtils.cpp:20

References ArrayUtils::createNumpyArray(), and getBinCenters().

Here is the call graph for this function:

◆ getBinValuesNumpy()

PyObject * Histogram1D::getBinValuesNumpy ( ) const

Definition at line 74 of file Histogram1D.cpp.

75 {
77 }
std::vector< double > getBinValues() const
returns vector of bin content (the value accumulated by bins)
Definition: Histogram1D.cpp:57

References ArrayUtils::createNumpyArray(), and getBinValues().

Here is the call graph for this function:

◆ getBinErrorsNumpy()

PyObject * Histogram1D::getBinErrorsNumpy ( ) const

Definition at line 79 of file Histogram1D.cpp.

80 {
82 }
std::vector< double > getBinErrors() const
returns vector of bin errors
Definition: Histogram1D.cpp:62

References ArrayUtils::createNumpyArray(), and getBinErrors().

Here is the call graph for this function:

◆ crop()

Histogram1D * Histogram1D::crop ( double  xmin,
double  xmax 
)

Creates new histogram by applying crop on axis.

Definition at line 86 of file Histogram1D.cpp.

87 {
88  const std::unique_ptr<IAxis> xaxis(getXaxis().createClippedAxis(xmin, xmax));
89  Histogram1D* result = new Histogram1D(*xaxis);
92  while (it_origin != m_data.end()) {
93  double x = m_data.getAxisValue(it_origin.getIndex(), 0);
94  if (result->getXaxis().contains(x)) {
95  *it_result = *it_origin;
96  ++it_result;
97  }
98  ++it_origin;
99  }
100  return result;
101 }
One dimensional histogram.
Definition: Histogram1D.h:24
virtual bool contains(double value) const
Returns true if axis contains given point.
Definition: IAxis.cpp:40
Template class to store data of any type in multi-dimensional space.
Definition: OutputData.h:33
iterator end()
Returns read/write iterator that points to the one past last element.
Definition: OutputData.h:96
iterator begin()
Returns read/write iterator that points to the first element.
Definition: OutputData.h:344
double getAxisValue(size_t global_index, size_t i_selected_axis) const
Returns the value of selected axis for given global_index.
Definition: OutputData.h:433

References OutputData< T >::begin(), IAxis::contains(), OutputData< T >::end(), OutputData< T >::getAxisValue(), IHistogram::getXaxis(), Histogram1D(), and IHistogram::m_data.

Here is the call graph for this function:

◆ getTotalNumberOfBins()

size_t IHistogram::getTotalNumberOfBins ( ) const
inherited

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.

40 {
41  return m_data.getAllocatedSize();
42 }
size_t getAllocatedSize() const
Returns total size of data buffer (product of bin number in every dimension).
Definition: OutputData.h:62

References OutputData< T >::getAllocatedSize(), and IHistogram::m_data.

Referenced by IHistogram::copyContentFrom(), Histogram2D::create_projectionX(), Histogram2D::create_projectionY(), IHistogram::createOutputData(), IHistogram::getDataVector(), IHistogram::integral(), IHistogram::operator+=(), IHistogram::relativeDifferenceHistogram(), and IHistogram::scale().

Here is the call graph for this function:

◆ getXaxis()

const IAxis & IHistogram::getXaxis ( ) const
inherited

returns x-axis

Definition at line 44 of file IHistogram.cpp.

45 {
46  check_x_axis();
47  return m_data.getAxis(0);
48 }
void check_x_axis() const
Definition: IHistogram.cpp:258
const IAxis & getAxis(size_t serial_number) const
returns axis with given serial number
Definition: OutputData.h:314

References IHistogram::check_x_axis(), OutputData< T >::getAxis(), and IHistogram::m_data.

Referenced by Histogram2D::create_projectionX(), crop(), Histogram2D::crop(), fill(), Histogram2D::fill(), SpectrumUtils::FindPeaks(), getBinCenters(), IHistogram::getNbinsX(), IHistogram::getXmax(), IHistogram::getXmin(), Histogram2D::projectionX(), and Histogram2D::projectionY().

Here is the call graph for this function:

◆ getYaxis()

const IAxis & IHistogram::getYaxis ( ) const
inherited

returns y-axis for 2D histograms

Definition at line 50 of file IHistogram.cpp.

51 {
52  check_y_axis();
53  return m_data.getAxis(1);
54 }
void check_y_axis() const
Definition: IHistogram.cpp:268

References IHistogram::check_y_axis(), OutputData< T >::getAxis(), and IHistogram::m_data.

Referenced by Histogram2D::create_projectionY(), Histogram2D::crop(), Histogram2D::fill(), SpectrumUtils::FindPeaks(), IHistogram::getNbinsY(), IHistogram::getYmax(), IHistogram::getYmin(), and Histogram2D::projectionX().

Here is the call graph for this function:

◆ getXmin()

double IHistogram::getXmin ( ) const
inherited

Returns x-axis min (lower edge of first bin).

Definition at line 56 of file IHistogram.cpp.

57 {
58  return getXaxis().getMin();
59 }

References IAxis::getMin(), and IHistogram::getXaxis().

Here is the call graph for this function:

◆ getXmax()

double IHistogram::getXmax ( ) const
inherited

Returns x-axis max (upper edge of last bin).

Definition at line 61 of file IHistogram.cpp.

62 {
63  return getXaxis().getMax();
64 }

References IAxis::getMax(), and IHistogram::getXaxis().

Here is the call graph for this function:

◆ getNbinsX()

size_t IHistogram::getNbinsX ( ) const
inherited

Returns number of bins on x-axis.

Definition at line 66 of file IHistogram.cpp.

67 {
68  return getXaxis().size();
69 }
virtual size_t size() const =0
retrieve the number of bins

References IHistogram::getXaxis(), and IAxis::size().

Here is the call graph for this function:

◆ getYmin()

double IHistogram::getYmin ( ) const
inherited

Returns y-axis min (lower edge of first bin) for 2D histograms.

Definition at line 71 of file IHistogram.cpp.

72 {
73  return getYaxis().getMin();
74 }
const IAxis & getYaxis() const
returns y-axis for 2D histograms
Definition: IHistogram.cpp:50

References IAxis::getMin(), and IHistogram::getYaxis().

Here is the call graph for this function:

◆ getYmax()

double IHistogram::getYmax ( ) const
inherited

Returns y-axis max (upper edge of last bin) for 2D histograms.

Definition at line 76 of file IHistogram.cpp.

77 {
78  return getYaxis().getMax();
79 }

References IAxis::getMax(), and IHistogram::getYaxis().

Here is the call graph for this function:

◆ getNbinsY()

size_t IHistogram::getNbinsY ( ) const
inherited

Returns number of bins on y-axis.

Definition at line 81 of file IHistogram.cpp.

82 {
83  return getYaxis().size();
84 }

References IHistogram::getYaxis(), and IAxis::size().

Here is the call graph for this function:

◆ getGlobalBin()

size_t IHistogram::getGlobalBin ( size_t  binx,
size_t  biny = 0 
) const
inherited

Returns global bin index for given axes indices. For 1D, just returns binx.

Definition at line 86 of file IHistogram.cpp.

87 {
88  std::vector<unsigned> axes_indices;
89  axes_indices.push_back(static_cast<unsigned>(binx));
90  if (getRank() == 2)
91  axes_indices.push_back(static_cast<unsigned>(biny));
92  return m_data.toGlobalIndex(axes_indices);
93 }
virtual size_t getRank() const =0
Returns number of histogram dimensions.
size_t toGlobalIndex(const std::vector< unsigned > &axes_indices) const
Returns global index for specified indices of axes.
Definition: OutputData.h:393

References IHistogram::getRank(), IHistogram::m_data, and OutputData< T >::toGlobalIndex().

Referenced by IHistogram::getBinAverage(), IHistogram::getBinContent(), IHistogram::getBinError(), and IHistogram::getBinNumberOfEntries().

Here is the call graph for this function:

◆ findGlobalBin()

size_t IHistogram::findGlobalBin ( double  x,
double  y 
) const
inherited

Returns closest global bin index for given axes coordinates.

Definition at line 95 of file IHistogram.cpp.

96 {
97  std::vector<double> coordinates;
98  coordinates.push_back(x);
99  if (getRank() == 2)
100  coordinates.push_back(y);
101  return m_data.findGlobalIndex(coordinates);
102 }
size_t findGlobalIndex(const std::vector< double > &coordinates) const
Returns global index for specified axes values.
Definition: OutputData.h:418

References OutputData< T >::findGlobalIndex(), IHistogram::getRank(), and IHistogram::m_data.

Here is the call graph for this function:

◆ getXaxisIndex()

size_t IHistogram::getXaxisIndex ( size_t  i) const
inherited

Returns x-axis index for global bin index i.

Definition at line 104 of file IHistogram.cpp.

105 {
106  return m_data.getAxisBinIndex(i, 0);
107 }
size_t getAxisBinIndex(size_t global_index, size_t i_selected_axis) const
Returns axis bin index for given global index.
Definition: OutputData.h:371

References OutputData< T >::getAxisBinIndex(), and IHistogram::m_data.

Referenced by Histogram2D::create_projectionY().

Here is the call graph for this function:

◆ getYaxisIndex()

size_t IHistogram::getYaxisIndex ( size_t  i) const
inherited

Returns y-axis index for global bin index i.

Definition at line 109 of file IHistogram.cpp.

110 {
111  return m_data.getAxisBinIndex(i, 1);
112 }

References OutputData< T >::getAxisBinIndex(), and IHistogram::m_data.

Referenced by Histogram2D::create_projectionX().

Here is the call graph for this function:

◆ getXaxisValue()

double IHistogram::getXaxisValue ( size_t  i)
inherited

Returns the center of bin i of the x axis.

Definition at line 114 of file IHistogram.cpp.

115 {
116  check_x_axis();
117  return m_data.getAxisValue(i, 0);
118 }

References IHistogram::check_x_axis(), OutputData< T >::getAxisValue(), and IHistogram::m_data.

Referenced by Histogram2D::create_projectionX().

Here is the call graph for this function:

◆ getYaxisValue()

double IHistogram::getYaxisValue ( size_t  i)
inherited

Returns the center of bin i of the y axis.

Definition at line 120 of file IHistogram.cpp.

121 {
122  check_y_axis();
123  return m_data.getAxisValue(i, 1);
124 }

References IHistogram::check_y_axis(), OutputData< T >::getAxisValue(), and IHistogram::m_data.

Referenced by Histogram2D::create_projectionY().

Here is the call graph for this function:

◆ getBinContent() [1/2]

double IHistogram::getBinContent ( size_t  i) const
inherited

Returns content (accumulated value) of bin i.

Definition at line 126 of file IHistogram.cpp.

127 {
128  return m_data[i].getContent();
129 }

References IHistogram::m_data.

Referenced by Histogram2D::create_projectionX(), Histogram2D::create_projectionY(), IHistogram::getBinContent(), IHistogram::getBinData(), IHistogram::operator+=(), and IHistogram::relativeDifferenceHistogram().

◆ getBinContent() [2/2]

double IHistogram::getBinContent ( size_t  binx,
size_t  biny 
) const
inherited

Returns content (accumulated value) of the 2D histogram bin.

Definition at line 131 of file IHistogram.cpp.

132 {
133  return getBinContent(getGlobalBin(binx, biny));
134 }
size_t getGlobalBin(size_t binx, size_t biny=0) const
Returns global bin index for given axes indices. For 1D, just returns binx.
Definition: IHistogram.cpp:86
double getBinContent(size_t i) const
Returns content (accumulated value) of bin i.
Definition: IHistogram.cpp:126

References IHistogram::getBinContent(), and IHistogram::getGlobalBin().

Here is the call graph for this function:

◆ getData() [1/2]

const OutputData<CumulativeValue>& IHistogram::getData ( ) const
inlineinherited

Definition at line 92 of file IHistogram.h.

92 { return m_data; }

References IHistogram::m_data.

Referenced by IntensityDataFunctions::getRelativeDifference().

◆ getData() [2/2]

OutputData<CumulativeValue>& IHistogram::getData ( )
inlineinherited

Definition at line 93 of file IHistogram.h.

93 { return m_data; }

References IHistogram::m_data.

◆ setBinContent()

void IHistogram::setBinContent ( size_t  i,
double  value 
)
inherited

Sets content of the bin corresponding to the globalbin number.

Definition at line 136 of file IHistogram.cpp.

137 {
138  m_data[i].setContent(value);
139 }

References IHistogram::m_data.

Referenced by IHistogram::relativeDifferenceHistogram().

◆ addBinContent()

void IHistogram::addBinContent ( size_t  i,
double  value 
)
inherited

Add the value to the bin.

Definition at line 141 of file IHistogram.cpp.

142 {
143  m_data[i].add(value);
144 }

References IHistogram::m_data.

Referenced by IHistogram::operator+=().

◆ getBinError() [1/2]

double IHistogram::getBinError ( size_t  i) const
inherited

Returns error of the bin with given index.

Definition at line 146 of file IHistogram.cpp.

147 {
148  return m_data[i].getRMS();
149 }

References IHistogram::m_data.

Referenced by IHistogram::getBinData(), and IHistogram::getBinError().

◆ getBinError() [2/2]

double IHistogram::getBinError ( size_t  binx,
size_t  biny 
) const
inherited

Returns error of the bin with given indices (for 2D histograms).

Definition at line 151 of file IHistogram.cpp.

152 {
153  return getBinError(getGlobalBin(binx, biny));
154 }
double getBinError(size_t i) const
Returns error of the bin with given index.
Definition: IHistogram.cpp:146

References IHistogram::getBinError(), and IHistogram::getGlobalBin().

Here is the call graph for this function:

◆ getBinAverage() [1/2]

double IHistogram::getBinAverage ( size_t  i) const
inherited

Returns average value in the bin with given index.

Definition at line 156 of file IHistogram.cpp.

157 {
158  return m_data[i].getAverage();
159 }

References IHistogram::m_data.

Referenced by IHistogram::getBinAverage(), and IHistogram::getBinData().

◆ getBinAverage() [2/2]

double IHistogram::getBinAverage ( size_t  binx,
size_t  biny 
) const
inherited

Returns average value of the bin with given indices (for 2D histograms).

Definition at line 161 of file IHistogram.cpp.

162 {
163  return getBinAverage(getGlobalBin(binx, biny));
164 }
double getBinAverage(size_t i) const
Returns average value in the bin with given index.
Definition: IHistogram.cpp:156

References IHistogram::getBinAverage(), and IHistogram::getGlobalBin().

Here is the call graph for this function:

◆ getBinNumberOfEntries() [1/2]

int IHistogram::getBinNumberOfEntries ( size_t  i) const
inherited

Returns number of entries in the bin with given index.

Definition at line 166 of file IHistogram.cpp.

167 {
168  return m_data[i].getNumberOfEntries();
169 }

References IHistogram::m_data.

Referenced by IHistogram::getBinData(), and IHistogram::getBinNumberOfEntries().

◆ getBinNumberOfEntries() [2/2]

int IHistogram::getBinNumberOfEntries ( size_t  binx,
size_t  biny 
) const
inherited

Returns number of entries in the bin with given indices (for 2D histograms).

Definition at line 171 of file IHistogram.cpp.

172 {
173  return getBinNumberOfEntries(getGlobalBin(binx, biny));
174 }
int getBinNumberOfEntries(size_t i) const
Returns number of entries in the bin with given index.
Definition: IHistogram.cpp:166

References IHistogram::getBinNumberOfEntries(), and IHistogram::getGlobalBin().

Here is the call graph for this function:

◆ getMaximum()

double IHistogram::getMaximum ( ) const
inherited

Returns histogram maximum value (maximum of getBinContent() over all bins)

Definition at line 176 of file IHistogram.cpp.

177 {
179  return it->getContent();
180 }

References OutputData< T >::begin(), OutputData< T >::end(), and IHistogram::m_data.

Here is the call graph for this function:

◆ getMaximumBinIndex()

size_t IHistogram::getMaximumBinIndex ( ) const
inherited

Returns globalbin index with maximum content.

Definition at line 182 of file IHistogram.cpp.

183 {
185  return std::distance(m_data.begin(), it);
186 }

References OutputData< T >::begin(), OutputData< T >::end(), and IHistogram::m_data.

Here is the call graph for this function:

◆ getMinimum()

double IHistogram::getMinimum ( ) const
inherited

Returns histogram minimum value (minimum of getBinContent() over all bins)

Definition at line 188 of file IHistogram.cpp.

189 {
191  return it->getContent();
192 }

References OutputData< T >::begin(), OutputData< T >::end(), and IHistogram::m_data.

Here is the call graph for this function:

◆ getMinimumBinIndex()

size_t IHistogram::getMinimumBinIndex ( ) const
inherited

Returns globalbin index with minimum content.

Definition at line 194 of file IHistogram.cpp.

195 {
196  return std::distance(m_data.begin(), std::min_element(m_data.begin(), m_data.end()));
197 }

References OutputData< T >::begin(), OutputData< T >::end(), and IHistogram::m_data.

Here is the call graph for this function:

◆ scale()

void IHistogram::scale ( double  value)
inherited

Multiply this histogram (every bin content value) by a constant.

Definition at line 199 of file IHistogram.cpp.

200 {
201  for (size_t index = 0; index < getTotalNumberOfBins(); ++index) {
202  m_data[index].setContent(value * m_data[index].getContent());
203  }
204 }
size_t getTotalNumberOfBins() const
Returns total number of histogram bins.
Definition: IHistogram.cpp:39

References IHistogram::getTotalNumberOfBins(), and IHistogram::m_data.

Here is the call graph for this function:

◆ integral()

double IHistogram::integral ( ) const
inherited

Returns integral of bins content (computed as a sum of all bin content).

Definition at line 206 of file IHistogram.cpp.

207 {
208  double result(0.0);
209  for (size_t index = 0; index < getTotalNumberOfBins(); ++index) {
210  result += m_data[index].getContent();
211  }
212  return result;
213 }

References IHistogram::getTotalNumberOfBins(), and IHistogram::m_data.

Here is the call graph for this function:

◆ array()

PyObject * IHistogram::array ( DataType  dataType = DataType::INTEGRAL) const
inherited

Returns numpy array with bin content (accumulated values).

Definition at line 216 of file IHistogram.cpp.

217 {
218  const std::unique_ptr<OutputData<double>> data(createOutputData(dataType));
219  return data->getArray();
220 }
OutputData< double > * createOutputData(DataType dataType=DataType::INTEGRAL) const
creates new OutputData with histogram's shape and values corresponding to DataType
Definition: IHistogram.cpp:334

References IHistogram::createOutputData().

Referenced by IHistogram::getArray().

Here is the call graph for this function:

◆ getArray()

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

Definition at line 222 of file IHistogram.cpp.

223 {
224  return array(dataType);
225 }
PyObject * array(DataType dataType=DataType::INTEGRAL) const
Returns numpy array with bin content (accumulated values).
Definition: IHistogram.cpp:216

References IHistogram::array().

Here is the call graph for this function:

◆ reset()

void IHistogram::reset ( )
inherited

Reset histogram content (axes remains)

Definition at line 228 of file IHistogram.cpp.

229 {
231 }
The cumulative value with average and rms on-the-flight calculations.
void setAllTo(const T &value)
Sets content of output data to specific value.
Definition: OutputData.h:479

References IHistogram::m_data, and OutputData< T >::setAllTo().

Referenced by IHistogram::copyContentFrom(), IHistogram::relativeDifferenceHistogram(), and Histogram2D::setContent().

Here is the call graph for this function:

◆ createHistogram()

IHistogram * IHistogram::createHistogram ( const OutputData< double > &  source)
staticinherited

Definition at line 233 of file IHistogram.cpp.

234 {
235  if (source.getRank() == 1) {
236  return new Histogram1D(source);
237  } else if (source.getRank() == 2) {
238  return new Histogram2D(source);
239  } else {
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.";
244  throw Exceptions::LogicErrorException(message.str());
245  }
246 }
Two dimensional histogram.
Definition: Histogram2D.h:25
size_t getRank() const
Returns number of dimensions.
Definition: OutputData.h:59

References OutputData< T >::getRank().

Referenced by DetectorMask::createHistogram(), and IntensityDataIOFactory::readIntensityData().

Here is the call graph for this function:

◆ createFrom() [1/2]

IHistogram * IHistogram::createFrom ( const std::string &  filename)
staticinherited

create new histogram from file content

Definition at line 248 of file IHistogram.cpp.

249 {
251 }
static IHistogram * readIntensityData(const std::string &file_name)
Reads file and returns newly created Histogram object.
std::string filename(const std::string &path)
Returns path without directory part ("Foo/Bar/Doz.int.gz" -> "Doz.int.gz")

References FileSystemUtils::filename(), and IntensityDataIOFactory::readIntensityData().

Here is the call graph for this function:

◆ createFrom() [2/2]

IHistogram * IHistogram::createFrom ( const std::vector< std::vector< double >> &  data)
staticinherited

create new histogram from numpy array

Definition at line 253 of file IHistogram.cpp.

254 {
255  return new Histogram2D(data);
256 }

◆ createOutputData()

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

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.

335 {
337  result->copyShapeFrom(m_data);
338  for (size_t i = 0; i < getTotalNumberOfBins(); ++i) {
339  (*result)[i] = getBinData(i, dataType);
340  }
341  return result;
342 }
double getBinData(size_t i, DataType dataType) const
returns data of requested type for globalbin number
Definition: IHistogram.cpp:295
void copyShapeFrom(const OutputData< U > &other)
Definition: OutputData.h:271

References OutputData< T >::copyShapeFrom(), IHistogram::getBinData(), IHistogram::getTotalNumberOfBins(), and IHistogram::m_data.

Referenced by IHistogram::array(), SpectrumUtils::FindPeaks(), and IntensityDataIOFactory::writeIntensityData().

Here is the call graph for this function:

◆ hasSameShape()

bool IHistogram::hasSameShape ( const IHistogram other) const
inherited

Returns true if objects a) have same dimensions b) bin boundaries of axes coincide.

Definition at line 344 of file IHistogram.cpp.

345 {
346  return m_data.hasSameShape(other.m_data);
347 }
bool hasSameShape(const OutputData< U > &right) const
Returns true if objects a) have same dimensions b) bin boundaries of axes coincide.
Definition: OutputData.h:595

References OutputData< T >::hasSameShape(), and IHistogram::m_data.

Here is the call graph for this function:

◆ hasSameDimensions()

bool IHistogram::hasSameDimensions ( const IHistogram other) const
inherited

Returns true if object have same rank and number of axes bins.

Definition at line 349 of file IHistogram.cpp.

350 {
351  return m_data.hasSameDimensions(other.m_data);
352 }
bool hasSameDimensions(const OutputData< U > &right) const
Returns true if object have same dimensions and number of axes bins.
Definition: OutputData.h:578

References OutputData< T >::hasSameDimensions(), and IHistogram::m_data.

Referenced by IHistogram::copyContentFrom(), IHistogram::operator+=(), and IHistogram::relativeDifferenceHistogram().

Here is the call graph for this function:

◆ operator+=()

const IHistogram & IHistogram::operator+= ( const IHistogram right)
inherited

addition-assignment operator for two histograms

Definition at line 354 of file IHistogram.cpp.

355 {
356  if (!hasSameDimensions(right))
358  "IHistogram::operator+=() -> Error. Histograms have different dimension");
359  for (size_t i = 0; i < getTotalNumberOfBins(); ++i)
360  addBinContent(i, right.getBinContent(i));
361  return *this;
362 }
void addBinContent(size_t i, double value)
Add the value to the bin.
Definition: IHistogram.cpp:141
bool hasSameDimensions(const IHistogram &other) const
Returns true if object have same rank and number of axes bins.
Definition: IHistogram.cpp:349

References IHistogram::addBinContent(), IHistogram::getBinContent(), IHistogram::getTotalNumberOfBins(), and IHistogram::hasSameDimensions().

Here is the call graph for this function:

◆ relativeDifferenceHistogram()

IHistogram * IHistogram::relativeDifferenceHistogram ( const IHistogram rhs)
inherited

returns histogram representing relative difference of two histograms.

Definition at line 364 of file IHistogram.cpp.

365 {
366  if (!hasSameDimensions(rhs))
367  throw Exceptions::LogicErrorException("IHistogram::relativeDifferenceHistogram() -> Error. "
368  "Histograms have different dimensions");
369 
370  IHistogram* result = this->clone();
371  result->reset();
372 
373  for (size_t i = 0; i < getTotalNumberOfBins(); ++i) {
375  result->setBinContent(i, diff);
376  }
377  return result;
378 }
Base class for 1D and 2D histograms holding values of double type.
Definition: IHistogram.h:27
void setBinContent(size_t i, double value)
Sets content of the bin corresponding to the globalbin number.
Definition: IHistogram.cpp:136
virtual IHistogram * clone() const =0
void reset()
Reset histogram content (axes remains)
Definition: IHistogram.cpp:228
double GetRelativeDifference(double a, double b)
Returns the safe relative difference, which is 2(|a-b|)/(|a|+|b|) except in special cases.
Definition: Numeric.cpp:32

References IHistogram::clone(), IHistogram::getBinContent(), Numeric::GetRelativeDifference(), IHistogram::getTotalNumberOfBins(), IHistogram::hasSameDimensions(), IHistogram::reset(), and IHistogram::setBinContent().

Here is the call graph for this function:

◆ save()

void IHistogram::save ( const std::string &  filename)
inherited

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.

381 {
383 }
static void writeIntensityData(const IHistogram &histogram, const std::string &file_name)
Writes histogram in file.

References FileSystemUtils::filename(), and IntensityDataIOFactory::writeIntensityData().

Here is the call graph for this function:

◆ load()

void IHistogram::load ( const std::string &  filename)
inherited

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.

386 {
387  const std::unique_ptr<IHistogram> hist(IntensityDataIOFactory::readIntensityData(filename));
388  copyContentFrom(*hist);
389 }
void copyContentFrom(const IHistogram &other)
Copy content (but not the axes) from other histogram. Dimensions should be the same.
Definition: IHistogram.cpp:322

References IHistogram::copyContentFrom(), FileSystemUtils::filename(), and IntensityDataIOFactory::readIntensityData().

Here is the call graph for this function:

◆ check_x_axis()

void IHistogram::check_x_axis ( ) const
protectedinherited

Definition at line 258 of file IHistogram.cpp.

259 {
260  if (getRank() < 1) {
261  std::ostringstream message;
262  message << "IHistogram::check_x_axis() -> Error. X-xis does not exist. ";
263  message << "Rank of histogram " << getRank() << "." << std::endl;
264  throw Exceptions::LogicErrorException(message.str());
265  }
266 }

References IHistogram::getRank().

Referenced by IHistogram::getXaxis(), and IHistogram::getXaxisValue().

Here is the call graph for this function:

◆ check_y_axis()

void IHistogram::check_y_axis ( ) const
protectedinherited

Definition at line 268 of file IHistogram.cpp.

269 {
270  if (getRank() < 2) {
271  std::ostringstream message;
272  message << "IHistogram::check_y_axis() -> Error. Y-axis does not exist. ";
273  message << "Rank of histogram " << getRank() << "." << std::endl;
274  throw Exceptions::LogicErrorException(message.str());
275  }
276 }

References IHistogram::getRank().

Referenced by IHistogram::getYaxis(), and IHistogram::getYaxisValue().

Here is the call graph for this function:

◆ init_from_data()

void IHistogram::init_from_data ( const OutputData< double > &  source)
protectedinherited

Definition at line 278 of file IHistogram.cpp.

279 {
280  if (getRank() != source.getRank()) {
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;
285  throw Exceptions::LogicErrorException(message.str());
286  }
287 
288  m_data.copyShapeFrom(source);
289  for (size_t i = 0; i < source.getAllocatedSize(); ++i) {
290  m_data[i].add(source[i]);
291  }
292 }

References OutputData< T >::copyShapeFrom(), OutputData< T >::getAllocatedSize(), OutputData< T >::getRank(), IHistogram::getRank(), and IHistogram::m_data.

Referenced by Histogram1D(), and Histogram2D::Histogram2D().

Here is the call graph for this function:

◆ getBinData()

double IHistogram::getBinData ( size_t  i,
IHistogram::DataType  dataType 
) const
protectedinherited

returns data of requested type for globalbin number

Definition at line 295 of file IHistogram.cpp.

296 {
297  if (dataType == DataType::INTEGRAL) {
298  return getBinContent(i);
299  } else if (dataType == DataType::AVERAGE) {
300  return getBinAverage(i);
301  } else if (dataType == DataType::STANDARD_ERROR) {
302  return getBinError(i);
303  } else if (dataType == DataType::NENTRIES) {
304  return getBinNumberOfEntries(i);
305  } else
307  "IHistogram::getBinData() -> Error. Unknown data type.");
308 }

References IHistogram::getBinAverage(), IHistogram::getBinContent(), IHistogram::getBinError(), and IHistogram::getBinNumberOfEntries().

Referenced by IHistogram::createOutputData(), and IHistogram::getDataVector().

Here is the call graph for this function:

◆ getDataVector()

std::vector< double > IHistogram::getDataVector ( IHistogram::DataType  dataType) const
protectedinherited

returns vector of values of requested DataType

Definition at line 311 of file IHistogram.cpp.

312 {
313  std::vector<double> result;
314  result.resize(getTotalNumberOfBins(), 0.0);
315  for (size_t index = 0; index < getTotalNumberOfBins(); ++index) {
316  result[index] = getBinData(index, dataType);
317  }
318  return result;
319 }

References IHistogram::getBinData(), and IHistogram::getTotalNumberOfBins().

Referenced by getBinErrors(), and getBinValues().

Here is the call graph for this function:

◆ copyContentFrom()

void IHistogram::copyContentFrom ( const IHistogram other)
protectedinherited

Copy content (but not the axes) from other histogram. Dimensions should be the same.

Definition at line 322 of file IHistogram.cpp.

323 {
324  if (!hasSameDimensions(other))
326  "IHistogram::copyContentFrom() -> Error. Can't copy the data of different shape.");
327  reset();
328  for (size_t i = 0; i < getTotalNumberOfBins(); ++i) {
329  m_data[i] = other.m_data[i];
330  }
331 }

References IHistogram::getTotalNumberOfBins(), IHistogram::hasSameDimensions(), IHistogram::m_data, and IHistogram::reset().

Referenced by IHistogram::load().

Here is the call graph for this function:

Member Data Documentation

◆ m_data


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