CMS 3D CMS Logo

CircularMapper1d.h
Go to the documentation of this file.
1 #ifndef NPSTAT_CIRCULARMAPPER1D_HH_
2 #define NPSTAT_CIRCULARMAPPER1D_HH_
3 
14 #include <cmath>
15 
17 
18 namespace npstat {
24  public:
25  inline CircularMapper1d() : a_(1.0), b_(0.0), period_(2.0 * M_PI) {}
26 
27  inline CircularMapper1d(const double ca, const double cb, const double cperiod)
28  : a_(ca), b_(cb), period_(std::abs(cperiod)) {
29  check();
30  }
31 
32  inline CircularMapper1d(const LinearMapper1d& mapper, const double cperiod)
33  : a_(mapper.a()), b_(mapper.b()), period_(std::abs(cperiod)) {
34  check();
35  }
36 
37  inline double operator()(const double& x) const {
38  double value = a_ * x + b_;
39  value -= period_ * floor(value / period_);
40  if (value > period_ / 2.0)
41  value -= period_;
42  return value;
43  }
44 
45  inline double a() const { return a_; }
46  inline double b() const { return b_; }
47  inline double period() const { return period_; }
48  inline LinearMapper1d linearMapper() const { return LinearMapper1d(a_, b_); }
49 
50  private:
51  inline void check() {
52  if (!period_)
54  "In npstat::CircularMapper1d constructor: "
55  "invalid period argument (can not be 0)");
56  }
57 
58  double a_;
59  double b_;
60  double period_;
61  };
62 } // namespace npstat
63 
64 #endif // NPSTAT_CIRCULARMAPPER1D_HH_
CircularMapper1d(const double ca, const double cb, const double cperiod)
Linear transformation functor.
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: value.py:1
#define M_PI
float x
CircularMapper1d(const LinearMapper1d &mapper, const double cperiod)
LinearMapper1d linearMapper() const
double operator()(const double &x) const