File indexing completed on 2023-03-17 11:10:41
0001 #ifndef NPSTAT_LINEARMAPPER1D_HH_
0002 #define NPSTAT_LINEARMAPPER1D_HH_
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "JetMETCorrections/InterpolationTables/interface/NpstatException.h"
0015
0016 namespace npstat {
0017
0018 class LinearMapper1d {
0019 public:
0020
0021 inline LinearMapper1d() : a_(1.0), b_(0.0) {}
0022
0023
0024
0025
0026
0027
0028 inline LinearMapper1d(const double x0, const double y0, const double x1, const double y1) {
0029 const double dx = x1 - x0;
0030 if (!dx)
0031 throw npstat::NpstatInvalidArgument(
0032 "In npstat::LinearMapper1d constructor: "
0033 "invalid arguments (x0 == x1)");
0034 a_ = (y1 - y0) / dx;
0035 b_ = ((y0 + y1) - a_ * (x0 + x1)) / 2.0;
0036 }
0037
0038
0039 inline LinearMapper1d(const double ca, const double cb) : a_(ca), b_(cb) {}
0040
0041
0042 inline double operator()(const double& x) const { return a_ * x + b_; }
0043
0044
0045 inline double a() const { return a_; }
0046
0047
0048 inline double b() const { return b_; }
0049
0050
0051 inline LinearMapper1d inverse() const {
0052 if (!a_)
0053 throw npstat::NpstatInvalidArgument(
0054 "In npstat::LinearMapper1d::inverse: "
0055 "mapping is not invertible");
0056 return LinearMapper1d(1.0 / a_, -b_ / a_);
0057 }
0058
0059
0060 inline LinearMapper1d operator*(const LinearMapper1d& r) const { return LinearMapper1d(a_ * r.a_, a_ * r.b_ + b_); }
0061
0062 private:
0063 double a_;
0064 double b_;
0065 };
0066 }
0067
0068 #endif