BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
FixedBinAxis.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
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_CORE_AXIS_FIXEDBINAXIS_H
16 #define BORNAGAIN_CORE_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 {
25 public:
26  //! FixedBinAxis constructor.
27  //! @param name Axis name
28  //! @param nbins number of bins
29  //! @param start low edge of first bin
30  //! @param end upper edge of last bin
31  FixedBinAxis(const std::string& name, size_t nbins, double start, double end);
32  virtual ~FixedBinAxis() {}
33 
34  FixedBinAxis* clone() const;
35 
36  size_t size() const { return m_nbins; }
37 
38  double operator[](size_t index) const;
39 
40  Bin1D getBin(size_t index) const;
41 
42  double getMin() const { return m_start; }
43  double getMax() const { return m_end; }
44 
45  double getBinCenter(size_t index) const { return (*this)[index]; }
46 
47  size_t findClosestIndex(double value) const;
48 
49  std::vector<double> getBinCenters() const;
50 
51  std::vector<double> getBinBoundaries() const;
52 
53  FixedBinAxis* createClippedAxis(double left, double right) const;
54 
55  std::string pyString(const std::string& units, size_t) const final;
56 
57 protected:
58  void print(std::ostream& ostr) const;
59  virtual bool equals(const IAxis& other) const;
60 
61 private:
62  size_t m_nbins;
63  double m_start;
64  double m_end;
65 };
66 
67 #endif // BORNAGAIN_CORE_AXIS_FIXEDBINAXIS_H
Defines class IAxis.
Axis with fixed bin size.
Definition: FixedBinAxis.h:24
double m_start
Definition: FixedBinAxis.h:63
FixedBinAxis * createClippedAxis(double left, double right) const
Creates a new clipped axis.
virtual bool equals(const IAxis &other) const
double operator[](size_t index) const
indexed accessor retrieves a sample
size_t findClosestIndex(double value) const
find bin index which is best match for given value
double getMax() const
Returns value of last point of axis.
Definition: FixedBinAxis.h:43
void print(std::ostream &ostr) const
FixedBinAxis * clone() const
clone function
std::vector< double > getBinBoundaries() const
double getBinCenter(size_t index) const
Definition: FixedBinAxis.h:45
double getMin() const
Returns value of first point of axis.
Definition: FixedBinAxis.h:42
std::vector< double > getBinCenters() const
double m_end
Definition: FixedBinAxis.h:64
size_t m_nbins
Definition: FixedBinAxis.h:62
std::string pyString(const std::string &units, size_t) const final
FixedBinAxis(const std::string &name, size_t nbins, double start, double end)
FixedBinAxis constructor.
size_t size() const
retrieve the number of bins
Definition: FixedBinAxis.h:36
virtual ~FixedBinAxis()
Definition: FixedBinAxis.h:32
Bin1D getBin(size_t index) const
retrieve a 1d bin for the given index
Interface for one-dimensional axes.
Definition: IAxis.h:25
Definition: Bin.h:20