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 virtual double operator()(
const double& x)
const;
58 {
return !(*
this ==
r);}
68 inline const double*
data()
const {
return &
data_[0];}
85 std::auto_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));
112 namespace fftjetcms {
113 template <
typename RealN>
116 const double x_min,
const double x_max,
117 const bool leftExtrapolationLinear,
118 const bool rightExtrapolationLinear)
119 : data_(data, data+npoints),
122 binwidth_((x_max - x_min)/(npoints - 1U)),
124 leftExtrapolationLinear_(leftExtrapolationLinear),
125 rightExtrapolationLinear_(rightExtrapolationLinear),
127 monotonicityKnown_(
false)
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,
141 const bool leftExtrapolationLinear,
142 const bool rightExtrapolationLinear)
145 binwidth_((xmax_ - xmin_)/(npoints - 1U)),
147 leftExtrapolationLinear_(leftExtrapolationLinear),
148 rightExtrapolationLinear_(rightExtrapolationLinear),
150 monotonicityKnown_(
false)
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 - 2U].first, vdata[len - 1U].first,
195 vdata[len - 2U].
second, vdata[len - 1U].second,
xmax_);
199 data_[npoints - 1U +
shift] = vdata[len - 1U].second;
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
virtual ~LinInterpolatedTable1D()
std::vector< double > data_
bool operator==(const LinInterpolatedTable1D &r) const
bool leftExtrapolationLinear() const
bool isMonotonous() const
U second(std::pair< T, U > const &p)
T x() const
Cartesian x coordinate.
static double interpolateSimple(const double x0, const double x1, const double y0, const double y1, const double x)
bool rightExtrapolationLinear_
virtual double operator()(const double &x) const
bool rightExtrapolationLinear() const
char data[epos_bytes_allocation]
std::auto_ptr< LinInterpolatedTable1D > inverse(unsigned npoints, bool leftExtrapolationLinear, bool rightExtrapolationLinear) const
bool operator!=(const LinInterpolatedTable1D &r) const
static unsigned int const shift
volatile std::atomic< bool > shutdown_flag false
LinInterpolatedTable1D(const RealN *data, unsigned npoints, double x_min, double x_max, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
tuple size
Write out results.
bool leftExtrapolationLinear_