CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 {
24  {
25  public:
26  // Constructors
27  inline DualHistoAxis(const NUHistoAxis& a)
28  : a_(a), u_(1U, 0.0, 1.0), uniform_(false) {}
29 
30  inline DualHistoAxis(const HistoAxis& u)
31  : a_(dummy_vec()), u_(u), uniform_(true) {}
32 
33  inline DualHistoAxis(const std::vector<double>& binEdges,
34  const char* label = 0)
35  : a_(binEdges, label), u_(1U, 0.0, 1.0), uniform_(false) {}
36 
37  inline DualHistoAxis(unsigned nBins, double min, double max,
38  const char* label = 0)
39  : a_(dummy_vec()), u_(nBins, min, max, label), uniform_(true) {}
40 
41  // Inspectors
42  inline bool isUniform() const {return uniform_;}
43 
44  inline double min() const
45  {return uniform_ ? u_.min() : a_.min();}
46 
47  inline double max() const
48  {return uniform_ ? u_.max() : a_.max();}
49 
50  inline Interval<double> interval() const
51  {return uniform_ ? u_.interval() : a_.interval();}
52 
53  inline double length() const
54  {return uniform_ ? u_.length() : a_.length();}
55 
56  inline unsigned nBins() const
57  {return uniform_ ? u_.nBins() : a_.nBins();}
58 
59  inline double binWidth(const int binNum) const
60  {return uniform_ ? u_.binWidth(binNum) : a_.binWidth(binNum);}
61 
62  inline const std::string& label() const
63  {return uniform_ ? u_.label() : a_.label();}
64 
65  inline double binCenter(const int binNum) const
66  {return uniform_ ? u_.binCenter(binNum) : a_.binCenter(binNum);}
67 
68  inline double leftBinEdge(const int binNum) const
69  {return uniform_ ? u_.leftBinEdge(binNum) : a_.leftBinEdge(binNum);}
70 
71  inline double rightBinEdge(const int binNum) const
72  {return uniform_ ? u_.rightBinEdge(binNum) : a_.rightBinEdge(binNum);}
73 
74  inline Interval<double> binInterval(const int binNum) const
75  {return uniform_ ? u_.binInterval(binNum) : a_.binInterval(binNum);}
76 
78 
83  inline const NUHistoAxis* getNUHistoAxis() const
84  {return uniform_ ? static_cast<const NUHistoAxis*>(0) : &a_;}
85 
86  inline const HistoAxis* getHistoAxis() const
87  {return uniform_ ? &u_ : static_cast<const HistoAxis*>(0);}
89 
91  inline void setLabel(const char* newlabel)
92  {uniform_ ? u_.setLabel(newlabel) : a_.setLabel(newlabel);}
93 
98  inline int binNumber(const double x) const
99  {return uniform_ ? u_.binNumber(x) : a_.binNumber(x);}
100 
105  inline double fltBinNumber(const double x,
106  const bool mapLeftEdgeTo0=true) const
107  {
108  return uniform_ ? u_.fltBinNumber(x, mapLeftEdgeTo0) :
109  a_.fltBinNumber(x, mapLeftEdgeTo0);
110  }
111 
113  inline unsigned closestValidBin(const double x) const
114  {return uniform_ ? u_.closestValidBin(x) : a_.closestValidBin(x);}
115 
116  inline bool operator==(const DualHistoAxis& r) const
117  {return uniform_ == r.uniform_ && a_ == r.a_ && u_ == r.u_;}
118 
119  inline bool operator!=(const DualHistoAxis& r) const
120  {return !(*this == r);}
121 
123  inline bool isClose(const DualHistoAxis& r, const double tol) const
124  {
125  return uniform_ == r.uniform_ &&
126  a_.isClose(r.a_, tol) &&
127  u_.isClose(r.u_, tol);
128  }
129 
131  inline DualHistoAxis rebin(const unsigned newBins) const
132  {return DualHistoAxis(newBins, min(), max(), label().c_str());}
133 
135  // Method related to "geners" I/O
136  inline gs::ClassId classId() const {return gs::ClassId(*this);}
137  bool write(std::ostream& of) const;
139 
140  static inline const char* classname() {return "npstat::DualHistoAxis";}
141  static inline unsigned version() {return 1;}
142  static DualHistoAxis* read(const gs::ClassId& id, std::istream& in);
143 
144  private:
147  bool uniform_;
148 
149  template <typename Numeric, class Axis> friend class HistoND;
150 
151  inline unsigned overflowIndex(
152  const double x, unsigned* binNumber) const
153  {
154  return uniform_ ? u_.overflowIndex(x, binNumber) :
155  a_.overflowIndex(x, binNumber);
156  }
157 
158  inline static std::vector<double> dummy_vec()
159  {
160  std::vector<double> vec(2, 0.0);
161  vec[1] = 1.0;
162  return vec;
163  }
164 
165  inline DualHistoAxis()
166  : a_(dummy_vec()), u_(1U, 0.0, 1.0), uniform_(true) {}
167  };
168 }
169 
170 #endif // NPSTAT_DUALHISTOAXIS_HH_
171 
unsigned closestValidBin(double x) const
Definition: NUHistoAxis.cc:150
double leftBinEdge(const int binNum) const
Definition: DualHistoAxis.h:68
int binNumber(const double x) const
Definition: DualHistoAxis.h:98
const std::string & label() const
Definition: DualHistoAxis.h:62
double rightBinEdge(const int binNum) const
Definition: NUHistoAxis.h:56
int binNumber(double x) const
Definition: NUHistoAxis.cc:78
double min() const
Definition: NUHistoAxis.h:39
unsigned overflowIndex(const double x, unsigned *binNum) const
Definition: NUHistoAxis.h:123
void setLabel(const char *newlabel)
Definition: NUHistoAxis.h:69
double fltBinNumber(const double x, const bool mapLeftEdgeTo0=true) const
int binNumber(double x) const
Definition: HistoAxis.cc:51
bool operator==(const DualHistoAxis &r) const
Histogram axis with non-uniform bin spacing.
unsigned nBins() const
Definition: NUHistoAxis.h:44
const std::string & label() const
Definition: HistoAxis.h:49
double binCenter(const int binNum) const
Definition: DualHistoAxis.h:65
double leftBinEdge(const int binNum) const
Definition: HistoAxis.h:58
bool write(std::ostream &of) const
Definition: DualHistoAxis.cc:8
void setLabel(const char *newlabel)
Definition: HistoAxis.h:70
const HistoAxis * getHistoAxis() const
Definition: DualHistoAxis.h:86
unsigned overflowIndex(const double x, unsigned *binNumber) const
static const char * classname()
double length() const
Definition: DualHistoAxis.h:53
double leftBinEdge(const int binNum) const
Definition: NUHistoAxis.h:52
DualHistoAxis rebin(const unsigned newBins) const
unsigned nBins() const
Definition: HistoAxis.h:47
bool isClose(const HistoAxis &, double tol) const
Definition: HistoAxis.cc:30
double binCenter(const int binNum) const
Definition: NUHistoAxis.h:60
const NUHistoAxis * getNUHistoAxis() const
Definition: DualHistoAxis.h:83
DualHistoAxis(const HistoAxis &u)
Definition: DualHistoAxis.h:30
double min() const
Definition: DualHistoAxis.h:44
static DualHistoAxis * read(const gs::ClassId &id, std::istream &in)
Interval< double > interval() const
Definition: HistoAxis.h:44
bool operator!=(const DualHistoAxis &r) const
double binCenter(const int binNum) const
Definition: HistoAxis.h:54
double max() const
Definition: DualHistoAxis.h:47
bool isUniform() const
Definition: DualHistoAxis.h:42
void setLabel(const char *newlabel)
Definition: DualHistoAxis.h:91
Interval< double > interval() const
Definition: NUHistoAxis.h:41
double binWidth(const int=0) const
Definition: HistoAxis.h:48
double binWidth(const int binNum) const
Definition: DualHistoAxis.h:59
double rightBinEdge(const int binNum) const
Definition: DualHistoAxis.h:71
DualHistoAxis(unsigned nBins, double min, double max, const char *label=0)
Definition: DualHistoAxis.h:37
Interval< double > interval() const
Definition: DualHistoAxis.h:50
Interval< double > binInterval(const int binNum) const
Definition: HistoAxis.h:66
static unsigned version()
bool isClose(const NUHistoAxis &, double tol) const
Definition: NUHistoAxis.cc:49
unsigned nBins() const
Definition: DualHistoAxis.h:56
double fltBinNumber(double x, bool mapLeftEdgeTo0=true) const
Definition: NUHistoAxis.cc:85
double length() const
Definition: HistoAxis.h:46
double a
Definition: hdecay.h:121
double max() const
Definition: HistoAxis.h:43
Interval< double > binInterval(const int binNum) const
Definition: NUHistoAxis.h:64
gs::ClassId classId() const
unsigned overflowIndex(const double x, unsigned *binNumber) const
Definition: HistoAxis.h:140
Interval< double > binInterval(const int binNum) const
Definition: DualHistoAxis.h:74
volatile std::atomic< bool > shutdown_flag false
bool isClose(const DualHistoAxis &r, const double tol) const
double rightBinEdge(const int binNum) const
Definition: HistoAxis.h:62
double binWidth(const int binNum) const
Definition: NUHistoAxis.h:45
unsigned closestValidBin(const double x) const
double fltBinNumber(const double x, const bool mapLeftEdgeTo0=true) const
Definition: HistoAxis.h:99
unsigned closestValidBin(double x) const
Definition: HistoAxis.cc:77
DualHistoAxis(const std::vector< double > &binEdges, const char *label=0)
Definition: DualHistoAxis.h:33
double max() const
Definition: NUHistoAxis.h:40
double length() const
Definition: NUHistoAxis.h:43
Histogram axis with equidistant bins.
double min() const
Definition: HistoAxis.h:42
static std::vector< double > dummy_vec()
const std::string & label() const
Definition: NUHistoAxis.h:47
DualHistoAxis(const NUHistoAxis &a)
Definition: DualHistoAxis.h:27