npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
UniformAxis.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_UNIFORMAXIS_HH_
2 #define NPSTAT_UNIFORMAXIS_HH_
3 
4 /*!
5 // \file UniformAxis.hh
6 //
7 // \brief Uniformly spaced coordinate sets for use in constructing
8 // rectangular grids
9 //
10 // Author: I. Volobouev
11 //
12 // June 2012
13 */
14 
15 #include <vector>
16 #include <utility>
17 #include <string>
18 #include <iostream>
19 
20 #include "geners/ClassId.hh"
21 
22 namespace npstat {
23  /**
24  // This class contains the info needed to define an axis of a rectangular
25  // grid. The distance between grid points is uniform.
26  */
28  {
29  public:
30  // The number of coordinates must be at least 2
31  UniformAxis(unsigned nCoords, double min, double max,
32  const char* label=0);
33 
34  // Basic accessors
35  inline unsigned nCoords() const {return npt_;}
36  inline double min() const {return min_;}
37  inline double max() const {return max_;}
38  inline const std::string& label() const {return label_;}
39  inline bool usesLogSpace() const {return false;}
40 
41  // The following function returns the grid interval number and
42  // the weight of the point at the left side of the interval.
43  // The weight will be set to 1 if the given coordinate coincides
44  // with the grid point and will decay to 0 linearly as the
45  // coordinate moves towards the next point on the right.
46  //
47  // The coordinates below the leftmost grid point are mapped
48  // into the 0th interval with weight 1. The coordinates above
49  // the rightmost grid point are mapped into the last interval
50  // with weight 0 for the left point (it is expected that weight 1
51  // will then be assigned to the right point).
52  std::pair<unsigned,double> getInterval(double coordinate) const;
53 
54  // Similar function which calculates the weights including
55  // the points outside of the axis boundaries
56  std::pair<unsigned,double> linearInterval(double coordinate) const;
57 
58  // Convenience methods
59  std::vector<double> coords() const;
60  double coordinate(unsigned i) const;
61  inline double length() const {return max_ - min_;}
62  inline bool isUniform() const {return true;}
63  inline unsigned nIntervals() const {return npt_ - 1;}
64  inline double intervalWidth(unsigned) const {return bw_;}
65 
66  bool operator==(const UniformAxis& r) const;
67  inline bool operator!=(const UniformAxis& r) const
68  {return !(*this == r);}
69 
70  // Closeness within tolerance
71  bool isClose(const UniformAxis& r, double tol) const;
72 
73  // Modify the label
74  inline void setLabel(const char* newlabel)
75  {label_ = newlabel ? newlabel : "";}
76 
77  // Methods related to I/O
78  inline gs::ClassId classId() const {return gs::ClassId(*this);}
79  bool write(std::ostream& of) const;
80 
81  static inline const char* classname() {return "npstat::UniformAxis";}
82  static inline unsigned version() {return 1;}
83  static UniformAxis* read(const gs::ClassId& id, std::istream& in);
84 
85  private:
86  double min_;
87  double max_;
88  double bw_;
89  std::string label_;
90  unsigned npt_;
91 
92 #ifdef SWIG
93  public:
94  inline std::pair<double,double> range() const
95  {return std::pair<double,double>(min_, max_);}
96 #endif // SWIG
97 
98  inline UniformAxis() : min_(0.), max_(0.), bw_(0.), npt_(0) {}
99  };
100 }
101 
102 #endif // NPSTAT_UNIFORMAXIS_HH_
Definition: UniformAxis.hh:28
Definition: AbsArrayProjector.hh:14