CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
LinearMapper1d.h
Go to the documentation of this file.
1 #ifndef NPSTAT_LINEARMAPPER1D_HH_
2 #define NPSTAT_LINEARMAPPER1D_HH_
3 
15 
16 namespace npstat {
19  public:
21  inline LinearMapper1d() : a_(1.0), b_(0.0) {}
22 
28  inline LinearMapper1d(const double x0, const double y0, const double x1, const double y1) {
29  const double dx = x1 - x0;
30  if (!dx)
32  "In npstat::LinearMapper1d constructor: "
33  "invalid arguments (x0 == x1)");
34  a_ = (y1 - y0) / dx;
35  b_ = ((y0 + y1) - a_ * (x0 + x1)) / 2.0;
36  }
37 
39  inline LinearMapper1d(const double ca, const double cb) : a_(ca), b_(cb) {}
40 
42  inline double operator()(const double& x) const { return a_ * x + b_; }
43 
45  inline double a() const { return a_; }
46 
48  inline double b() const { return b_; }
49 
51  inline LinearMapper1d inverse() const {
52  if (!a_)
54  "In npstat::LinearMapper1d::inverse: "
55  "mapping is not invertible");
56  return LinearMapper1d(1.0 / a_, -b_ / a_);
57  }
58 
60  inline LinearMapper1d operator*(const LinearMapper1d& r) const { return LinearMapper1d(a_ * r.a_, a_ * r.b_ + b_); }
61 
62  private:
63  double a_;
64  double b_;
65  };
66 } // namespace npstat
67 
68 #endif // NPSTAT_LINEARMAPPER1D_HH_
double operator()(const double &x) const
LinearMapper1d operator*(const LinearMapper1d &r) const
LinearMapper1d inverse() const
Exceptions for the npstat namespace.
LinearMapper1d(const double ca, const double cb)
LinearMapper1d(const double x0, const double y0, const double x1, const double y1)