File indexing completed on 2024-04-06 12:19:20
0001 #ifndef NPSTAT_GRIDAXIS_HH_
0002 #define NPSTAT_GRIDAXIS_HH_
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <vector>
0016 #include <utility>
0017 #include <string>
0018 #include <iostream>
0019
0020 #include "Alignment/Geners/interface/ClassId.hh"
0021
0022 namespace npstat {
0023
0024
0025
0026
0027
0028
0029
0030 class GridAxis {
0031 public:
0032
0033
0034
0035
0036
0037 explicit GridAxis(const std::vector<double>& coords, bool useLogSpace = false);
0038 GridAxis(const std::vector<double>& coords, const char* label, bool useLogSpace = false);
0039
0040
0041
0042
0043 inline const std::vector<double>& coords() const { return coords_; }
0044 inline const std::string& label() const { return label_; }
0045 inline bool usesLogSpace() const { return useLogSpace_; }
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 std::pair<unsigned, double> getInterval(double coordinate) const;
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077 std::pair<unsigned, double> linearInterval(double coordinate) const;
0078
0079
0080
0081 inline unsigned nCoords() const { return npt_; }
0082 inline double coordinate(const unsigned i) const { return coords_.at(i); }
0083 inline double min() const { return coords_.front(); }
0084 inline double max() const { return coords_.back(); }
0085 inline double length() const { return coords_.back() - coords_.front(); }
0086 inline bool isUniform() const { return false; }
0087 inline unsigned nIntervals() const { return coords_.size() - 1; }
0088 inline double intervalWidth(const unsigned i = 0) const { return coords_.at(i + 1) - coords_.at(i); }
0089
0090
0091
0092 bool operator==(const GridAxis& r) const;
0093
0094
0095 inline bool operator!=(const GridAxis& r) const { return !(*this == r); }
0096
0097
0098
0099
0100
0101 bool isClose(const GridAxis& r, double tol) const;
0102
0103
0104 inline void setLabel(const char* newlabel) { label_ = newlabel ? newlabel : ""; }
0105
0106
0107
0108 inline gs::ClassId classId() const { return gs::ClassId(*this); }
0109 bool write(std::ostream& of) const;
0110
0111
0112 static inline const char* classname() { return "npstat::GridAxis"; }
0113 static inline unsigned version() { return 2; }
0114 static GridAxis* read(const gs::ClassId& id, std::istream& in);
0115
0116 private:
0117 void initialize();
0118
0119 std::vector<double> coords_;
0120 std::vector<double> logs_;
0121 std::string label_;
0122 unsigned npt_;
0123 bool useLogSpace_;
0124
0125 inline GridAxis() : npt_(0), useLogSpace_(false) {}
0126 };
0127 }
0128
0129 #endif