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