CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
NUHistoAxis.h
Go to the documentation of this file.
1 #ifndef NPSTAT_NUHISTOAXIS_HH_
2 #define NPSTAT_NUHISTOAXIS_HH_
3 
14 #include <vector>
15 #include <utility>
16 
17 #include "Alignment/Geners/interface/ClassId.hh"
19 
20 namespace npstat {
21  template <typename Numeric, class Axis>
22  class HistoND;
23  class DualHistoAxis;
24 
28  class NUHistoAxis {
29  public:
35  NUHistoAxis(const std::vector<double>& binEdges, const char* label = nullptr);
36 
38 
39  inline double min() const { return min_; }
40  inline double max() const { return max_; }
41  inline Interval<double> interval() const { return Interval<double>(min_, max_); }
42  inline double length() const { return max_ - min_; }
43  inline unsigned nBins() const { return nBins_; }
44  inline double binWidth(const int binNum) const { return binEdges_.at(binNum + 1) - binEdges_.at(binNum); }
45  inline const std::string& label() const { return label_; }
46  inline bool isUniform() const { return uniform_; }
48 
50  inline double leftBinEdge(const int binNum) const { return binEdges_.at(binNum); }
51 
53  inline double rightBinEdge(const int binNum) const { return binEdges_.at(binNum + 1); }
54 
56  inline double binCenter(const int binNum) const { return 0.5 * (binEdges_.at(binNum) + binEdges_.at(binNum + 1)); }
57 
59  inline Interval<double> binInterval(const int binNum) const {
60  return Interval<double>(binEdges_.at(binNum), binEdges_.at(binNum + 1));
61  }
62 
64  inline void setLabel(const char* newlabel) { label_ = newlabel ? newlabel : ""; }
65 
70  int binNumber(double x) const;
71 
76  double fltBinNumber(double x, bool mapLeftEdgeTo0 = true) const;
77 
82  unsigned closestValidBin(double x) const;
83 
84  bool operator==(const NUHistoAxis&) const;
85  bool operator!=(const NUHistoAxis&) const;
86 
88  bool isClose(const NUHistoAxis&, double tol) const;
89 
91  NUHistoAxis rebin(unsigned newBins) const;
92 
94 
95  inline gs::ClassId classId() const { return gs::ClassId(*this); }
96  bool write(std::ostream& of) const;
98 
99  static inline const char* classname() { return "npstat::NUHistoAxis"; }
100  static inline unsigned version() { return 1; }
101  static NUHistoAxis* read(const gs::ClassId& id, std::istream& in);
102 
103  private:
104  NUHistoAxis(unsigned nBins, double min, double max, const char* label = nullptr);
105 
106  double min_;
107  double max_;
108  std::vector<double> binEdges_;
110  unsigned nBins_;
111  bool uniform_;
112 
113  template <typename Numeric, class Axis>
114  friend class HistoND;
115  friend class DualHistoAxis;
116 
117  inline unsigned overflowIndex(const double x, unsigned* binNum) const {
118  if (x < min_)
119  return 0U;
120  else if (x >= max_)
121  return 2U;
122  else {
123  *binNum = binNumber(x);
124  return 1U;
125  }
126  }
127 
128  inline NUHistoAxis() : min_(0.0), max_(0.0), nBins_(0), uniform_(false) {}
129  };
130 } // namespace npstat
131 
132 #endif // NPSTAT_NUHISTOAXIS_HH_
unsigned closestValidBin(double x) const
Definition: NUHistoAxis.cc:124
std::vector< double > binEdges_
Definition: NUHistoAxis.h:108
double rightBinEdge(const int binNum) const
Definition: NUHistoAxis.h:53
int binNumber(double x) const
Definition: NUHistoAxis.cc:62
double min() const
Definition: NUHistoAxis.h:39
unsigned overflowIndex(const double x, unsigned *binNum) const
Definition: NUHistoAxis.h:117
void setLabel(const char *newlabel)
Definition: NUHistoAxis.h:64
bool write(std::ostream &of) const
Definition: NUHistoAxis.cc:134
bool isUniform() const
Definition: NUHistoAxis.h:46
bool operator!=(const NUHistoAxis &) const
Definition: NUHistoAxis.cc:60
unsigned nBins() const
Definition: NUHistoAxis.h:43
std::string label_
Definition: NUHistoAxis.h:109
NUHistoAxis rebin(unsigned newBins) const
Definition: NUHistoAxis.cc:41
double leftBinEdge(const int binNum) const
Definition: NUHistoAxis.h:50
tuple of
Definition: haddnano.py:40
double binCenter(const int binNum) const
Definition: NUHistoAxis.h:56
gs::ClassId classId() const
Definition: NUHistoAxis.h:95
static unsigned version()
Definition: NUHistoAxis.h:100
Interval< double > interval() const
Definition: NUHistoAxis.h:41
static NUHistoAxis * read(const gs::ClassId &id, std::istream &in)
Definition: NUHistoAxis.cc:142
bool isClose(const NUHistoAxis &, double tol) const
Definition: NUHistoAxis.cc:45
double fltBinNumber(double x, bool mapLeftEdgeTo0=true) const
Definition: NUHistoAxis.cc:67
Interval< double > binInterval(const int binNum) const
Definition: NUHistoAxis.h:59
static const char * classname()
Definition: NUHistoAxis.h:99
bool operator==(const NUHistoAxis &) const
Definition: NUHistoAxis.cc:55
double binWidth(const int binNum) const
Definition: NUHistoAxis.h:44
Template to represent intervals in one dimension.
double max() const
Definition: NUHistoAxis.h:40
double length() const
Definition: NUHistoAxis.h:42
const std::string & label() const
Definition: NUHistoAxis.h:45