Go to the documentation of this file.00001 #ifndef NPSTAT_NUHISTOAXIS_HH_
00002 #define NPSTAT_NUHISTOAXIS_HH_
00003
00014 #include <vector>
00015 #include <utility>
00016
00017 #include "Alignment/Geners/interface/ClassId.hh"
00018 #include "JetMETCorrections/InterpolationTables/interface/Interval.h"
00019
00020 namespace npstat {
00021 template <typename Numeric, class Axis> class HistoND;
00022 class DualHistoAxis;
00023
00027 class NUHistoAxis
00028 {
00029 public:
00035 NUHistoAxis(const std::vector<double>& binEdges,
00036 const char* label = 0);
00037
00039
00040 inline double min() const {return min_;}
00041 inline double max() const {return max_;}
00042 inline Interval<double> interval() const
00043 {return Interval<double>(min_, max_);}
00044 inline double length() const {return max_ - min_;}
00045 inline unsigned nBins() const {return nBins_;}
00046 inline double binWidth(const int binNum) const
00047 {return binEdges_.at(binNum+1) - binEdges_.at(binNum);}
00048 inline const std::string& label() const {return label_;}
00049 inline bool isUniform() const {return uniform_;}
00051
00053 inline double leftBinEdge(const int binNum) const
00054 {return binEdges_.at(binNum);}
00055
00057 inline double rightBinEdge(const int binNum) const
00058 {return binEdges_.at(binNum + 1);}
00059
00061 inline double binCenter(const int binNum) const
00062 {return 0.5*(binEdges_.at(binNum) + binEdges_.at(binNum + 1));}
00063
00065 inline Interval<double> binInterval(const int binNum) const
00066 {return Interval<double>(binEdges_.at(binNum),
00067 binEdges_.at(binNum + 1));}
00068
00070 inline void setLabel(const char* newlabel)
00071 {label_ = newlabel ? newlabel : "";}
00072
00077 int binNumber(double x) const;
00078
00083 double fltBinNumber(double x, bool mapLeftEdgeTo0=true) const;
00084
00089 unsigned closestValidBin(double x) const;
00090
00091 bool operator==(const NUHistoAxis&) const;
00092 bool operator!=(const NUHistoAxis&) const;
00093
00095 bool isClose(const NUHistoAxis&, double tol) const;
00096
00098
00099 inline gs::ClassId classId() const {return gs::ClassId(*this);}
00100 bool write(std::ostream& of) const;
00102
00103 static inline const char* classname() {return "npstat::NUHistoAxis";}
00104 static inline unsigned version() {return 1;}
00105 static NUHistoAxis* read(const gs::ClassId& id, std::istream& in);
00106
00107 private:
00108 inline NUHistoAxis() : min_(0.0), max_(0.0),
00109 nBins_(0), uniform_(false) {}
00110
00111 NUHistoAxis(unsigned nBins, double min, double max,
00112 const char* label = 0);
00113
00114 double min_;
00115 double max_;
00116 std::vector<double> binEdges_;
00117 std::string label_;
00118 unsigned nBins_;
00119 bool uniform_;
00120
00121 template <typename Numeric, class Axis> friend class HistoND;
00122 friend class DualHistoAxis;
00123
00124 inline unsigned overflowIndex(
00125 const double x, unsigned* binNum) const
00126 {
00127 if (x < min_)
00128 return 0U;
00129 else if (x >= max_)
00130 return 2U;
00131 else
00132 {
00133 *binNum = binNumber(x);
00134 return 1U;
00135 }
00136 }
00137
00138 };
00139 }
00140
00141 #endif // NPSTAT_NUHISTOAXIS_HH_
00142