CMS 3D CMS Logo

GridAxis.h
Go to the documentation of this file.
1 #ifndef NPSTAT_GRIDAXIS_HH_
2 #define NPSTAT_GRIDAXIS_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 {
30  class GridAxis {
31  public:
33 
37  explicit GridAxis(const std::vector<double>& coords, bool useLogSpace = false);
38  GridAxis(const std::vector<double>& coords, const char* label, bool useLogSpace = false);
40 
42 
43  inline const std::vector<double>& coords() const { return coords_; }
44  inline const std::string& label() const { return label_; }
45  inline bool usesLogSpace() const { return useLogSpace_; }
47 
61  std::pair<unsigned, double> getInterval(double coordinate) const;
62 
77  std::pair<unsigned, double> linearInterval(double coordinate) const;
78 
80 
81  inline unsigned nCoords() const { return npt_; }
82  inline double coordinate(const unsigned i) const { return coords_.at(i); }
83  inline double min() const { return coords_.front(); }
84  inline double max() const { return coords_.back(); }
85  inline double length() const { return coords_.back() - coords_.front(); }
86  inline bool isUniform() const { return false; }
87  inline unsigned nIntervals() const { return coords_.size() - 1; }
88  inline double intervalWidth(const unsigned i = 0) const { return coords_.at(i + 1) - coords_.at(i); }
90 
92  bool operator==(const GridAxis& r) const;
93 
95  inline bool operator!=(const GridAxis& r) const { return !(*this == r); }
96 
101  bool isClose(const GridAxis& r, double tol) const;
102 
104  inline void setLabel(const char* newlabel) { label_ = newlabel ? newlabel : ""; }
105 
107 
108  inline gs::ClassId classId() const { return gs::ClassId(*this); }
109  bool write(std::ostream& of) const;
111 
112  static inline const char* classname() { return "npstat::GridAxis"; }
113  static inline unsigned version() { return 2; }
114  static GridAxis* read(const gs::ClassId& id, std::istream& in);
115 
116  private:
117  void initialize();
118 
119  std::vector<double> coords_;
120  std::vector<double> logs_;
122  unsigned npt_;
124 
125  inline GridAxis() : npt_(0), useLogSpace_(false) {}
126  };
127 } // namespace npstat
128 
129 #endif // NPSTAT_GRIDAXIS_HH_
std::pair< unsigned, double > linearInterval(double coordinate) const
Definition: GridAxis.cc:71
void initialize()
Definition: GridAxis.cc:12
std::string label_
Definition: GridAxis.h:121
static const char * classname()
Definition: GridAxis.h:112
double max() const
Definition: GridAxis.h:84
bool isClose(const GridAxis &r, double tol) const
Definition: GridAxis.cc:141
double intervalWidth(const unsigned i=0) const
Definition: GridAxis.h:88
unsigned nCoords() const
Definition: GridAxis.h:81
static unsigned version()
Definition: GridAxis.h:113
unsigned npt_
Definition: GridAxis.h:122
bool usesLogSpace() const
Definition: GridAxis.h:45
const std::string & label() const
Definition: GridAxis.h:44
bool operator!=(const GridAxis &r) const
Definition: GridAxis.h:95
double length() const
Definition: GridAxis.h:85
gs::ClassId classId() const
Definition: GridAxis.h:108
double coordinate(const unsigned i) const
Definition: GridAxis.h:82
std::pair< unsigned, double > getInterval(double coordinate) const
Definition: GridAxis.cc:48
bool write(std::ostream &of) const
Definition: GridAxis.cc:108
std::vector< double > logs_
Definition: GridAxis.h:120
void setLabel(const char *newlabel)
Definition: GridAxis.h:104
unsigned nIntervals() const
Definition: GridAxis.h:87
static GridAxis * read(const gs::ClassId &id, std::istream &in)
Definition: GridAxis.cc:117
bool isUniform() const
Definition: GridAxis.h:86
const std::vector< double > & coords() const
Definition: GridAxis.h:43
bool operator==(const GridAxis &r) const
Definition: GridAxis.cc:137
std::vector< double > coords_
Definition: GridAxis.h:119
double min() const
Definition: GridAxis.h:83