CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/JetMETCorrections/InterpolationTables/interface/GridAxis.h

Go to the documentation of this file.
00001 #ifndef NPSTAT_GRIDAXIS_HH_
00002 #define NPSTAT_GRIDAXIS_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 {
00030     class GridAxis
00031     {
00032     public:
00034 
00038         GridAxis(const std::vector<double>& coords, bool useLogSpace=false);
00039         GridAxis(const std::vector<double>& coords, const char* label,
00040                  bool useLogSpace=false);
00042 
00044 
00045         inline const std::vector<double>& coords() const {return coords_;}
00046         inline const std::string& label() const {return label_;}
00047         inline bool usesLogSpace() const {return useLogSpace_;}
00049 
00063         std::pair<unsigned,double> getInterval(double coordinate) const;
00064 
00079         std::pair<unsigned,double> linearInterval(double coordinate) const;
00080 
00082 
00083         inline unsigned nCoords() const {return npt_;}
00084         inline double coordinate(const unsigned i) const
00085             {return coords_.at(i);}
00086         inline double min() const {return coords_.front();}
00087         inline double max() const {return coords_.back();}
00088         inline double length() const {return coords_.back() - coords_.front();}
00089         inline bool isUniform() const {return false;}
00090         inline unsigned nIntervals() const {return coords_.size() - 1;}
00091         inline double intervalWidth(const unsigned i=0) const
00092             {return coords_.at(i+1) - coords_.at(i);}
00094 
00096         bool operator==(const GridAxis& r) const;
00097 
00099         inline bool operator!=(const GridAxis& r) const
00100             {return !(*this == r);}
00101 
00106         bool isClose(const GridAxis& r, double tol) const;
00107 
00109         inline void setLabel(const char* newlabel)
00110             {label_ = newlabel ? newlabel : "";}
00111 
00113 
00114         inline gs::ClassId classId() const {return gs::ClassId(*this);}
00115         bool write(std::ostream& of) const;
00117 
00118         static inline const char* classname() {return "npstat::GridAxis";}
00119         static inline unsigned version() {return 2;}
00120         static GridAxis* read(const gs::ClassId& id, std::istream& in);
00121 
00122     private:
00123         inline GridAxis() : npt_(0), useLogSpace_(false) {}
00124 
00125         void initialize();
00126 
00127         std::vector<double> coords_;
00128         std::vector<double> logs_;
00129         std::string label_;
00130         unsigned npt_;
00131         bool useLogSpace_;
00132 
00133     };
00134 }
00135 
00136 #endif // NPSTAT_GRIDAXIS_HH_
00137