CMS 3D CMS Logo

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>
22  class HistoND;
23  class DualHistoAxis;
24 
28  class NUHistoAxis {
29  public:
35  NUHistoAxis(const std::vector<double>& binEdges, const char* label = nullptr);
36 
38 
39  inline double min() const { return min_; }
40  inline double max() const { return max_; }
41  inline Interval<double> interval() const { return Interval<double>(min_, max_); }
42  inline double length() const { return max_ - min_; }
43  inline unsigned nBins() const { return nBins_; }
44  inline double binWidth(const int binNum) const { return binEdges_.at(binNum + 1) - binEdges_.at(binNum); }
45  inline const std::string& label() const { return label_; }
46  inline bool isUniform() const { return uniform_; }
48 
50  inline double leftBinEdge(const int binNum) const { return binEdges_.at(binNum); }
51 
53  inline double rightBinEdge(const int binNum) const { return binEdges_.at(binNum + 1); }
54 
56  inline double binCenter(const int binNum) const { return 0.5 * (binEdges_.at(binNum) + binEdges_.at(binNum + 1)); }
57 
59  inline Interval<double> binInterval(const int binNum) const {
60  return Interval<double>(binEdges_.at(binNum), binEdges_.at(binNum + 1));
61  }
62 
64  inline void setLabel(const char* newlabel) { label_ = newlabel ? newlabel : ""; }
65 
70  int binNumber(double x) const;
71 
76  double fltBinNumber(double x, bool mapLeftEdgeTo0 = true) const;
77 
82  unsigned closestValidBin(double x) const;
83 
84  bool operator==(const NUHistoAxis&) const;
85  bool operator!=(const NUHistoAxis&) const;
86 
88  bool isClose(const NUHistoAxis&, double tol) const;
89 
91  NUHistoAxis rebin(unsigned newBins) const;
92 
94 
95  inline gs::ClassId classId() const { return gs::ClassId(*this); }
96  bool write(std::ostream& of) const;
98 
99  static inline const char* classname() { return "npstat::NUHistoAxis"; }
100  static inline unsigned version() { return 1; }
101  static NUHistoAxis* read(const gs::ClassId& id, std::istream& in);
102 
103  private:
104  NUHistoAxis(unsigned nBins, double min, double max, const char* label = nullptr);
105 
106  double min_;
107  double max_;
108  std::vector<double> binEdges_;
110  unsigned nBins_;
111  bool uniform_;
112 
113  template <typename Numeric, class Axis>
114  friend class HistoND;
115  friend class DualHistoAxis;
116 
117  inline unsigned overflowIndex(const double x, unsigned* binNum) const {
118  if (x < min_)
119  return 0U;
120  else if (x >= max_)
121  return 2U;
122  else {
123  *binNum = binNumber(x);
124  return 1U;
125  }
126  }
127 
128  inline NUHistoAxis() : min_(0.0), max_(0.0), nBins_(0), uniform_(false) {}
129  };
130 } // namespace npstat
131 
132 #endif // NPSTAT_NUHISTOAXIS_HH_
npstat::NUHistoAxis::operator!=
bool operator!=(const NUHistoAxis &) const
Definition: NUHistoAxis.cc:60
npstat::NUHistoAxis::binNumber
int binNumber(double x) const
Definition: NUHistoAxis.cc:62
funct::false
false
Definition: Factorize.h:34
npstat::NUHistoAxis::length
double length() const
Definition: NUHistoAxis.h:42
npstat::NUHistoAxis::overflowIndex
unsigned overflowIndex(const double x, unsigned *binNum) const
Definition: NUHistoAxis.h:117
npstat::NUHistoAxis::rightBinEdge
double rightBinEdge(const int binNum) const
Definition: NUHistoAxis.h:53
npstat::NUHistoAxis::nBins_
unsigned nBins_
Definition: NUHistoAxis.h:110
npstat::NUHistoAxis::nBins
unsigned nBins() const
Definition: NUHistoAxis.h:43
DDAxes::x
npstat::NUHistoAxis::binEdges_
std::vector< double > binEdges_
Definition: NUHistoAxis.h:108
npstat::NUHistoAxis::read
static NUHistoAxis * read(const gs::ClassId &id, std::istream &in)
Definition: NUHistoAxis.cc:142
npstat::NUHistoAxis::write
bool write(std::ostream &of) const
Definition: NUHistoAxis.cc:134
npstat::NUHistoAxis::classname
static const char * classname()
Definition: NUHistoAxis.h:99
npstat
Definition: AbsArrayProjector.h:14
npstat::NUHistoAxis::rebin
NUHistoAxis rebin(unsigned newBins) const
Definition: NUHistoAxis.cc:41
npstat::Interval
Definition: Interval.h:25
npstat::DualHistoAxis
Definition: DualHistoAxis.h:23
npstat::NUHistoAxis::NUHistoAxis
NUHistoAxis()
Definition: NUHistoAxis.h:128
npstat::NUHistoAxis::classId
gs::ClassId classId() const
Definition: NUHistoAxis.h:95
npstat::NUHistoAxis::leftBinEdge
double leftBinEdge(const int binNum) const
Definition: NUHistoAxis.h:50
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
npstat::NUHistoAxis::uniform_
bool uniform_
Definition: NUHistoAxis.h:111
npstat::NUHistoAxis::label
const std::string & label() const
Definition: NUHistoAxis.h:45
npstat::NUHistoAxis::max
double max() const
Definition: NUHistoAxis.h:40
npstat::NUHistoAxis::label_
std::string label_
Definition: NUHistoAxis.h:109
npstat::NUHistoAxis::min
double min() const
Definition: NUHistoAxis.h:39
npstat::NUHistoAxis::closestValidBin
unsigned closestValidBin(double x) const
Definition: NUHistoAxis.cc:124
recoMuon::in
Definition: RecoMuonEnumerators.h:6
npstat::NUHistoAxis::version
static unsigned version()
Definition: NUHistoAxis.h:100
npstat::NUHistoAxis::binInterval
Interval< double > binInterval(const int binNum) const
Definition: NUHistoAxis.h:59
npstat::NUHistoAxis::max_
double max_
Definition: NUHistoAxis.h:107
npstat::NUHistoAxis::isClose
bool isClose(const NUHistoAxis &, double tol) const
Definition: NUHistoAxis.cc:45
npstat::NUHistoAxis::isUniform
bool isUniform() const
Definition: NUHistoAxis.h:46
npstat::HistoND
Definition: HistoAxis.h:23
npstat::NUHistoAxis::min_
double min_
Definition: NUHistoAxis.h:106
npstat::NUHistoAxis::fltBinNumber
double fltBinNumber(double x, bool mapLeftEdgeTo0=true) const
Definition: NUHistoAxis.cc:67
npstat::NUHistoAxis::interval
Interval< double > interval() const
Definition: NUHistoAxis.h:41
npstat::NUHistoAxis::binWidth
double binWidth(const int binNum) const
Definition: NUHistoAxis.h:44
npstat::NUHistoAxis::operator==
bool operator==(const NUHistoAxis &) const
Definition: NUHistoAxis.cc:55
Interval.h
Template to represent intervals in one dimension.
npstat::NUHistoAxis::binCenter
double binCenter(const int binNum) const
Definition: NUHistoAxis.h:56
npstat::NUHistoAxis::setLabel
void setLabel(const char *newlabel)
Definition: NUHistoAxis.h:64
npstat::NUHistoAxis
Definition: NUHistoAxis.h:28