CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/JetMETCorrections/InterpolationTables/interface/HistoAxis.h

Go to the documentation of this file.
00001 #ifndef NPSTAT_HISTOAXIS_HH_
00002 #define NPSTAT_HISTOAXIS_HH_
00003 
00014 #include <utility>
00015 
00016 #include "Alignment/Geners/interface/ClassId.hh"
00017 
00018 #include "JetMETCorrections/InterpolationTables/interface/CircularMapper1d.h"
00019 #include "JetMETCorrections/InterpolationTables/interface/Interval.h"
00020 
00021 namespace npstat {
00022     template <typename Numeric, class Axis> class HistoND;
00023     class DualHistoAxis;
00024 
00030     class HistoAxis
00031     {
00032     public:
00037         HistoAxis(unsigned nBins, double min, double max,
00038                   const char* label=0);
00039 
00041 
00042         inline double min() const {return min_;}
00043         inline double max() const {return max_;}
00044         inline Interval<double> interval() const
00045             {return Interval<double>(min_, max_);}
00046         inline double length() const {return max_ - min_;}
00047         inline unsigned nBins() const {return nBins_;}
00048         inline double binWidth(const int /*binNum*/=0) const {return bw_;}
00049         inline const std::string& label() const {return label_;}
00050         inline bool isUniform() const {return true;}
00052 
00054         inline double binCenter(const int binNum) const
00055             {return min_ + (binNum + 0.5)*bw_;}
00056 
00058         inline double leftBinEdge(const int binNum) const
00059             {return min_ + binNum*bw_;}
00060 
00062         inline double rightBinEdge(const int binNum) const
00063             {return min_ + (binNum + 1)*bw_;}
00064 
00066         inline Interval<double> binInterval(const int binNum) const
00067             {return Interval<double>(min_+binNum*bw_, min_+(binNum+1)*bw_);}
00068 
00070         inline void setLabel(const char* newlabel)
00071             {label_ = newlabel ? newlabel : "";}
00072 
00077         int binNumber(double x) const;
00078 
00083         unsigned closestValidBin(double x) const;
00084 
00092         LinearMapper1d binNumberMapper(bool mapLeftEdgeTo0=true) const;
00093 
00099         inline double fltBinNumber(const double x,
00100                                    const bool mapLeftEdgeTo0=true) const
00101             {return (x - min_)/bw_ - (mapLeftEdgeTo0 ? 0.0 : 0.5);}
00102 
00109         CircularMapper1d kernelScanMapper(bool doubleRange) const;
00110 
00111         bool operator==(const HistoAxis&) const;
00112         bool operator!=(const HistoAxis&) const;
00113 
00115         bool isClose(const HistoAxis&, double tol) const;
00116 
00118 
00119         inline gs::ClassId classId() const {return gs::ClassId(*this);}
00120         bool write(std::ostream& of) const;
00122 
00123         static inline const char* classname() {return "npstat::HistoAxis";}
00124         static inline unsigned version() {return 1;}
00125         static HistoAxis* read(const gs::ClassId& id, std::istream& in);
00126 
00127     private:
00128         inline HistoAxis() : min_(0.0), max_(0.0), bw_(0.0), nBins_(0) {}
00129 
00130         double min_;
00131         double max_;
00132         double bw_;
00133         std::string label_;
00134         unsigned nBins_;
00135 
00136         template <typename Numeric, class Axis> friend class HistoND;
00137         friend class DualHistoAxis;
00138 
00139         inline unsigned overflowIndex(
00140             const double x, unsigned* binNumber) const
00141         {
00142             if (x < min_)
00143                 return 0U;
00144             else if (x >= max_)
00145                 return 2U;
00146             else
00147             {
00148                 const unsigned bin = static_cast<unsigned>((x - min_)/bw_);
00149                 *binNumber = bin >= nBins_ ? nBins_ - 1U : bin;
00150                 return 1U;
00151             }
00152         }
00153 
00154         unsigned overflowIndexWeighted(double x, unsigned* binNumber,
00155                                        double *weight) const;
00156     };
00157 }
00158 
00159 #endif // NPSTAT_HISTOAXIS_HH_
00160