CMS 3D CMS Logo

UniformAxis.h
Go to the documentation of this file.
1 #ifndef NPSTAT_UNIFORMAXIS_HH_
2 #define NPSTAT_UNIFORMAXIS_HH_
3 
15 #include <vector>
16 #include <utility>
17 #include <string>
18 #include <iostream>
19 
20 #include "Alignment/Geners/interface/ClassId.hh"
21 
22 namespace npstat {
27  class UniformAxis {
28  public:
29  // The number of coordinates must be at least 2
30  UniformAxis(unsigned nCoords, double min, double max, const char* label = nullptr);
31 
32  // Basic accessors
33  inline unsigned nCoords() const { return npt_; }
34  inline double min() const { return min_; }
35  inline double max() const { return max_; }
36  inline const std::string& label() const { return label_; }
37  inline bool usesLogSpace() const { return false; }
38 
39  // The following function returns the grid interval number and
40  // the weight of the point at the left side of the interval.
41  // The weight will be set to 1 if the given coordinate coincides
42  // with the grid point and will decay to 0 linearly as the
43  // coordinate moves towards the next point on the right.
44  //
45  // The coordinates below the leftmost grid point are mapped
46  // into the 0th interval with weight 1. The coordinates above
47  // the rightmost grid point are mapped into the last interval
48  // with weight 0 for the left point (it is expected that weight 1
49  // will then be assigned to the right point).
50  std::pair<unsigned, double> getInterval(double coordinate) const;
51 
52  // Similar function which calculates the weights including
53  // the points outside of the axis boundaries
54  std::pair<unsigned, double> linearInterval(double coordinate) const;
55 
56  // Convenience methods
57  std::vector<double> coords() const;
58  double coordinate(unsigned i) const;
59  inline double length() const { return max_ - min_; }
60  inline bool isUniform() const { return true; }
61  inline unsigned nIntervals() const { return npt_ - 1; }
62  inline double intervalWidth(unsigned) const { return bw_; }
63 
64  bool operator==(const UniformAxis& r) const;
65  inline bool operator!=(const UniformAxis& r) const { return !(*this == r); }
66 
67  // Closeness within tolerance
68  bool isClose(const UniformAxis& r, double tol) const;
69 
70  // Modify the label
71  inline void setLabel(const char* newlabel) { label_ = newlabel ? newlabel : ""; }
72 
73  // Methods related to I/O
74  inline gs::ClassId classId() const { return gs::ClassId(*this); }
75  bool write(std::ostream& of) const;
76 
77  static inline const char* classname() { return "npstat::UniformAxis"; }
78  static inline unsigned version() { return 1; }
79  static UniformAxis* read(const gs::ClassId& id, std::istream& in);
80 
81  private:
82  double min_;
83  double max_;
84  double bw_;
86  unsigned npt_;
87 
88  inline UniformAxis() : min_(0.), max_(0.), bw_(0.), npt_(0) {}
89  };
90 } // namespace npstat
91 
92 #endif // NPSTAT_UNIFORMAXIS_HH_
bool usesLogSpace() const
Definition: UniformAxis.h:37
bool isUniform() const
Definition: UniformAxis.h:60
gs::ClassId classId() const
Definition: UniformAxis.h:74
double coordinate(unsigned i) const
Definition: UniformAxis.cc:74
static unsigned version()
Definition: UniformAxis.h:78
void setLabel(const char *newlabel)
Definition: UniformAxis.h:71
bool operator!=(const UniformAxis &r) const
Definition: UniformAxis.h:65
double min() const
Definition: UniformAxis.h:34
unsigned nCoords() const
Definition: UniformAxis.h:33
bool write(std::ostream &of) const
Definition: UniformAxis.cc:92
std::pair< unsigned, double > getInterval(double coordinate) const
Definition: UniformAxis.cc:28
double length() const
Definition: UniformAxis.h:59
double intervalWidth(unsigned) const
Definition: UniformAxis.h:62
std::pair< unsigned, double > linearInterval(double coordinate) const
Definition: UniformAxis.cc:46
bool isClose(const UniformAxis &r, double tol) const
Definition: UniformAxis.cc:83
std::string label_
Definition: UniformAxis.h:85
bool operator==(const UniformAxis &r) const
Definition: UniformAxis.cc:88
static const char * classname()
Definition: UniformAxis.h:77
static UniformAxis * read(const gs::ClassId &id, std::istream &in)
Definition: UniformAxis.cc:100
double max() const
Definition: UniformAxis.h:35
std::vector< double > coords() const
Definition: UniformAxis.cc:64
unsigned nIntervals() const
Definition: UniformAxis.h:61
const std::string & label() const
Definition: UniformAxis.h:36