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, const char* label = 0);
36 
38 
39  inline double min() const {return min_;}
40  inline double max() const {return max_;}
41  inline Interval<double> interval() const
42  {return Interval<double>(min_, max_);}
43  inline double length() const {return max_ - min_;}
44  inline unsigned nBins() const {return nBins_;}
45  inline double binWidth(const int binNum) const
46  {return binEdges_.at(binNum+1) - binEdges_.at(binNum);}
47  inline const std::string& label() const {return label_;}
48  inline bool isUniform() const {return uniform_;}
50 
52  inline double leftBinEdge(const int binNum) const
53  {return binEdges_.at(binNum);}
54 
56  inline double rightBinEdge(const int binNum) const
57  {return binEdges_.at(binNum + 1);}
58 
60  inline double binCenter(const int binNum) const
61  {return 0.5*(binEdges_.at(binNum) + binEdges_.at(binNum + 1));}
62 
64  inline Interval<double> binInterval(const int binNum) const
65  {return Interval<double>(binEdges_.at(binNum),
66  binEdges_.at(binNum + 1));}
67 
69  inline void setLabel(const char* newlabel)
70  {label_ = newlabel ? newlabel : "";}
71 
76  int binNumber(double x) const;
77 
82  double fltBinNumber(double x, bool mapLeftEdgeTo0=true) const;
83 
88  unsigned closestValidBin(double x) const;
89 
90  bool operator==(const NUHistoAxis&) const;
91  bool operator!=(const NUHistoAxis&) const;
92 
94  bool isClose(const NUHistoAxis&, double tol) const;
95 
97  NUHistoAxis rebin(unsigned newBins) const;
98 
100 
101  inline gs::ClassId classId() const {return gs::ClassId(*this);}
102  bool write(std::ostream& of) const;
104 
105  static inline const char* classname() {return "npstat::NUHistoAxis";}
106  static inline unsigned version() {return 1;}
107  static NUHistoAxis* read(const gs::ClassId& id, std::istream& in);
108 
109  private:
110  NUHistoAxis(unsigned nBins, double min, double max,
111  const char* label = 0);
112 
113  double min_;
114  double max_;
115  std::vector<double> binEdges_;
117  unsigned nBins_;
118  bool uniform_;
119 
120  template <typename Numeric, class Axis> friend class HistoND;
121  friend class DualHistoAxis;
122 
123  inline unsigned overflowIndex(
124  const double x, unsigned* binNum) const
125  {
126  if (x < min_)
127  return 0U;
128  else if (x >= max_)
129  return 2U;
130  else
131  {
132  *binNum = binNumber(x);
133  return 1U;
134  }
135  }
136 
137  inline NUHistoAxis() : min_(0.0), max_(0.0),
138  nBins_(0), uniform_(false) {}
139  };
140 }
141 
142 #endif // NPSTAT_NUHISTOAXIS_HH_
143 
unsigned closestValidBin(double x) const
Definition: NUHistoAxis.cc:150
std::vector< double > binEdges_
Definition: NUHistoAxis.h:115
double rightBinEdge(const int binNum) const
Definition: NUHistoAxis.h:56
int binNumber(double x) const
Definition: NUHistoAxis.cc:78
double min() const
Definition: NUHistoAxis.h:39
unsigned overflowIndex(const double x, unsigned *binNum) const
Definition: NUHistoAxis.h:123
void setLabel(const char *newlabel)
Definition: NUHistoAxis.h:69
bool write(std::ostream &of) const
Definition: NUHistoAxis.cc:162
bool isUniform() const
Definition: NUHistoAxis.h:48
bool operator!=(const NUHistoAxis &) const
Definition: NUHistoAxis.cc:73
unsigned nBins() const
Definition: NUHistoAxis.h:44
std::string label_
Definition: NUHistoAxis.h:116
NUHistoAxis rebin(unsigned newBins) const
Definition: NUHistoAxis.cc:44
double leftBinEdge(const int binNum) const
Definition: NUHistoAxis.h:52
double binCenter(const int binNum) const
Definition: NUHistoAxis.h:60
gs::ClassId classId() const
Definition: NUHistoAxis.h:101
static unsigned version()
Definition: NUHistoAxis.h:106
Interval< double > interval() const
Definition: NUHistoAxis.h:41
static NUHistoAxis * read(const gs::ClassId &id, std::istream &in)
Definition: NUHistoAxis.cc:171
bool isClose(const NUHistoAxis &, double tol) const
Definition: NUHistoAxis.cc:49
double fltBinNumber(double x, bool mapLeftEdgeTo0=true) const
Definition: NUHistoAxis.cc:85
Interval< double > binInterval(const int binNum) const
Definition: NUHistoAxis.h:64
static const char * classname()
Definition: NUHistoAxis.h:105
bool operator==(const NUHistoAxis &) const
Definition: NUHistoAxis.cc:63
volatile std::atomic< bool > shutdown_flag false
Definition: DDAxes.h:10
double binWidth(const int binNum) const
Definition: NUHistoAxis.h:45
double max() const
Definition: NUHistoAxis.h:40
double length() const
Definition: NUHistoAxis.h:43
const std::string & label() const
Definition: NUHistoAxis.h:47