npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
ExpMapper1d.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_EXPMAPPER1D_HH_
2 #define NPSTAT_EXPMAPPER1D_HH_
3 
4 /*!
5 // \file ExpMapper1d.hh
6 //
7 // \brief One-dimensional log-linear transformation functor (log in y)
8 //
9 // Author: I. Volobouev
10 //
11 // January 2014
12 */
13 
14 #include <cmath>
15 #include <stdexcept>
16 
17 namespace npstat {
18  /** Functor which performs log-linear mapping in 1-d (log in y) */
20  {
21  public:
22  /** The default constructor creates a transform y = exp(x) */
23  inline ExpMapper1d() : a_(1.0), b_(0.0) {}
24 
25  /**
26  // The point at x0 is mapped into y0, the point at x1
27  // is mapped into y1. y0 and y1 must be positive.
28  // Points between x0 and x1 are mapped into y in such a way
29  // that the transformation is linear in the log(y) space.
30  */
31  inline ExpMapper1d(const double x0, const double y0,
32  const double x1, const double y1)
33  {
34  if (!(y0 > 0.0 && y1 > 0.0)) throw std::invalid_argument(
35  "In npstat::ExpMapper1d constructor: "
36  "both ordinates must be positive");
37  const double lny1 = log(y1);
38  const double lny0 = log(y0);
39  const double dx = x1 - x0;
40  if (!dx) throw std::invalid_argument(
41  "In npstat::ExpMapper1d constructor: "
42  "invalid arguments (x0 == x1)");
43  a_ = (lny1 - lny0)/dx;
44  b_ = ((lny0 + lny1) - a_*(x0 + x1))/2.0;
45  }
46 
47  /** Explicit constructor for the transform y = exp(ca*x + cb) */
48  inline ExpMapper1d(const double ca, const double cb) : a_(ca), b_(cb) {}
49 
50  /** Perform the transformation */
51  inline double operator()(const double& x) const {return exp(a_*x+b_);}
52 
53  /** Get the linear coefficient of the transform */
54  inline double a() const {return a_;}
55 
56  /** Get the transform constant */
57  inline double b() const {return b_;}
58 
59  private:
60  double a_;
61  double b_;
62  };
63 }
64 
65 #endif // NPSTAT_EXPMAPPER1D_HH_
Definition: ExpMapper1d.hh:20
ExpMapper1d()
Definition: ExpMapper1d.hh:23
double a() const
Definition: ExpMapper1d.hh:54
ExpMapper1d(const double ca, const double cb)
Definition: ExpMapper1d.hh:48
ExpMapper1d(const double x0, const double y0, const double x1, const double y1)
Definition: ExpMapper1d.hh:31
double b() const
Definition: ExpMapper1d.hh:57
double operator()(const double &x) const
Definition: ExpMapper1d.hh:51
Definition: AbsArrayProjector.hh:14