BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
VariableBinAxis.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Axis/VariableBinAxis.h
6 //! @brief Defines class VariableBinAxis.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_BASE_AXIS_VARIABLEBINAXIS_H
16 #define BORNAGAIN_BASE_AXIS_VARIABLEBINAXIS_H
17 
18 #include "Base/Axis/IAxis.h"
19 
20 //! Axis with variable bin size.
21 //! @ingroup tools
22 
23 class VariableBinAxis : public IAxis {
24 public:
25  //! VariableBinAxis constructor.
26  //! @param name Axis name
27  //! @param bin_boundaries Array of size nbins+1 containing low-edges for each
28  //! bin and upper edge of last bin.
29  VariableBinAxis(const std::string& name, const std::vector<double>& bin_boundaries);
30  ~VariableBinAxis() override = default;
31 
32  VariableBinAxis* clone() const override;
33 
34  size_t size() const override { return m_nbins; }
35 
36  double operator[](size_t index) const override;
37 
38  Bin1D bin(size_t index) const override;
39 
40  double min() const override;
41  double max() const override;
42 
43  double binCenter(size_t index) const override;
44 
45  size_t findClosestIndex(double value) const override;
46 
47  std::vector<double> binCenters() const override;
48  std::vector<double> binBoundaries() const override { return m_bin_boundaries; }
49 
50  void clip(double lower, double upper) override;
51 
52 protected:
53  explicit VariableBinAxis(const std::string& name, size_t nbins = 0);
54  void setBinBoundaries(const std::vector<double>& bin_boundaries);
55 
56  void print(std::ostream& ostr) const override;
57  bool equals(const IAxis& other) const override;
58  size_t m_nbins;
59 
60 private:
61  std::vector<double> m_bin_boundaries; //!< vector containing the bin limits
62 };
63 
64 #endif // BORNAGAIN_BASE_AXIS_VARIABLEBINAXIS_H
Defines interface IAxis.
Definition: Bin.h:20
Abstract base class for one-dimensional axes.
Definition: IAxis.h:27
Axis with variable bin size.
double max() const override
Returns value of last point of axis.
bool equals(const IAxis &other) const override
~VariableBinAxis() override=default
void clip(double lower, double upper) override
Clips this axis to the given values.
std::vector< double > binCenters() const override
void setBinBoundaries(const std::vector< double > &bin_boundaries)
double binCenter(size_t index) const override
double operator[](size_t index) const override
indexed accessor retrieves a sample
Bin1D bin(size_t index) const override
retrieve a 1d bin for the given index
size_t size() const override
Returns the number of bins.
std::vector< double > binBoundaries() const override
std::vector< double > m_bin_boundaries
vector containing the bin limits
VariableBinAxis * clone() const override
size_t findClosestIndex(double value) const override
find bin index which is best match for given value
double min() const override
Returns value of first point of axis.
VariableBinAxis(const std::string &name, const std::vector< double > &bin_boundaries)
VariableBinAxis constructor.
void print(std::ostream &ostr) const override