npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
CircularMapper1d.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_CIRCULARMAPPER1D_HH_
2 #define NPSTAT_CIRCULARMAPPER1D_HH_
3 
4 /*!
5 // \file CircularMapper1d.hh
6 //
7 // \brief Linear transformation for circular topology
8 //
9 // Author: I. Volobouev
10 //
11 // June 2012
12 */
13 
14 #include <cmath>
15 
17 
18 namespace npstat {
19  /**
20  // 1-d linear transformation functor followed by the shift of
21  // the result into the interval [-T/2, T/2], where T is the period
22  */
24  {
25  public:
26  inline CircularMapper1d() : a_(1.0), b_(0.0), period_(2.0*M_PI) {}
27 
28  inline CircularMapper1d(const double ca, const double cb,
29  const double cperiod)
30  : a_(ca), b_(cb), period_(std::abs(cperiod)) {check();}
31 
32  inline CircularMapper1d(const LinearMapper1d& mapper,
33  const double cperiod)
34  : a_(mapper.a()), b_(mapper.b()),
35  period_(std::abs(cperiod)) {check();}
36 
37  inline double operator()(const double& x) const
38  {
39  double value = a_*x + b_;
40  value -= period_*floor(value/period_);
41  if (value > period_/2.0)
42  value -= period_;
43  return value;
44  }
45 
46  inline double a() const {return a_;}
47  inline double b() const {return b_;}
48  inline double period() const {return period_;}
49  inline LinearMapper1d linearMapper() const
50  {return LinearMapper1d(a_, b_);}
51 
52  private:
53  inline void check()
54  {
55  if (!period_) throw std::invalid_argument(
56  "In npstat::CircularMapper1d constructor: "
57  "invalid period argument (can not be 0)");
58  }
59 
60  double a_;
61  double b_;
62  double period_;
63  };
64 }
65 
66 #endif // NPSTAT_CIRCULARMAPPER1D_HH_
Linear transformation functor.
Definition: CircularMapper1d.hh:24
Definition: LinearMapper1d.hh:20
Numeric a() const
Definition: LinearMapper1d.hh:49
Numeric b() const
Definition: LinearMapper1d.hh:52
Definition: AbsArrayProjector.hh:14
LinearMapper1dTmpl< double > LinearMapper1d
Definition: LinearMapper1d.hh:75