test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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  {
20  public:
22  inline LinearMapper1d() : a_(1.0), b_(0.0) {}
23 
29  inline LinearMapper1d(const double x0, const double y0,
30  const double x1, const double y1)
31  {
32  const double dx = x1 - x0;
33  if (!dx) throw npstat::NpstatInvalidArgument(
34  "In npstat::LinearMapper1d constructor: "
35  "invalid arguments (x0 == x1)");
36  a_ = (y1 - y0)/dx;
37  b_ = ((y0 + y1) - a_*(x0 + x1))/2.0;
38  }
39 
41  inline LinearMapper1d(const double ca, const double cb)
42  : a_(ca), b_(cb) {}
43 
45  inline double operator()(const double& x) const {return a_*x + b_;}
46 
48  inline double a() const {return a_;}
49 
51  inline double b() const {return b_;}
52 
54  inline LinearMapper1d inverse() const
55  {
57  "In npstat::LinearMapper1d::inverse: "
58  "mapping is not invertible");
59  return LinearMapper1d(1.0/a_, -b_/a_);
60  }
61 
64  {
65  return LinearMapper1d(a_*r.a_, a_*r.b_ + b_);
66  }
67 
68  private:
69  double a_;
70  double b_;
71  };
72 }
73 
74 #endif // NPSTAT_LINEARMAPPER1D_HH_
75 
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)
Definition: DDAxes.h:10
LinearMapper1d(const double x0, const double y0, const double x1, const double y1)