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 {
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=nullptr);
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_;
90  unsigned npt_;
91 
92  inline UniformAxis() : min_(0.), max_(0.), bw_(0.), npt_(0) {}
93  };
94 }
95 
96 #endif // NPSTAT_UNIFORMAXIS_HH_
97 
bool isClose(const UniformAxis &r, double tol) const
Definition: UniformAxis.cc:92
bool operator==(const UniformAxis &r) const
Definition: UniformAxis.cc:100
static unsigned version()
Definition: UniformAxis.h:82
unsigned nCoords() const
Definition: UniformAxis.h:35
double max() const
Definition: UniformAxis.h:37
bool isUniform() const
Definition: UniformAxis.h:62
void setLabel(const char *newlabel)
Definition: UniformAxis.h:74
unsigned nIntervals() const
Definition: UniformAxis.h:63
double coordinate(unsigned i) const
Definition: UniformAxis.cc:81
double length() const
Definition: UniformAxis.h:61
bool operator!=(const UniformAxis &r) const
Definition: UniformAxis.h:67
const std::string & label() const
Definition: UniformAxis.h:38
bool write(std::ostream &of) const
Definition: UniformAxis.cc:108
std::string label_
Definition: UniformAxis.h:89
bool usesLogSpace() const
Definition: UniformAxis.h:39
static const char * classname()
Definition: UniformAxis.h:81
std::vector< double > coords() const
Definition: UniformAxis.cc:70
static UniformAxis * read(const gs::ClassId &id, std::istream &in)
Definition: UniformAxis.cc:117
double min() const
Definition: UniformAxis.h:36
std::pair< unsigned, double > getInterval(double coordinate) const
Definition: UniformAxis.cc:30
double intervalWidth(unsigned) const
Definition: UniformAxis.h:64
std::pair< unsigned, double > linearInterval(double coordinate) const
Definition: UniformAxis.cc:50
gs::ClassId classId() const
Definition: UniformAxis.h:78