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