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_
npstat::UniformAxis::coords
std::vector< double > coords() const
Definition: UniformAxis.cc:64
npstat::UniformAxis::max
double max() const
Definition: UniformAxis.h:35
mps_fire.i
i
Definition: mps_fire.py:428
npstat::UniformAxis
Definition: UniformAxis.h:27
npstat::UniformAxis::length
double length() const
Definition: UniformAxis.h:59
npstat::UniformAxis::classname
static const char * classname()
Definition: UniformAxis.h:77
npstat::UniformAxis::coordinate
double coordinate(unsigned i) const
Definition: UniformAxis.cc:74
npstat::UniformAxis::label
const std::string & label() const
Definition: UniformAxis.h:36
npstat::UniformAxis::getInterval
std::pair< unsigned, double > getInterval(double coordinate) const
Definition: UniformAxis.cc:28
npstat::UniformAxis::max_
double max_
Definition: UniformAxis.h:83
npstat::UniformAxis::operator==
bool operator==(const UniformAxis &r) const
Definition: UniformAxis.cc:88
npstat::UniformAxis::operator!=
bool operator!=(const UniformAxis &r) const
Definition: UniformAxis.h:65
npstat
Definition: AbsArrayProjector.h:14
npstat::UniformAxis::read
static UniformAxis * read(const gs::ClassId &id, std::istream &in)
Definition: UniformAxis.cc:100
npstat::UniformAxis::classId
gs::ClassId classId() const
Definition: UniformAxis.h:74
npstat::UniformAxis::nCoords
unsigned nCoords() const
Definition: UniformAxis.h:33
npstat::UniformAxis::label_
std::string label_
Definition: UniformAxis.h:85
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
npstat::UniformAxis::npt_
unsigned npt_
Definition: UniformAxis.h:86
npstat::UniformAxis::setLabel
void setLabel(const char *newlabel)
Definition: UniformAxis.h:71
recoMuon::in
Definition: RecoMuonEnumerators.h:6
npstat::UniformAxis::write
bool write(std::ostream &of) const
Definition: UniformAxis.cc:92
alignCSCRings.r
r
Definition: alignCSCRings.py:93
npstat::UniformAxis::version
static unsigned version()
Definition: UniformAxis.h:78
npstat::UniformAxis::intervalWidth
double intervalWidth(unsigned) const
Definition: UniformAxis.h:62
npstat::UniformAxis::UniformAxis
UniformAxis()
Definition: UniformAxis.h:88
npstat::UniformAxis::isUniform
bool isUniform() const
Definition: UniformAxis.h:60
npstat::UniformAxis::min_
double min_
Definition: UniformAxis.h:82
npstat::UniformAxis::linearInterval
std::pair< unsigned, double > linearInterval(double coordinate) const
Definition: UniformAxis.cc:46
npstat::UniformAxis::nIntervals
unsigned nIntervals() const
Definition: UniformAxis.h:61
npstat::UniformAxis::min
double min() const
Definition: UniformAxis.h:34
npstat::UniformAxis::usesLogSpace
bool usesLogSpace() const
Definition: UniformAxis.h:37
npstat::UniformAxis::bw_
double bw_
Definition: UniformAxis.h:84
npstat::UniformAxis::isClose
bool isClose(const UniformAxis &r, double tol) const
Definition: UniformAxis.cc:83