BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
FixedBinAxis.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file Base/Axis/FixedBinAxis.h
6 //! @brief Defines class FixedBinAxis.
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_FIXEDBINAXIS_H
16 #define BORNAGAIN_BASE_AXIS_FIXEDBINAXIS_H
17 
18 #include "Base/Axis/IAxis.h"
19 
20 //! Axis with fixed bin size.
21 //! @ingroup tools
22 
23 class FixedBinAxis : public IAxis {
24 public:
25  //! FixedBinAxis constructor.
26  //! @param name Axis name
27  //! @param nbins number of bins
28  //! @param start low edge of first bin
29  //! @param end upper edge of last bin
30  FixedBinAxis(const std::string& name, size_t nbins, double start, double end);
31  ~FixedBinAxis() override = default;
32 
33  FixedBinAxis* clone() const override;
34 
35  size_t size() const override { return m_nbins; }
36 
37  double operator[](size_t index) const override;
38 
39  Bin1D bin(size_t index) const override;
40 
41  double min() const override { return m_start; }
42  double max() const override { return m_end; }
43 
44  double binCenter(size_t index) const override { return (*this)[index]; }
45 
46  size_t findClosestIndex(double value) const override;
47 
48  std::vector<double> binCenters() const override;
49 
50  std::vector<double> binBoundaries() const override;
51 
52  void clip(double lower, double upper) override;
53 
54 protected:
55  void print(std::ostream& ostr) const override;
56  bool equals(const IAxis& other) const override;
57 
58 private:
59  size_t m_nbins;
60  double m_start;
61  double m_end;
62 };
63 
64 #endif // BORNAGAIN_BASE_AXIS_FIXEDBINAXIS_H
Defines interface IAxis.
Definition: Bin.h:20
Axis with fixed bin size.
Definition: FixedBinAxis.h:23
double m_start
Definition: FixedBinAxis.h:60
bool equals(const IAxis &other) const override
void clip(double lower, double upper) override
Clips this axis to the given values.
std::vector< double > binCenters() const override
FixedBinAxis * clone() const override
size_t findClosestIndex(double value) const override
find bin index which is best match for given value
double binCenter(size_t index) const override
Definition: FixedBinAxis.h:44
void print(std::ostream &ostr) const override
double operator[](size_t index) const override
indexed accessor retrieves a sample
size_t size() const override
Returns the number of bins.
Definition: FixedBinAxis.h:35
double m_end
Definition: FixedBinAxis.h:61
~FixedBinAxis() override=default
double max() const override
Returns value of last point of axis.
Definition: FixedBinAxis.h:42
Bin1D bin(size_t index) const override
retrieve a 1d bin for the given index
double min() const override
Returns value of first point of axis.
Definition: FixedBinAxis.h:41
size_t m_nbins
Definition: FixedBinAxis.h:59
std::vector< double > binBoundaries() const override
FixedBinAxis(const std::string &name, size_t nbins, double start, double end)
FixedBinAxis constructor.
Abstract base class for one-dimensional axes.
Definition: IAxis.h:27