12 #ifndef RecoJets_FFTJetAlgorithms_LinInterpolatedTable1D_h 13 #define RecoJets_FFTJetAlgorithms_LinInterpolatedTable1D_h 20 #include "fftjet/SimpleFunctors.hh" 30 template <
typename RealN>
32 double x_min,
double x_max,
41 template <
typename RealN>
44 bool leftExtrapolationLinear,
45 bool rightExtrapolationLinear);
53 double operator()(
const double& x)
const override;
58 {
return !(*
this ==
r);}
68 inline const double*
data()
const {
return &
data_[0];}
85 std::unique_ptr<LinInterpolatedTable1D>
inverse(
86 unsigned npoints,
bool leftExtrapolationLinear,
87 bool rightExtrapolationLinear)
const;
91 const double x0,
const double x1,
92 const double y0,
const double y1,
95 return y0 + (y1 - y0)*((x - x0)/(x1 - x0));
113 template <
typename RealN>
116 const double x_min,
const double x_max,
119 :
data_(data, data+npoints),
131 <<
"No data configured" << std::endl;
134 <<
"Not enough data points" << std::endl;
137 template <
typename RealN>
139 const std::vector<std::pair<RealN,RealN> >&
v,
152 const unsigned len =
v.size();
155 <<
"Not enough data for interpolation" 160 <<
"Not enough interpolation table entries" 163 const std::pair<RealN,RealN>* vdata = &
v[0];
164 for (
unsigned i=1;
i<len; ++
i)
167 <<
"Input data is not sorted properly" 171 if (leftExtrapolationLinear)
177 if (rightExtrapolationLinear)
185 if (leftExtrapolationLinear)
188 vdata[0].first, vdata[1].first,
191 if (rightExtrapolationLinear)
194 vdata[len - 2
U].first, vdata[len - 1
U].first,
200 unsigned ibelow = 0, iabove = 1;
201 for (
unsigned i=1;
i<npoints-1; ++
i)
204 while (static_cast<double>(
v[iabove].first) <= x)
209 if (
v[ibelow].first ==
v[iabove].first)
210 data_[
i +
shift] = (
v[ibelow].second +
v[iabove].second)/2.0;
213 v[ibelow].first,
v[iabove].first,
214 v[ibelow].
second,
v[iabove].second, x);
219 #endif // RecoJets_FFTJetAlgorithms_LinInterpolatedTable1D_h const double * data() const
std::vector< double > data_
bool operator==(const LinInterpolatedTable1D &r) const
bool leftExtrapolationLinear() const
bool isMonotonous() const
U second(std::pair< T, U > const &p)
static double interpolateSimple(const double x0, const double x1, const double y0, const double y1, const double x)
double operator()(const double &x) const override
bool rightExtrapolationLinear_
std::unique_ptr< LinInterpolatedTable1D > inverse(unsigned npoints, bool leftExtrapolationLinear, bool rightExtrapolationLinear) const
bool rightExtrapolationLinear() const
~LinInterpolatedTable1D() override
bool operator!=(const LinInterpolatedTable1D &r) const
static unsigned int const shift
LinInterpolatedTable1D(const RealN *data, unsigned npoints, double x_min, double x_max, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
bool leftExtrapolationLinear_