BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
PointwiseAxis.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Base/Axis/PointwiseAxis.h
6 //! @brief Defines class PointwiseAxis.
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_CORE_AXIS_POINTWISEAXIS_H
16 #define BORNAGAIN_CORE_AXIS_POINTWISEAXIS_H
17 
18 #include "Base/Axis/IAxis.h"
19 
20 //! Axis containing arbitrary (non-equidistant) coordinate values.
21 //! Lower boundary of the first bin and upper boundary of the
22 //! last bin correspond to first and last passed coordinates.
23 //! Other bin boundaries are computed as arithmetical mean of
24 //! two adjacent coordinates.
25 //! One should be aware, that bin centers reported
26 //! by PointwiseAxis::getBinCenter do not coincide with the
27 //! values produced by Bin1D::getMidPoint.
28 //! On-axis values are bounded by minimum/maximum
29 //! values passed to the constructor.
30 //! @ingroup tools
31 
32 class PointwiseAxis : public IAxis
33 {
34 public:
35  template <class String, class Vector>
36  PointwiseAxis(String&& name, Vector&& coordinate_values)
37  : IAxis(std::forward<String>(name)), m_coordinates(std::forward<Vector>(coordinate_values))
38  {
39  sanityCheck();
40  }
41 
42  //! clone function
43  PointwiseAxis* clone() const override;
44 
45  ~PointwiseAxis() override = default;
46 
47  //! retrieve the number of bins
48  size_t size() const override { return m_coordinates.size(); }
49 
50  //! indexed accessor retrieves a sample
51  double operator[](size_t index) const override { return getBinCenter(index); }
52 
53  //! retrieve a 1d bin for the given index
54  Bin1D getBin(size_t index) const override;
55 
56  //! Returns value of first on-axis point
57  double getMin() const override;
58 
59  //! Returns value of last on-axis point
60  double getMax() const override;
61 
62  //! Returns the coordinate corresponding to the
63  //! given index.
64  double getBinCenter(size_t index) const override;
65 
66  //! find index of the coordinate closest to the given value
67  size_t findClosestIndex(double value) const override;
68 
69  std::vector<double> getBinCenters() const override { return m_coordinates; }
70 
71  std::vector<double> getBinBoundaries() const override;
72 
73  //! Creates a new clipped axis
74  PointwiseAxis* createClippedAxis(double left, double right) const override;
75 
76  std::string pyString(const std::string& units, size_t offset) const final;
77 
78 private:
79  void print(std::ostream& ostr) const override;
80  bool equals(const IAxis& other) const override;
81 
82  double lowerBoundary(size_t index) const;
83  double upperBoundary(size_t index) const;
84  void checkIndex(size_t index) const;
85  void sanityCheck() const;
86 
87  std::vector<double> m_coordinates;
88 };
89 
90 #endif // BORNAGAIN_CORE_AXIS_POINTWISEAXIS_H
Defines class IAxis.
Interface for one-dimensional axes.
Definition: IAxis.h:25
Axis containing arbitrary (non-equidistant) coordinate values.
Definition: PointwiseAxis.h:33
double upperBoundary(size_t index) const
double lowerBoundary(size_t index) const
PointwiseAxis(String &&name, Vector &&coordinate_values)
Definition: PointwiseAxis.h:36
Bin1D getBin(size_t index) const override
retrieve a 1d bin for the given index
PointwiseAxis * clone() const override
clone function
~PointwiseAxis() override=default
std::vector< double > getBinCenters() const override
Definition: PointwiseAxis.h:69
void checkIndex(size_t index) const
double getBinCenter(size_t index) const override
Returns the coordinate corresponding to the given index.
std::vector< double > m_coordinates
Definition: PointwiseAxis.h:87
PointwiseAxis * createClippedAxis(double left, double right) const override
Creates a new clipped axis.
std::string pyString(const std::string &units, size_t offset) const final
std::vector< double > getBinBoundaries() const override
double getMax() const override
Returns value of last on-axis point.
size_t findClosestIndex(double value) const override
find index of the coordinate closest to the given value
double operator[](size_t index) const override
indexed accessor retrieves a sample
Definition: PointwiseAxis.h:51
size_t size() const override
retrieve the number of bins
Definition: PointwiseAxis.h:48
double getMin() const override
Returns value of first on-axis point.
bool equals(const IAxis &other) const override
void print(std::ostream &ostr) const override
void sanityCheck() const
Definition: Bin.h:20