12 #ifndef RecoJets_FFTJetAlgorithms_LinInterpolatedTable1D_h 13 #define RecoJets_FFTJetAlgorithms_LinInterpolatedTable1D_h 20 #include "fftjet/SimpleFunctors.hh" 29 template <
typename RealN>
42 template <
typename RealN>
45 bool leftExtrapolationLinear,
46 bool rightExtrapolationLinear);
54 double operator()(
const double& x)
const override;
66 inline const double*
data()
const {
return &
data_[0]; }
83 std::unique_ptr<LinInterpolatedTable1D>
inverse(
unsigned npoints,
84 bool leftExtrapolationLinear,
85 bool rightExtrapolationLinear)
const;
89 const double x0,
const double x1,
const double y0,
const double y1,
const double x) {
90 return y0 + (y1 - y0) * ((x - x0) / (x1 - x0));
107 template <
typename RealN>
114 :
data_(data, data + npoints),
124 throw cms::Exception(
"FFTJetBadConfig") <<
"No data configured" << std::endl;
126 throw cms::Exception(
"FFTJetBadConfig") <<
"Not enough data points" << std::endl;
129 template <
typename RealN>
142 const unsigned len =
v.size();
144 throw cms::Exception(
"FFTJetBadConfig") <<
"Not enough data for interpolation" << std::endl;
147 throw cms::Exception(
"FFTJetBadConfig") <<
"Not enough interpolation table entries" << std::endl;
149 const std::pair<RealN, RealN>* vdata = &
v[0];
150 for (
unsigned i = 1;
i < len; ++
i)
152 throw cms::Exception(
"FFTJetBadConfig") <<
"Input data is not sorted properly" << std::endl;
155 if (leftExtrapolationLinear) {
160 if (rightExtrapolationLinear) {
167 if (leftExtrapolationLinear) {
170 if (rightExtrapolationLinear) {
172 vdata[len - 2
U].first, vdata[len - 1
U].first, vdata[len - 2
U].
second, vdata[len - 1
U].second,
xmax_);
177 unsigned ibelow = 0, iabove = 1;
178 for (
unsigned i = 1;
i < npoints - 1; ++
i) {
180 while (static_cast<double>(
v[iabove].first) <= x) {
184 if (
v[ibelow].first ==
v[iabove].first)
185 data_[
i +
shift] = (
v[ibelow].second +
v[iabove].second) / 2.0;
192 #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_