test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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> class HistoND;
23  class DualHistoAxis;
24 
30  class HistoAxis
31  {
32  public:
37  HistoAxis(unsigned nBins, double min, double max,
38  const char* label=0);
39 
41 
42  inline double min() const {return min_;}
43  inline double max() const {return max_;}
44  inline Interval<double> interval() const
45  {return Interval<double>(min_, max_);}
46  inline double length() const {return max_ - min_;}
47  inline unsigned nBins() const {return nBins_;}
48  inline double binWidth(const int /*binNum*/=0) const {return bw_;}
49  inline const std::string& label() const {return label_;}
50  inline bool isUniform() const {return true;}
52 
54  inline double binCenter(const int binNum) const
55  {return min_ + (binNum + 0.5)*bw_;}
56 
58  inline double leftBinEdge(const int binNum) const
59  {return min_ + binNum*bw_;}
60 
62  inline double rightBinEdge(const int binNum) const
63  {return min_ + (binNum + 1)*bw_;}
64 
66  inline Interval<double> binInterval(const int binNum) const
67  {return Interval<double>(min_+binNum*bw_, min_+(binNum+1)*bw_);}
68 
70  inline void setLabel(const char* newlabel)
71  {label_ = newlabel ? newlabel : "";}
72 
77  int binNumber(double x) const;
78 
83  unsigned closestValidBin(double x) const;
84 
92  LinearMapper1d binNumberMapper(bool mapLeftEdgeTo0=true) const;
93 
99  inline double fltBinNumber(const double x,
100  const bool mapLeftEdgeTo0=true) const
101  {return (x - min_)/bw_ - (mapLeftEdgeTo0 ? 0.0 : 0.5);}
102 
109  CircularMapper1d kernelScanMapper(bool doubleRange) const;
110 
111  bool operator==(const HistoAxis&) const;
112  bool operator!=(const HistoAxis&) const;
113 
115  bool isClose(const HistoAxis&, double tol) const;
116 
118  HistoAxis rebin(unsigned newBins) const;
119 
121 
122  inline gs::ClassId classId() const {return gs::ClassId(*this);}
123  bool write(std::ostream& of) const;
125 
126  static inline const char* classname() {return "npstat::HistoAxis";}
127  static inline unsigned version() {return 1;}
128  static HistoAxis* read(const gs::ClassId& id, std::istream& in);
129 
130  private:
131  double min_;
132  double max_;
133  double bw_;
135  unsigned nBins_;
136 
137  template <typename Numeric, class Axis> friend class HistoND;
138  friend class DualHistoAxis;
139 
140  inline unsigned overflowIndex(
141  const double x, unsigned* binNumber) const
142  {
143  if (x < min_)
144  return 0U;
145  else if (x >= max_)
146  return 2U;
147  else
148  {
149  const unsigned bin = static_cast<unsigned>((x - min_)/bw_);
150  *binNumber = bin >= nBins_ ? nBins_ - 1U : bin;
151  return 1U;
152  }
153  }
154 
155  unsigned overflowIndexWeighted(double x, unsigned* binNumber,
156  double *weight) const;
157  inline HistoAxis() : min_(0.0), max_(0.0), bw_(0.0), nBins_(0) {}
158  };
159 }
160 
161 #endif // NPSTAT_HISTOAXIS_HH_
162 
static unsigned version()
Definition: HistoAxis.h:127
Linear transformation for circular topology.
bool isUniform() const
Definition: HistoAxis.h:50
int binNumber(double x) const
Definition: HistoAxis.cc:51
const std::string & label() const
Definition: HistoAxis.h:49
std::string label_
Definition: HistoAxis.h:134
double leftBinEdge(const int binNum) const
Definition: HistoAxis.h:58
bool operator!=(const HistoAxis &) const
Definition: HistoAxis.cc:46
void setLabel(const char *newlabel)
Definition: HistoAxis.h:70
bool write(std::ostream &of) const
Definition: HistoAxis.cc:143
gs::ClassId classId() const
Definition: HistoAxis.h:122
static HistoAxis * read(const gs::ClassId &id, std::istream &in)
Definition: HistoAxis.cc:152
HistoAxis rebin(unsigned newBins) const
Definition: HistoAxis.cc:25
unsigned nBins() const
Definition: HistoAxis.h:47
bool isClose(const HistoAxis &, double tol) const
Definition: HistoAxis.cc:30
CircularMapper1d kernelScanMapper(bool doubleRange) const
Definition: HistoAxis.cc:99
Interval< double > interval() const
Definition: HistoAxis.h:44
double binCenter(const int binNum) const
Definition: HistoAxis.h:54
unsigned overflowIndexWeighted(double x, unsigned *binNumber, double *weight) const
Definition: HistoAxis.cc:110
double binWidth(const int=0) const
Definition: HistoAxis.h:48
bool operator==(const HistoAxis &) const
Definition: HistoAxis.cc:38
static const char * classname()
Definition: HistoAxis.h:126
Interval< double > binInterval(const int binNum) const
Definition: HistoAxis.h:66
LinearMapper1d binNumberMapper(bool mapLeftEdgeTo0=true) const
Definition: HistoAxis.cc:90
double length() const
Definition: HistoAxis.h:46
double max() const
Definition: HistoAxis.h:43
unsigned overflowIndex(const double x, unsigned *binNumber) const
Definition: HistoAxis.h:140
unsigned nBins_
Definition: HistoAxis.h:135
double rightBinEdge(const int binNum) const
Definition: HistoAxis.h:62
double fltBinNumber(const double x, const bool mapLeftEdgeTo0=true) const
Definition: HistoAxis.h:99
unsigned closestValidBin(double x) const
Definition: HistoAxis.cc:77
double min() const
Definition: HistoAxis.h:42