CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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> class HistoND;
22  class DualHistoAxis;
23 
28  {
29  public:
35  NUHistoAxis(const std::vector<double>& binEdges,
36  const char* label = 0);
37 
39 
40  inline double min() const {return min_;}
41  inline double max() const {return max_;}
42  inline Interval<double> interval() const
43  {return Interval<double>(min_, max_);}
44  inline double length() const {return max_ - min_;}
45  inline unsigned nBins() const {return nBins_;}
46  inline double binWidth(const int binNum) const
47  {return binEdges_.at(binNum+1) - binEdges_.at(binNum);}
48  inline const std::string& label() const {return label_;}
49  inline bool isUniform() const {return uniform_;}
51 
53  inline double leftBinEdge(const int binNum) const
54  {return binEdges_.at(binNum);}
55 
57  inline double rightBinEdge(const int binNum) const
58  {return binEdges_.at(binNum + 1);}
59 
61  inline double binCenter(const int binNum) const
62  {return 0.5*(binEdges_.at(binNum) + binEdges_.at(binNum + 1));}
63 
65  inline Interval<double> binInterval(const int binNum) const
66  {return Interval<double>(binEdges_.at(binNum),
67  binEdges_.at(binNum + 1));}
68 
70  inline void setLabel(const char* newlabel)
71  {label_ = newlabel ? newlabel : "";}
72 
77  int binNumber(double x) const;
78 
83  double fltBinNumber(double x, bool mapLeftEdgeTo0=true) const;
84 
89  unsigned closestValidBin(double x) const;
90 
91  bool operator==(const NUHistoAxis&) const;
92  bool operator!=(const NUHistoAxis&) const;
93 
95  bool isClose(const NUHistoAxis&, double tol) const;
96 
98 
99  inline gs::ClassId classId() const {return gs::ClassId(*this);}
100  bool write(std::ostream& of) const;
102 
103  static inline const char* classname() {return "npstat::NUHistoAxis";}
104  static inline unsigned version() {return 1;}
105  static NUHistoAxis* read(const gs::ClassId& id, std::istream& in);
106 
107  private:
108  inline NUHistoAxis() : min_(0.0), max_(0.0),
109  nBins_(0), uniform_(false) {}
110 
111  NUHistoAxis(unsigned nBins, double min, double max,
112  const char* label = 0);
113 
114  double min_;
115  double max_;
116  std::vector<double> binEdges_;
118  unsigned nBins_;
119  bool uniform_;
120 
121  template <typename Numeric, class Axis> friend class HistoND;
122  friend class DualHistoAxis;
123 
124  inline unsigned overflowIndex(
125  const double x, unsigned* binNum) const
126  {
127  if (x < min_)
128  return 0U;
129  else if (x >= max_)
130  return 2U;
131  else
132  {
133  *binNum = binNumber(x);
134  return 1U;
135  }
136  }
137 
138  };
139 }
140 
141 #endif // NPSTAT_NUHISTOAXIS_HH_
142 
unsigned closestValidBin(double x) const
Definition: NUHistoAxis.cc:137
std::vector< double > binEdges_
Definition: NUHistoAxis.h:116
double rightBinEdge(const int binNum) const
Definition: NUHistoAxis.h:57
int binNumber(double x) const
Definition: NUHistoAxis.cc:73
double min() const
Definition: NUHistoAxis.h:40
unsigned overflowIndex(const double x, unsigned *binNum) const
Definition: NUHistoAxis.h:124
void setLabel(const char *newlabel)
Definition: NUHistoAxis.h:70
bool write(std::ostream &of) const
Definition: NUHistoAxis.cc:149
bool isUniform() const
Definition: NUHistoAxis.h:49
bool operator!=(const NUHistoAxis &) const
Definition: NUHistoAxis.cc:68
unsigned nBins() const
Definition: NUHistoAxis.h:45
std::string label_
Definition: NUHistoAxis.h:117
double leftBinEdge(const int binNum) const
Definition: NUHistoAxis.h:53
double binCenter(const int binNum) const
Definition: NUHistoAxis.h:61
gs::ClassId classId() const
Definition: NUHistoAxis.h:99
static unsigned version()
Definition: NUHistoAxis.h:104
Interval< double > interval() const
Definition: NUHistoAxis.h:42
static NUHistoAxis * read(const gs::ClassId &id, std::istream &in)
Definition: NUHistoAxis.cc:158
bool isClose(const NUHistoAxis &, double tol) const
Definition: NUHistoAxis.cc:44
double fltBinNumber(double x, bool mapLeftEdgeTo0=true) const
Definition: NUHistoAxis.cc:80
Interval< double > binInterval(const int binNum) const
Definition: NUHistoAxis.h:65
static const char * classname()
Definition: NUHistoAxis.h:103
bool operator==(const NUHistoAxis &) const
Definition: NUHistoAxis.cc:58
Definition: DDAxes.h:10
double binWidth(const int binNum) const
Definition: NUHistoAxis.h:46
double max() const
Definition: NUHistoAxis.h:41
double length() const
Definition: NUHistoAxis.h:44
const std::string & label() const
Definition: NUHistoAxis.h:48