CMS 3D CMS Logo

HistoAxis.h
Go to the documentation of this file.
1 #ifndef NPSTAT_HISTOAXIS_HH_
2 #define NPSTAT_HISTOAXIS_HH_
3 
14 #include <utility>
15 
16 #include "Alignment/Geners/interface/ClassId.hh"
17 
20 
21 namespace npstat {
22  template <typename Numeric, class Axis>
23  class HistoND;
24  class DualHistoAxis;
25 
31  class HistoAxis {
32  public:
37  HistoAxis(unsigned nBins, double min, double max, const char* label = nullptr);
38 
40 
41  inline double min() const { return min_; }
42  inline double max() const { return max_; }
43  inline Interval<double> interval() const { 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*/ = 0) const { return bw_; }
47  inline const std::string& label() const { return label_; }
48  inline bool isUniform() const { return true; }
50 
52  inline double binCenter(const int binNum) const { return min_ + (binNum + 0.5) * bw_; }
53 
55  inline double leftBinEdge(const int binNum) const { return min_ + binNum * bw_; }
56 
58  inline double rightBinEdge(const int binNum) const { return min_ + (binNum + 1) * bw_; }
59 
61  inline Interval<double> binInterval(const int binNum) const {
62  return Interval<double>(min_ + binNum * bw_, min_ + (binNum + 1) * bw_);
63  }
64 
66  inline void setLabel(const char* newlabel) { label_ = newlabel ? newlabel : ""; }
67 
72  int binNumber(double x) const;
73 
78  unsigned closestValidBin(double x) const;
79 
87  LinearMapper1d binNumberMapper(bool mapLeftEdgeTo0 = true) const;
88 
94  inline double fltBinNumber(const double x, const bool mapLeftEdgeTo0 = true) const {
95  return (x - min_) / bw_ - (mapLeftEdgeTo0 ? 0.0 : 0.5);
96  }
97 
104  CircularMapper1d kernelScanMapper(bool doubleRange) const;
105 
106  bool operator==(const HistoAxis&) const;
107  bool operator!=(const HistoAxis&) const;
108 
110  bool isClose(const HistoAxis&, double tol) const;
111 
113  HistoAxis rebin(unsigned newBins) const;
114 
116 
117  inline gs::ClassId classId() const { return gs::ClassId(*this); }
118  bool write(std::ostream& of) const;
120 
121  static inline const char* classname() { return "npstat::HistoAxis"; }
122  static inline unsigned version() { return 1; }
123  static HistoAxis* read(const gs::ClassId& id, std::istream& in);
124 
125  private:
126  double min_;
127  double max_;
128  double bw_;
130  unsigned nBins_;
131 
132  template <typename Numeric, class Axis>
133  friend class HistoND;
134  friend class DualHistoAxis;
135 
136  inline unsigned overflowIndex(const double x, unsigned* binNumber) const {
137  if (x < min_)
138  return 0U;
139  else if (x >= max_)
140  return 2U;
141  else {
142  const unsigned bin = static_cast<unsigned>((x - min_) / bw_);
143  *binNumber = bin >= nBins_ ? nBins_ - 1U : bin;
144  return 1U;
145  }
146  }
147 
148  unsigned overflowIndexWeighted(double x, unsigned* binNumber, double* weight) const;
149  inline HistoAxis() : min_(0.0), max_(0.0), bw_(0.0), nBins_(0) {}
150  };
151 } // namespace npstat
152 
153 #endif // NPSTAT_HISTOAXIS_HH_
static unsigned version()
Definition: HistoAxis.h:122
Linear transformation for circular topology.
bool isUniform() const
Definition: HistoAxis.h:48
int binNumber(double x) const
Definition: HistoAxis.cc:37
Definition: weight.py:1
const std::string & label() const
Definition: HistoAxis.h:47
std::string label_
Definition: HistoAxis.h:129
double leftBinEdge(const int binNum) const
Definition: HistoAxis.h:55
bool operator!=(const HistoAxis &) const
Definition: HistoAxis.cc:35
void setLabel(const char *newlabel)
Definition: HistoAxis.h:66
bool write(std::ostream &of) const
Definition: HistoAxis.cc:113
gs::ClassId classId() const
Definition: HistoAxis.h:117
static HistoAxis * read(const gs::ClassId &id, std::istream &in)
Definition: HistoAxis.cc:121
HistoAxis rebin(unsigned newBins) const
Definition: HistoAxis.cc:24
unsigned nBins() const
Definition: HistoAxis.h:45
bool isClose(const HistoAxis &, double tol) const
Definition: HistoAxis.cc:26
CircularMapper1d kernelScanMapper(bool doubleRange) const
Definition: HistoAxis.cc:76
Interval< double > interval() const
Definition: HistoAxis.h:43
double binCenter(const int binNum) const
Definition: HistoAxis.h:52
unsigned overflowIndexWeighted(double x, unsigned *binNumber, double *weight) const
Definition: HistoAxis.cc:87
double binWidth(const int=0) const
Definition: HistoAxis.h:46
bool operator==(const HistoAxis &) const
Definition: HistoAxis.cc:31
static const char * classname()
Definition: HistoAxis.h:121
Interval< double > binInterval(const int binNum) const
Definition: HistoAxis.h:61
LinearMapper1d binNumberMapper(bool mapLeftEdgeTo0=true) const
Definition: HistoAxis.cc:67
double length() const
Definition: HistoAxis.h:44
double max() const
Definition: HistoAxis.h:42
unsigned overflowIndex(const double x, unsigned *binNumber) const
Definition: HistoAxis.h:136
unsigned nBins_
Definition: HistoAxis.h:130
double rightBinEdge(const int binNum) const
Definition: HistoAxis.h:58
double fltBinNumber(const double x, const bool mapLeftEdgeTo0=true) const
Definition: HistoAxis.h:94
unsigned closestValidBin(double x) const
Definition: HistoAxis.cc:56
double min() const
Definition: HistoAxis.h:41