CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #ifndef NPSTAT_LINEARMAPPER1D_HH_
00002 #define NPSTAT_LINEARMAPPER1D_HH_
00003 
00014 #include "JetMETCorrections/InterpolationTables/interface/NpstatException.h"
00015 
00016 namespace npstat {
00018     class LinearMapper1d
00019     {
00020     public:
00022         inline LinearMapper1d() : a_(1.0), b_(0.0) {}
00023 
00029         inline LinearMapper1d(const double x0, const double y0,
00030                               const double x1, const double y1)
00031         {
00032             const double dx = x1 - x0;
00033             if (!dx) throw npstat::NpstatInvalidArgument(
00034                 "In npstat::LinearMapper1d constructor: "
00035                 "invalid arguments (x0 == x1)");
00036             a_ = (y1 - y0)/dx;
00037             b_ = ((y0 + y1) - a_*(x0 + x1))/2.0;
00038         }
00039 
00041         inline LinearMapper1d(const double ca, const double cb)
00042             : a_(ca), b_(cb) {}
00043 
00045         inline double operator()(const double& x) const {return a_*x + b_;}
00046 
00048         inline double a() const {return a_;}
00049 
00051         inline double b() const {return b_;}
00052 
00054         inline LinearMapper1d inverse() const
00055         {
00056             if (!a_) throw npstat::NpstatInvalidArgument(
00057                 "In npstat::LinearMapper1d::inverse: "
00058                 "mapping is not invertible");
00059             return LinearMapper1d(1.0/a_, -b_/a_);
00060         }
00061 
00063         inline LinearMapper1d operator*(const LinearMapper1d& r) const
00064         {
00065             return LinearMapper1d(a_*r.a_, a_*r.b_ + b_);
00066         }
00067 
00068     private:
00069         double a_;
00070         double b_;
00071     };
00072 }
00073 
00074 #endif // NPSTAT_LINEARMAPPER1D_HH_
00075