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 
119  inline gs::ClassId classId() const {return gs::ClassId(*this);}
120  bool write(std::ostream& of) const;
122 
123  static inline const char* classname() {return "npstat::HistoAxis";}
124  static inline unsigned version() {return 1;}
125  static HistoAxis* read(const gs::ClassId& id, std::istream& in);
126 
127  private:
128  inline HistoAxis() : min_(0.0), max_(0.0), bw_(0.0), nBins_(0) {}
129 
130  double min_;
131  double max_;
132  double bw_;
134  unsigned nBins_;
135 
136  template <typename Numeric, class Axis> friend class HistoND;
137  friend class DualHistoAxis;
138 
139  inline unsigned overflowIndex(
140  const double x, unsigned* binNumber) const
141  {
142  if (x < min_)
143  return 0U;
144  else if (x >= max_)
145  return 2U;
146  else
147  {
148  const unsigned bin = static_cast<unsigned>((x - min_)/bw_);
149  *binNumber = bin >= nBins_ ? nBins_ - 1U : bin;
150  return 1U;
151  }
152  }
153 
154  unsigned overflowIndexWeighted(double x, unsigned* binNumber,
155  double *weight) const;
156  };
157 }
158 
159 #endif // NPSTAT_HISTOAXIS_HH_
160 
static unsigned version()
Definition: HistoAxis.h:124
Linear transformation for circular topology.
bool isUniform() const
Definition: HistoAxis.h:50
int binNumber(double x) const
Definition: HistoAxis.cc:46
const std::string & label() const
Definition: HistoAxis.h:49
std::string label_
Definition: HistoAxis.h:133
double leftBinEdge(const int binNum) const
Definition: HistoAxis.h:58
bool operator!=(const HistoAxis &) const
Definition: HistoAxis.cc:41
void setLabel(const char *newlabel)
Definition: HistoAxis.h:70
bool write(std::ostream &of) const
Definition: HistoAxis.cc:138
gs::ClassId classId() const
Definition: HistoAxis.h:119
static HistoAxis * read(const gs::ClassId &id, std::istream &in)
Definition: HistoAxis.cc:147
unsigned nBins() const
Definition: HistoAxis.h:47
bool isClose(const HistoAxis &, double tol) const
Definition: HistoAxis.cc:25
CircularMapper1d kernelScanMapper(bool doubleRange) const
Definition: HistoAxis.cc:94
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:105
double binWidth(const int=0) const
Definition: HistoAxis.h:48
bool operator==(const HistoAxis &) const
Definition: HistoAxis.cc:33
static const char * classname()
Definition: HistoAxis.h:123
Interval< double > binInterval(const int binNum) const
Definition: HistoAxis.h:66
LinearMapper1d binNumberMapper(bool mapLeftEdgeTo0=true) const
Definition: HistoAxis.cc:85
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:139
unsigned nBins_
Definition: HistoAxis.h:134
Definition: DDAxes.h:10
int weight
Definition: histoStyle.py:50
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:72
double min() const
Definition: HistoAxis.h:42