CMS 3D CMS Logo

DualHistoAxis.h
Go to the documentation of this file.
1 #ifndef NPSTAT_DUALHISTOAXIS_HH_
2 #define NPSTAT_DUALHISTOAXIS_HH_
3 
16 
17 namespace npstat {
23  class DualHistoAxis {
24  public:
25  // Constructors
26  inline DualHistoAxis(const NUHistoAxis& a) : a_(a), u_(1U, 0.0, 1.0), uniform_(false) {}
27 
28  inline DualHistoAxis(const HistoAxis& u) : a_(dummy_vec()), u_(u), uniform_(true) {}
29 
30  inline DualHistoAxis(const std::vector<double>& binEdges, const char* label = nullptr)
31  : a_(binEdges, label), u_(1U, 0.0, 1.0), uniform_(false) {}
32 
33  inline DualHistoAxis(unsigned nBins, double min, double max, const char* label = nullptr)
34  : a_(dummy_vec()), u_(nBins, min, max, label), uniform_(true) {}
35 
36  // Inspectors
37  inline bool isUniform() const { return uniform_; }
38 
39  inline double min() const { return uniform_ ? u_.min() : a_.min(); }
40 
41  inline double max() const { return uniform_ ? u_.max() : a_.max(); }
42 
43  inline Interval<double> interval() const { return uniform_ ? u_.interval() : a_.interval(); }
44 
45  inline double length() const { return uniform_ ? u_.length() : a_.length(); }
46 
47  inline unsigned nBins() const { return uniform_ ? u_.nBins() : a_.nBins(); }
48 
49  inline double binWidth(const int binNum) const { return uniform_ ? u_.binWidth(binNum) : a_.binWidth(binNum); }
50 
51  inline const std::string& label() const { return uniform_ ? u_.label() : a_.label(); }
52 
53  inline double binCenter(const int binNum) const { return uniform_ ? u_.binCenter(binNum) : a_.binCenter(binNum); }
54 
55  inline double leftBinEdge(const int binNum) const {
56  return uniform_ ? u_.leftBinEdge(binNum) : a_.leftBinEdge(binNum);
57  }
58 
59  inline double rightBinEdge(const int binNum) const {
60  return uniform_ ? u_.rightBinEdge(binNum) : a_.rightBinEdge(binNum);
61  }
62 
63  inline Interval<double> binInterval(const int binNum) const {
64  return uniform_ ? u_.binInterval(binNum) : a_.binInterval(binNum);
65  }
66 
68 
73  inline const NUHistoAxis* getNUHistoAxis() const {
74  return uniform_ ? static_cast<const NUHistoAxis*>(nullptr) : &a_;
75  }
76 
77  inline const HistoAxis* getHistoAxis() const { return uniform_ ? &u_ : static_cast<const HistoAxis*>(nullptr); }
79 
81  inline void setLabel(const char* newlabel) { uniform_ ? u_.setLabel(newlabel) : a_.setLabel(newlabel); }
82 
87  inline int binNumber(const double x) const { return uniform_ ? u_.binNumber(x) : a_.binNumber(x); }
88 
93  inline double fltBinNumber(const double x, const bool mapLeftEdgeTo0 = true) const {
94  return uniform_ ? u_.fltBinNumber(x, mapLeftEdgeTo0) : a_.fltBinNumber(x, mapLeftEdgeTo0);
95  }
96 
98  inline unsigned closestValidBin(const double x) const {
99  return uniform_ ? u_.closestValidBin(x) : a_.closestValidBin(x);
100  }
101 
102  inline bool operator==(const DualHistoAxis& r) const { return uniform_ == r.uniform_ && a_ == r.a_ && u_ == r.u_; }
103 
104  inline bool operator!=(const DualHistoAxis& r) const { return !(*this == r); }
105 
107  inline bool isClose(const DualHistoAxis& r, const double tol) const {
108  return uniform_ == r.uniform_ && a_.isClose(r.a_, tol) && u_.isClose(r.u_, tol);
109  }
110 
112  inline DualHistoAxis rebin(const unsigned newBins) const {
113  return DualHistoAxis(newBins, min(), max(), label().c_str());
114  }
115 
117  // Method related to "geners" I/O
118  inline gs::ClassId classId() const { return gs::ClassId(*this); }
119  bool write(std::ostream& of) const;
121 
122  static inline const char* classname() { return "npstat::DualHistoAxis"; }
123  static inline unsigned version() { return 1; }
124  static DualHistoAxis* read(const gs::ClassId& id, std::istream& in);
125 
126  private:
129  bool uniform_;
130 
131  template <typename Numeric, class Axis>
132  friend class HistoND;
133 
134  inline unsigned overflowIndex(const double x, unsigned* binNumber) const {
136  }
137 
138  inline static std::vector<double> dummy_vec() {
139  std::vector<double> vec(2, 0.0);
140  vec[1] = 1.0;
141  return vec;
142  }
143 
144  inline DualHistoAxis() : a_(dummy_vec()), u_(1U, 0.0, 1.0), uniform_(true) {}
145  };
146 } // namespace npstat
147 
148 #endif // NPSTAT_DUALHISTOAXIS_HH_
npstat::DualHistoAxis::DualHistoAxis
DualHistoAxis(const HistoAxis &u)
Definition: DualHistoAxis.h:28
npstat::DualHistoAxis::u_
HistoAxis u_
Definition: DualHistoAxis.h:128
npstat::HistoAxis::nBins
unsigned nBins() const
Definition: HistoAxis.h:45
npstat::DualHistoAxis::version
static unsigned version()
Definition: DualHistoAxis.h:123
npstat::DualHistoAxis::operator!=
bool operator!=(const DualHistoAxis &r) const
Definition: DualHistoAxis.h:104
npstat::NUHistoAxis::binNumber
int binNumber(double x) const
Definition: NUHistoAxis.cc:62
HistoAxis.h
Histogram axis with equidistant bins.
npstat::DualHistoAxis::closestValidBin
unsigned closestValidBin(const double x) const
Definition: DualHistoAxis.h:98
funct::false
false
Definition: Factorize.h:34
npstat::DualHistoAxis::isClose
bool isClose(const DualHistoAxis &r, const double tol) const
Definition: DualHistoAxis.h:107
npstat::DualHistoAxis::binCenter
double binCenter(const int binNum) const
Definition: DualHistoAxis.h:53
npstat::HistoAxis::isClose
bool isClose(const HistoAxis &, double tol) const
Definition: HistoAxis.cc:26
npstat::DualHistoAxis::overflowIndex
unsigned overflowIndex(const double x, unsigned *binNumber) const
Definition: DualHistoAxis.h:134
npstat::HistoAxis::binInterval
Interval< double > binInterval(const int binNum) const
Definition: HistoAxis.h:61
npstat::DualHistoAxis::fltBinNumber
double fltBinNumber(const double x, const bool mapLeftEdgeTo0=true) const
Definition: DualHistoAxis.h:93
npstat::HistoAxis::min
double min() const
Definition: HistoAxis.h:41
npstat::DualHistoAxis::write
bool write(std::ostream &of) const
Definition: DualHistoAxis.cc:8
npstat::NUHistoAxis::length
double length() const
Definition: NUHistoAxis.h:42
npstat::DualHistoAxis::isUniform
bool isUniform() const
Definition: DualHistoAxis.h:37
npstat::DualHistoAxis::uniform_
bool uniform_
Definition: DualHistoAxis.h:129
npstat::NUHistoAxis::overflowIndex
unsigned overflowIndex(const double x, unsigned *binNum) const
Definition: NUHistoAxis.h:117
npstat::HistoAxis::fltBinNumber
double fltBinNumber(const double x, const bool mapLeftEdgeTo0=true) const
Definition: HistoAxis.h:94
npstat::NUHistoAxis::rightBinEdge
double rightBinEdge(const int binNum) const
Definition: NUHistoAxis.h:53
npstat::DualHistoAxis::leftBinEdge
double leftBinEdge(const int binNum) const
Definition: DualHistoAxis.h:55
npstat::NUHistoAxis::nBins
unsigned nBins() const
Definition: NUHistoAxis.h:43
DDAxes::x
npstat::DualHistoAxis::getHistoAxis
const HistoAxis * getHistoAxis() const
Definition: DualHistoAxis.h:77
npstat::HistoAxis::setLabel
void setLabel(const char *newlabel)
Definition: HistoAxis.h:66
npstat::HistoAxis::interval
Interval< double > interval() const
Definition: HistoAxis.h:43
NUHistoAxis.h
Histogram axis with non-uniform bin spacing.
npstat::HistoAxis::length
double length() const
Definition: HistoAxis.h:44
npstat::DualHistoAxis::max
double max() const
Definition: DualHistoAxis.h:41
npstat::DualHistoAxis::read
static DualHistoAxis * read(const gs::ClassId &id, std::istream &in)
Definition: DualHistoAxis.cc:17
npstat::DualHistoAxis::DualHistoAxis
DualHistoAxis(const NUHistoAxis &a)
Definition: DualHistoAxis.h:26
npstat
Definition: AbsArrayProjector.h:14
npstat::DualHistoAxis::dummy_vec
static std::vector< double > dummy_vec()
Definition: DualHistoAxis.h:138
npstat::DualHistoAxis::interval
Interval< double > interval() const
Definition: DualHistoAxis.h:43
npstat::HistoAxis::rightBinEdge
double rightBinEdge(const int binNum) const
Definition: HistoAxis.h:58
npstat::DualHistoAxis::classname
static const char * classname()
Definition: DualHistoAxis.h:122
npstat::Interval
Definition: Interval.h:25
npstat::DualHistoAxis
Definition: DualHistoAxis.h:23
npstat::DualHistoAxis::binWidth
double binWidth(const int binNum) const
Definition: DualHistoAxis.h:49
npstat::NUHistoAxis::leftBinEdge
double leftBinEdge(const int binNum) const
Definition: NUHistoAxis.h:50
npstat::HistoAxis::max
double max() const
Definition: HistoAxis.h:42
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
npstat::DualHistoAxis::binNumber
int binNumber(const double x) const
Definition: DualHistoAxis.h:87
npstat::HistoAxis::label
const std::string & label() const
Definition: HistoAxis.h:47
npstat::NUHistoAxis::label
const std::string & label() const
Definition: NUHistoAxis.h:45
npstat::NUHistoAxis::max
double max() const
Definition: NUHistoAxis.h:40
funct::true
true
Definition: Factorize.h:173
npstat::HistoAxis
Definition: HistoAxis.h:31
a
double a
Definition: hdecay.h:119
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::DualHistoAxis::getNUHistoAxis
const NUHistoAxis * getNUHistoAxis() const
Definition: DualHistoAxis.h:73
npstat::NUHistoAxis::binInterval
Interval< double > binInterval(const int binNum) const
Definition: NUHistoAxis.h:59
npstat::DualHistoAxis::label
const std::string & label() const
Definition: DualHistoAxis.h:51
npstat::NUHistoAxis::isClose
bool isClose(const NUHistoAxis &, double tol) const
Definition: NUHistoAxis.cc:45
npstat::HistoND
Definition: HistoAxis.h:23
npstat::HistoAxis::closestValidBin
unsigned closestValidBin(double x) const
Definition: HistoAxis.cc:56
npstat::DualHistoAxis::DualHistoAxis
DualHistoAxis(unsigned nBins, double min, double max, const char *label=nullptr)
Definition: DualHistoAxis.h:33
npstat::NUHistoAxis::fltBinNumber
double fltBinNumber(double x, bool mapLeftEdgeTo0=true) const
Definition: NUHistoAxis.cc:67
alignCSCRings.r
r
Definition: alignCSCRings.py:93
npstat::NUHistoAxis::interval
Interval< double > interval() const
Definition: NUHistoAxis.h:41
npstat::DualHistoAxis::binInterval
Interval< double > binInterval(const int binNum) const
Definition: DualHistoAxis.h:63
npstat::DualHistoAxis::classId
gs::ClassId classId() const
Definition: DualHistoAxis.h:118
npstat::HistoAxis::leftBinEdge
double leftBinEdge(const int binNum) const
Definition: HistoAxis.h:55
npstat::DualHistoAxis::min
double min() const
Definition: DualHistoAxis.h:39
npstat::NUHistoAxis::binWidth
double binWidth(const int binNum) const
Definition: NUHistoAxis.h:44
npstat::NUHistoAxis::binCenter
double binCenter(const int binNum) const
Definition: NUHistoAxis.h:56
npstat::HistoAxis::binCenter
double binCenter(const int binNum) const
Definition: HistoAxis.h:52
npstat::DualHistoAxis::setLabel
void setLabel(const char *newlabel)
Definition: DualHistoAxis.h:81
npstat::NUHistoAxis::setLabel
void setLabel(const char *newlabel)
Definition: NUHistoAxis.h:64
npstat::HistoAxis::overflowIndex
unsigned overflowIndex(const double x, unsigned *binNumber) const
Definition: HistoAxis.h:136
npstat::DualHistoAxis::operator==
bool operator==(const DualHistoAxis &r) const
Definition: DualHistoAxis.h:102
npstat::NUHistoAxis
Definition: NUHistoAxis.h:28
npstat::DualHistoAxis::DualHistoAxis
DualHistoAxis(const std::vector< double > &binEdges, const char *label=nullptr)
Definition: DualHistoAxis.h:30
npstat::DualHistoAxis::a_
NUHistoAxis a_
Definition: DualHistoAxis.h:127
npstat::DualHistoAxis::rebin
DualHistoAxis rebin(const unsigned newBins) const
Definition: DualHistoAxis.h:112
npstat::DualHistoAxis::nBins
unsigned nBins() const
Definition: DualHistoAxis.h:47
npstat::DualHistoAxis::length
double length() const
Definition: DualHistoAxis.h:45
npstat::HistoAxis::binWidth
double binWidth(const int=0) const
Definition: HistoAxis.h:46
npstat::DualHistoAxis::DualHistoAxis
DualHistoAxis()
Definition: DualHistoAxis.h:144
npstat::HistoAxis::binNumber
int binNumber(double x) const
Definition: HistoAxis.cc:37
npstat::DualHistoAxis::rightBinEdge
double rightBinEdge(const int binNum) const
Definition: DualHistoAxis.h:59