File indexing completed on 2023-03-17 11:10:42
0001 #ifndef NPSTAT_NUHISTOAXIS_HH_
0002 #define NPSTAT_NUHISTOAXIS_HH_
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <vector>
0015 #include <utility>
0016
0017 #include "Alignment/Geners/interface/ClassId.hh"
0018 #include "JetMETCorrections/InterpolationTables/interface/Interval.h"
0019
0020 namespace npstat {
0021 template <typename Numeric, class Axis>
0022 class HistoND;
0023 class DualHistoAxis;
0024
0025
0026
0027
0028 class NUHistoAxis {
0029 public:
0030
0031
0032
0033
0034
0035 NUHistoAxis(const std::vector<double>& binEdges, const char* label = nullptr);
0036
0037
0038
0039 inline double min() const { return min_; }
0040 inline double max() const { return max_; }
0041 inline Interval<double> interval() const { return Interval<double>(min_, max_); }
0042 inline double length() const { return max_ - min_; }
0043 inline unsigned nBins() const { return nBins_; }
0044 inline double binWidth(const int binNum) const { return binEdges_.at(binNum + 1) - binEdges_.at(binNum); }
0045 inline const std::string& label() const { return label_; }
0046 inline bool isUniform() const { return uniform_; }
0047
0048
0049
0050 inline double leftBinEdge(const int binNum) const { return binEdges_.at(binNum); }
0051
0052
0053 inline double rightBinEdge(const int binNum) const { return binEdges_.at(binNum + 1); }
0054
0055
0056 inline double binCenter(const int binNum) const { return 0.5 * (binEdges_.at(binNum) + binEdges_.at(binNum + 1)); }
0057
0058
0059 inline Interval<double> binInterval(const int binNum) const {
0060 return Interval<double>(binEdges_.at(binNum), binEdges_.at(binNum + 1));
0061 }
0062
0063
0064 inline void setLabel(const char* newlabel) { label_ = newlabel ? newlabel : ""; }
0065
0066
0067
0068
0069
0070 int binNumber(double x) const;
0071
0072
0073
0074
0075
0076 double fltBinNumber(double x, bool mapLeftEdgeTo0 = true) const;
0077
0078
0079
0080
0081
0082 unsigned closestValidBin(double x) const;
0083
0084 bool operator==(const NUHistoAxis&) const;
0085 bool operator!=(const NUHistoAxis&) const;
0086
0087
0088 bool isClose(const NUHistoAxis&, double tol) const;
0089
0090
0091 NUHistoAxis rebin(unsigned newBins) const;
0092
0093
0094
0095 inline gs::ClassId classId() const { return gs::ClassId(*this); }
0096 bool write(std::ostream& of) const;
0097
0098
0099 static inline const char* classname() { return "npstat::NUHistoAxis"; }
0100 static inline unsigned version() { return 1; }
0101 static NUHistoAxis* read(const gs::ClassId& id, std::istream& in);
0102
0103 private:
0104 NUHistoAxis(unsigned nBins, double min, double max, const char* label = nullptr);
0105
0106 double min_;
0107 double max_;
0108 std::vector<double> binEdges_;
0109 std::string label_;
0110 unsigned nBins_;
0111 bool uniform_;
0112
0113 template <typename Numeric, class Axis>
0114 friend class HistoND;
0115 friend class DualHistoAxis;
0116
0117 inline unsigned overflowIndex(const double x, unsigned* binNum) const {
0118 if (x < min_)
0119 return 0U;
0120 else if (x >= max_)
0121 return 2U;
0122 else {
0123 *binNum = binNumber(x);
0124 return 1U;
0125 }
0126 }
0127
0128 inline NUHistoAxis() : min_(0.0), max_(0.0), nBins_(0), uniform_(false) {}
0129 };
0130 }
0131
0132 #endif