CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
135  return uniform_ ? u_.overflowIndex(x, binNumber) : a_.overflowIndex(x, binNumber);
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_
unsigned closestValidBin(double x) const
Definition: NUHistoAxis.cc:124
double leftBinEdge(const int binNum) const
Definition: DualHistoAxis.h:55
int binNumber(const double x) const
Definition: DualHistoAxis.h:87
const std::string & label() const
Definition: DualHistoAxis.h:51
double rightBinEdge(const int binNum) const
Definition: NUHistoAxis.h:53
int binNumber(double x) const
Definition: NUHistoAxis.cc:62
double min() const
Definition: NUHistoAxis.h:39
unsigned overflowIndex(const double x, unsigned *binNum) const
Definition: NUHistoAxis.h:117
void setLabel(const char *newlabel)
Definition: NUHistoAxis.h:64
double fltBinNumber(const double x, const bool mapLeftEdgeTo0=true) const
Definition: DualHistoAxis.h:93
int binNumber(double x) const
Definition: HistoAxis.cc:37
bool operator==(const DualHistoAxis &r) const
Histogram axis with non-uniform bin spacing.
unsigned nBins() const
Definition: NUHistoAxis.h:43
const std::string & label() const
Definition: HistoAxis.h:47
double binCenter(const int binNum) const
Definition: DualHistoAxis.h:53
double leftBinEdge(const int binNum) const
Definition: HistoAxis.h:55
bool write(std::ostream &of) const
Definition: DualHistoAxis.cc:8
void setLabel(const char *newlabel)
Definition: HistoAxis.h:66
const HistoAxis * getHistoAxis() const
Definition: DualHistoAxis.h:77
unsigned overflowIndex(const double x, unsigned *binNumber) const
static const char * classname()
double length() const
Definition: DualHistoAxis.h:45
DualHistoAxis(unsigned nBins, double min, double max, const char *label=nullptr)
Definition: DualHistoAxis.h:33
double leftBinEdge(const int binNum) const
Definition: NUHistoAxis.h:50
tuple of
Definition: haddnano.py:40
DualHistoAxis rebin(const unsigned newBins) const
unsigned nBins() const
Definition: HistoAxis.h:45
bool isClose(const HistoAxis &, double tol) const
Definition: HistoAxis.cc:26
double binCenter(const int binNum) const
Definition: NUHistoAxis.h:56
const NUHistoAxis * getNUHistoAxis() const
Definition: DualHistoAxis.h:73
DualHistoAxis(const HistoAxis &u)
Definition: DualHistoAxis.h:28
double min() const
Definition: DualHistoAxis.h:39
static DualHistoAxis * read(const gs::ClassId &id, std::istream &in)
Interval< double > interval() const
Definition: HistoAxis.h:43
bool operator!=(const DualHistoAxis &r) const
double binCenter(const int binNum) const
Definition: HistoAxis.h:52
DualHistoAxis(const std::vector< double > &binEdges, const char *label=nullptr)
Definition: DualHistoAxis.h:30
double max() const
Definition: DualHistoAxis.h:41
bool isUniform() const
Definition: DualHistoAxis.h:37
void setLabel(const char *newlabel)
Definition: DualHistoAxis.h:81
Interval< double > interval() const
Definition: NUHistoAxis.h:41
double binWidth(const int=0) const
Definition: HistoAxis.h:46
double binWidth(const int binNum) const
Definition: DualHistoAxis.h:49
double rightBinEdge(const int binNum) const
Definition: DualHistoAxis.h:59
Interval< double > interval() const
Definition: DualHistoAxis.h:43
Interval< double > binInterval(const int binNum) const
Definition: HistoAxis.h:61
static unsigned version()
bool isClose(const NUHistoAxis &, double tol) const
Definition: NUHistoAxis.cc:45
unsigned nBins() const
Definition: DualHistoAxis.h:47
double fltBinNumber(double x, bool mapLeftEdgeTo0=true) const
Definition: NUHistoAxis.cc:67
double length() const
Definition: HistoAxis.h:44
double a
Definition: hdecay.h:119
double max() const
Definition: HistoAxis.h:42
Interval< double > binInterval(const int binNum) const
Definition: NUHistoAxis.h:59
gs::ClassId classId() const
unsigned overflowIndex(const double x, unsigned *binNumber) const
Definition: HistoAxis.h:136
Interval< double > binInterval(const int binNum) const
Definition: DualHistoAxis.h:63
bool isClose(const DualHistoAxis &r, const double tol) const
double rightBinEdge(const int binNum) const
Definition: HistoAxis.h:58
double binWidth(const int binNum) const
Definition: NUHistoAxis.h:44
unsigned closestValidBin(const double x) const
Definition: DualHistoAxis.h:98
double fltBinNumber(const double x, const bool mapLeftEdgeTo0=true) const
Definition: HistoAxis.h:94
unsigned closestValidBin(double x) const
Definition: HistoAxis.cc:56
double max() const
Definition: NUHistoAxis.h:40
double length() const
Definition: NUHistoAxis.h:42
Histogram axis with equidistant bins.
double min() const
Definition: HistoAxis.h:41
static std::vector< double > dummy_vec()
const std::string & label() const
Definition: NUHistoAxis.h:45
DualHistoAxis(const NUHistoAxis &a)
Definition: DualHistoAxis.h:26