CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/JetMETCorrections/InterpolationTables/interface/UniformAxis.h

Go to the documentation of this file.
00001 #ifndef NPSTAT_UNIFORMAXIS_HH_
00002 #define NPSTAT_UNIFORMAXIS_HH_
00003 
00015 #include <vector>
00016 #include <utility>
00017 #include <string>
00018 #include <iostream>
00019 
00020 #include "Alignment/Geners/interface/ClassId.hh"
00021 
00022 namespace npstat {
00027     class UniformAxis
00028     {
00029     public:
00030         // The number of coordinates must be at least 2
00031         UniformAxis(unsigned nCoords, double min, double max,
00032                     const char* label=0);
00033 
00034         // Basic accessors
00035         inline unsigned nCoords() const {return npt_;}
00036         inline double min() const {return min_;}
00037         inline double max() const {return max_;}
00038         inline const std::string& label() const {return label_;}
00039         inline bool usesLogSpace() const {return false;}
00040 
00041         // The following function returns the grid interval number and
00042         // the weight of the point at the left side of the interval.
00043         // The weight will be set to 1 if the given coordinate coincides
00044         // with the grid point and will decay to 0 linearly as the
00045         // coordinate moves towards the next point on the right.
00046         //
00047         // The coordinates below the leftmost grid point are mapped
00048         // into the 0th interval with weight 1. The coordinates above
00049         // the rightmost grid point are mapped into the last interval
00050         // with weight 0 for the left point (it is expected that weight 1
00051         // will then be assigned to the right point).
00052         std::pair<unsigned,double> getInterval(double coordinate) const;
00053 
00054         // Similar function which calculates the weights including
00055         // the points outside of the axis boundaries
00056         std::pair<unsigned,double> linearInterval(double coordinate) const;
00057 
00058         // Convenience methods
00059         std::vector<double> coords() const;
00060         double coordinate(unsigned i) const;
00061         inline double length() const {return max_ - min_;}
00062         inline bool isUniform() const {return true;}
00063         inline unsigned nIntervals() const {return npt_ - 1;}
00064         inline double intervalWidth(unsigned) const {return bw_;}
00065 
00066         bool operator==(const UniformAxis& r) const;
00067         inline bool operator!=(const UniformAxis& r) const
00068             {return !(*this == r);}
00069 
00070         // Closeness within tolerance
00071         bool isClose(const UniformAxis& r, double tol) const;
00072 
00073         // Modify the label
00074         inline void setLabel(const char* newlabel)
00075             {label_ = newlabel ? newlabel : "";}
00076 
00077         // Methods related to I/O
00078         inline gs::ClassId classId() const {return gs::ClassId(*this);}
00079         bool write(std::ostream& of) const;
00080 
00081         static inline const char* classname() {return "npstat::UniformAxis";}
00082         static inline unsigned version() {return 1;}
00083         static UniformAxis* read(const gs::ClassId& id, std::istream& in);
00084 
00085     private:
00086         inline UniformAxis() : min_(0.), max_(0.), bw_(0.), npt_(0) {}
00087 
00088         double min_;
00089         double max_;
00090         double bw_;
00091         std::string label_;
00092         unsigned npt_;
00093 
00094     };
00095 }
00096 
00097 #endif // NPSTAT_UNIFORMAXIS_HH_
00098