CMS 3D CMS Logo

interpolate.h
Go to the documentation of this file.
1 #ifndef NPSTAT_INTERPOLATE_HH_
2 #define NPSTAT_INTERPOLATE_HH_
3 
16 
17 namespace npstat {
22  template <typename T>
23  inline T interpolate_linear(const double x, const T& f0, const T& f1) {
24  const typename ProperDblFromCmpl<T>::type dx = 1.0 - x;
25  return f0 * dx + f1 * static_cast<typename ProperDblFromCmpl<T>::type>(x);
26  }
27 
32  template <typename T>
33  inline T interpolate_quadratic(const double x, const T& f0, const T& f1, const T& f2) {
34  static const typename ProperDblFromCmpl<T>::type two = 2.0;
35  const typename ProperDblFromCmpl<T>::type dx = x - 1.0;
36  return f1 + ((f2 - f0) / two + ((f2 - f1) + (f0 - f1)) * (dx / two)) * dx;
37  }
38 
43  template <typename T>
44  inline T interpolate_cubic(const double x, const T& f0, const T& f1, const T& f2, const T& f3) {
45  return interpolate_linear(
46  x * (3.0 - x) / 2.0, interpolate_linear(x / 3.0, f0, f3), interpolate_linear(x - 1.0, f1, f2));
47  }
48 
50 
60  template <typename T>
61  unsigned interpolation_coefficients(T* buffer, unsigned bufLen, const T& f0, const T& f1);
62  template <typename T>
63  unsigned interpolation_coefficients(T* buffer, unsigned bufLen, const T& f0, const T& f1, const T& f2);
64  template <typename T>
65  unsigned interpolation_coefficients(T* buffer, unsigned bufLen, const T& f0, const T& f1, const T& f2, const T& f3);
67 } // namespace npstat
68 
70 
71 namespace npstat {
72  template <typename T>
73  unsigned interpolation_coefficients(T* buffer, const unsigned bufLen, const T& f0, const T& f1) {
74  if (bufLen <= 1U)
76  "In npstat::interpolation_coefficients: "
77  "insufficient length of the output buffer");
78  buffer[0] = f0;
79  buffer[1] = f1 - f0;
80  return 2U;
81  }
82 
83  template <typename T>
84  unsigned interpolation_coefficients(T* buffer, const unsigned bufLen, const T& f0, const T& f1, const T& f2) {
85  if (bufLen <= 2U)
87  "In npstat::interpolation_coefficients: "
88  "insufficient length of the output buffer");
89  buffer[0] = f0;
90  buffer[1] = static_cast<T>((f1 - f2 + 3 * (f1 - f0)) / 2.0);
91  buffer[2] = static_cast<T>(((f0 - f1) + (f2 - f1)) / 2.0);
92  return 3U;
93  }
94 
95  template <typename T>
97  T* buffer, const unsigned bufLen, const T& f0, const T& f1, const T& f2, const T& f3) {
98  if (bufLen <= 3U)
100  "In npstat::interpolation_coefficients: "
101  "insufficient length of the output buffer");
102  buffer[0] = f0;
103  buffer[1] = static_cast<T>((11 * (f1 - f0) + 7 * (f1 - f2) + 2 * (f3 - f2)) / 6.0);
104  buffer[2] = static_cast<T>((2 * (f0 - f1) + 3 * (f2 - f1) + (f2 - f3)) / 2.0);
105  buffer[3] = static_cast<T>(((f3 - f0) + 3 * (f1 - f2)) / 6.0);
106  return 4U;
107  }
108 } // namespace npstat
109 
110 #endif // NPSTAT_INTERPOLATE_HH_
npstat::interpolate_cubic
T interpolate_cubic(const double x, const T &f0, const T &f1, const T &f2, const T &f3)
Definition: interpolate.h:44
ProperDblFromCmpl.h
Compile-time deduction of the underlying floating point type from the given complex type.
npstat::interpolation_coefficients
unsigned interpolation_coefficients(T *buffer, unsigned bufLen, const T &f0, const T &f1)
Definition: interpolate.h:73
npstat::interpolate_quadratic
T interpolate_quadratic(const double x, const T &f0, const T &f1, const T &f2)
Definition: interpolate.h:33
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
npstat
Definition: AbsArrayProjector.h:14
npstat::NpstatInvalidArgument
Definition: NpstatException.h:38
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
DeadROC_duringRun.f2
f2
Definition: DeadROC_duringRun.py:220
npstat::ProperDblFromCmpl::type
double type
Definition: ProperDblFromCmpl.h:20
SiPixelPI::two
Definition: SiPixelPayloadInspectorHelper.h:39
T
long double T
Definition: Basic3DVectorLD.h:48
npstat::interpolate_linear
T interpolate_linear(const double x, const T &f0, const T &f1)
Definition: interpolate.h:23
NpstatException.h
Exceptions for the npstat namespace.
DeadROC_duringRun.f1
f1
Definition: DeadROC_duringRun.py:219
PVValHelper::dx
Definition: PVValidationHelpers.h:48