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_
npstat::HistoAxis::nBins
unsigned nBins() const
Definition: HistoAxis.h:45
npstat::HistoAxis::rebin
HistoAxis rebin(unsigned newBins) const
Definition: HistoAxis.cc:24
npstat::HistoAxis::isClose
bool isClose(const HistoAxis &, double tol) const
Definition: HistoAxis.cc:26
npstat::HistoAxis::binInterval
Interval< double > binInterval(const int binNum) const
Definition: HistoAxis.h:61
npstat::HistoAxis::operator==
bool operator==(const HistoAxis &) const
Definition: HistoAxis.cc:31
npstat::HistoAxis::min
double min() const
Definition: HistoAxis.h:41
npstat::LinearMapper1d
Definition: LinearMapper1d.h:18
npstat::HistoAxis::version
static unsigned version()
Definition: HistoAxis.h:122
npstat::HistoAxis::fltBinNumber
double fltBinNumber(const double x, const bool mapLeftEdgeTo0=true) const
Definition: HistoAxis.h:94
DDAxes::x
npstat::HistoAxis::setLabel
void setLabel(const char *newlabel)
Definition: HistoAxis.h:66
npstat::HistoAxis::classId
gs::ClassId classId() const
Definition: HistoAxis.h:117
npstat::HistoAxis::interval
Interval< double > interval() const
Definition: HistoAxis.h:43
npstat::HistoAxis::length
double length() const
Definition: HistoAxis.h:44
npstat::HistoAxis::operator!=
bool operator!=(const HistoAxis &) const
Definition: HistoAxis.cc:35
npstat
Definition: AbsArrayProjector.h:14
npstat::HistoAxis::write
bool write(std::ostream &of) const
Definition: HistoAxis.cc:113
npstat::HistoAxis::rightBinEdge
double rightBinEdge(const int binNum) const
Definition: HistoAxis.h:58
npstat::Interval
Definition: Interval.h:25
npstat::DualHistoAxis
Definition: DualHistoAxis.h:23
npstat::HistoAxis::min_
double min_
Definition: HistoAxis.h:126
npstat::HistoAxis::max
double max() const
Definition: HistoAxis.h:42
npstat::HistoAxis::label_
std::string label_
Definition: HistoAxis.h:129
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
npstat::HistoAxis::overflowIndexWeighted
unsigned overflowIndexWeighted(double x, unsigned *binNumber, double *weight) const
Definition: HistoAxis.cc:87
npstat::HistoAxis::label
const std::string & label() const
Definition: HistoAxis.h:47
npstat::HistoAxis::classname
static const char * classname()
Definition: HistoAxis.h:121
npstat::HistoAxis
Definition: HistoAxis.h:31
npstat::HistoAxis::nBins_
unsigned nBins_
Definition: HistoAxis.h:130
npstat::HistoAxis::max_
double max_
Definition: HistoAxis.h:127
recoMuon::in
Definition: RecoMuonEnumerators.h:6
CircularMapper1d.h
Linear transformation for circular topology.
npstat::HistoAxis::binNumberMapper
LinearMapper1d binNumberMapper(bool mapLeftEdgeTo0=true) const
Definition: HistoAxis.cc:67
npstat::HistoAxis::read
static HistoAxis * read(const gs::ClassId &id, std::istream &in)
Definition: HistoAxis.cc:121
npstat::HistoND
Definition: HistoAxis.h:23
npstat::HistoAxis::closestValidBin
unsigned closestValidBin(double x) const
Definition: HistoAxis.cc:56
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
npstat::HistoAxis::isUniform
bool isUniform() const
Definition: HistoAxis.h:48
npstat::HistoAxis::leftBinEdge
double leftBinEdge(const int binNum) const
Definition: HistoAxis.h:55
Interval.h
Template to represent intervals in one dimension.
npstat::HistoAxis::bw_
double bw_
Definition: HistoAxis.h:128
npstat::HistoAxis::binCenter
double binCenter(const int binNum) const
Definition: HistoAxis.h:52
npstat::HistoAxis::kernelScanMapper
CircularMapper1d kernelScanMapper(bool doubleRange) const
Definition: HistoAxis.cc:76
npstat::HistoAxis::overflowIndex
unsigned overflowIndex(const double x, unsigned *binNumber) const
Definition: HistoAxis.h:136
npstat::CircularMapper1d
Definition: CircularMapper1d.h:23
npstat::HistoAxis::binWidth
double binWidth(const int=0) const
Definition: HistoAxis.h:46
weight
Definition: weight.py:1
npstat::HistoAxis::HistoAxis
HistoAxis()
Definition: HistoAxis.h:149
npstat::HistoAxis::binNumber
int binNumber(double x) const
Definition: HistoAxis.cc:37