CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #ifndef NPSTAT_CIRCULARMAPPER1D_HH_
00002 #define NPSTAT_CIRCULARMAPPER1D_HH_
00003 
00014 #include <cmath>
00015 
00016 #include "JetMETCorrections/InterpolationTables/interface/LinearMapper1d.h"
00017 
00018 namespace npstat {
00023     class CircularMapper1d
00024     {
00025     public:
00026         inline CircularMapper1d() : a_(1.0), b_(0.0), period_(2.0*M_PI) {}
00027 
00028         inline CircularMapper1d(const double ca, const double cb,
00029                                 const double cperiod)
00030             : a_(ca), b_(cb), period_(std::abs(cperiod)) {check();}
00031 
00032         inline CircularMapper1d(const LinearMapper1d& mapper,
00033                                 const double cperiod)
00034             : a_(mapper.a()), b_(mapper.b()),
00035               period_(std::abs(cperiod)) {check();}
00036 
00037         inline double operator()(const double& x) const
00038         {
00039             double value = a_*x + b_;
00040             value -= period_*floor(value/period_);
00041             if (value > period_/2.0)
00042                 value -= period_;
00043             return value;
00044         }
00045 
00046         inline double a() const {return a_;}
00047         inline double b() const {return b_;}
00048         inline double period() const {return period_;}
00049         inline LinearMapper1d linearMapper() const
00050             {return LinearMapper1d(a_, b_);}
00051 
00052     private:
00053         inline void check()
00054         {
00055             if (!period_) throw npstat::NpstatInvalidArgument(
00056                 "In npstat::CircularMapper1d constructor: "
00057                 "invalid period argument (can not be 0)");
00058         }
00059 
00060         double a_;
00061         double b_;
00062         double period_;
00063     };
00064 }
00065 
00066 #endif // NPSTAT_CIRCULARMAPPER1D_HH_
00067