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));
106 namespace fftjetcms {
107 template <
typename RealN>
112 const bool leftExtrapolationLinear,
113 const bool rightExtrapolationLinear)
114 : data_(data, data + npoints),
117 binwidth_((x_max - x_min) / (npoints - 1U)),
119 leftExtrapolationLinear_(leftExtrapolationLinear),
120 rightExtrapolationLinear_(rightExtrapolationLinear),
122 monotonicityKnown_(
false) {
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>
132 const bool leftExtrapolationLinear,
133 const bool rightExtrapolationLinear)
136 binwidth_((xmax_ - xmin_) / (npoints - 1U)),
138 leftExtrapolationLinear_(leftExtrapolationLinear),
139 rightExtrapolationLinear_(rightExtrapolationLinear),
141 monotonicityKnown_(
false) {
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 - 2U].first, vdata[len - 1U].first, vdata[len - 2U].
second, vdata[len - 1U].second,
xmax_);
176 data_[npoints - 1U +
shift] = vdata[len - 1U].second;
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_
const edm::EventSetup & c
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)
bool rightExtrapolationLinear_
std::unique_ptr< LinInterpolatedTable1D > inverse(unsigned npoints, bool leftExtrapolationLinear, bool rightExtrapolationLinear) const
double operator()(const double &x) const override
bool rightExtrapolationLinear() const
char data[epos_bytes_allocation]
~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)
tuple size
Write out results.
bool leftExtrapolationLinear_