CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #ifndef NPSTAT_DUALAXIS_HH_
00002 #define NPSTAT_DUALAXIS_HH_
00003 
00015 #include "JetMETCorrections/InterpolationTables/interface/GridAxis.h"
00016 #include "JetMETCorrections/InterpolationTables/interface/UniformAxis.h"
00017 
00018 namespace npstat {
00024     class DualAxis
00025     {
00026     public:
00027         // Constructors
00028         inline DualAxis(const GridAxis& g)
00029             : a_(g), u_(2, 0.0, 1.0), uniform_(false) {}
00030 
00031         inline DualAxis(const UniformAxis& u)
00032             : a_(dummy_vec()), u_(u), uniform_(true) {}
00033 
00034         inline DualAxis(unsigned nCoords, double min, double max,
00035                         const char* label=0)
00036             : a_(dummy_vec()), u_(nCoords, min, max, label), uniform_(true) {}
00037 
00038         inline DualAxis(const std::vector<double>& coords,
00039                         const bool useLogSpace=false)
00040             : a_(coords, useLogSpace), u_(2, 0.0, 1.0), uniform_(false) {}
00041 
00042         inline DualAxis(const std::vector<double>& coords, const char* label,
00043                         const bool useLogSpace=false)
00044             : a_(coords, label, useLogSpace), u_(2,0.0,1.0), uniform_(false) {}
00045 
00046         // Inspectors
00047         inline bool isUniform() const {return uniform_;}
00048 
00049         inline unsigned nCoords() const
00050             {return uniform_ ? u_.nCoords() : a_.nCoords();}
00051 
00052         inline double min() const
00053             {return uniform_ ? u_.min() : a_.min();}
00054 
00055         inline double max() const
00056             {return uniform_ ? u_.max() : a_.max();}
00057 
00058         inline const std::string& label() const
00059             {return uniform_ ? u_.label() : a_.label();}
00060 
00061         inline bool usesLogSpace() const
00062             {return uniform_ ? u_.usesLogSpace() : a_.usesLogSpace();}
00063 
00064         inline std::pair<unsigned,double> getInterval(const double x) const
00065             {return uniform_ ? u_.getInterval(x) : a_.getInterval(x);}
00066 
00067         inline std::pair<unsigned,double> linearInterval(const double x) const
00068             {return uniform_ ? u_.linearInterval(x) : a_.linearInterval(x);}
00069 
00070         inline double coordinate(const unsigned i) const
00071             {return uniform_ ? u_.coordinate(i) : a_.coordinate(i);}
00072 
00073         inline double length() const
00074             {return uniform_ ? u_.length() : a_.length();}
00075 
00076         inline unsigned nIntervals() const
00077             {return uniform_ ? u_.nIntervals() : a_.nIntervals();}
00078 
00079         inline double intervalWidth(const unsigned i=0) const
00080             {return uniform_ ? u_.intervalWidth(i) : a_.intervalWidth(i);}
00081 
00082         inline std::vector<double> coords() const
00083             {return uniform_ ? u_.coords() : a_.coords();}
00084 
00085         inline bool operator==(const DualAxis& r) const
00086             {return uniform_ == r.uniform_ && a_ == r.a_ && u_ == r.u_;}
00087 
00088         inline bool operator!=(const DualAxis& r) const
00089             {return !(*this == r);}
00090 
00092 
00097         inline const GridAxis* getGridAxis() const
00098             {return uniform_ ? static_cast<const GridAxis*>(0) : &a_;}
00099 
00100         inline const UniformAxis* getUniformAxis() const
00101             {return uniform_ ? &u_ : static_cast<const UniformAxis*>(0);}
00103 
00105         inline void setLabel(const char* newlabel)
00106             {uniform_ ? u_.setLabel(newlabel) : a_.setLabel(newlabel);}
00107 
00109 
00110         inline gs::ClassId classId() const {return gs::ClassId(*this);}
00111         bool write(std::ostream& of) const;
00113 
00114         static inline const char* classname() {return "npstat::DualAxis";}
00115         static inline unsigned version() {return 1;}
00116         static DualAxis* read(const gs::ClassId& id, std::istream& in);
00117 
00118     private:
00119         inline DualAxis()
00120             : a_(dummy_vec()), u_(2, 0.0, 1.0), uniform_(true) {}
00121 
00122         GridAxis a_;
00123         UniformAxis u_;
00124         bool uniform_;
00125 
00126         inline static std::vector<double> dummy_vec()
00127         {
00128             std::vector<double> vec(2, 0.0);
00129             vec[1] = 1.0;
00130             return vec;
00131         }
00132 
00133     };
00134 }
00135 
00136 #endif // NPSTAT_DUALAXIS_HH_
00137