CMS 3D CMS Logo

List of all members | Public Member Functions | Static Private Member Functions | Private Attributes
fftjetcms::LinInterpolatedTable1D Class Reference

#include <LinInterpolatedTable1D.h>

Inheritance diagram for fftjetcms::LinInterpolatedTable1D:

Public Member Functions

const double * data () const
 
std::unique_ptr< LinInterpolatedTable1Dinverse (unsigned npoints, bool leftExtrapolationLinear, bool rightExtrapolationLinear) const
 
bool isMonotonous () const
 
bool leftExtrapolationLinear () const
 
template<typename RealN >
 LinInterpolatedTable1D (const RealN *data, unsigned npoints, double x_min, double x_max, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
 
template<typename RealN >
 LinInterpolatedTable1D (const std::vector< std::pair< RealN, RealN > > &v, unsigned npoints, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
 
 LinInterpolatedTable1D (double c)
 
unsigned npoints () const
 
bool operator!= (const LinInterpolatedTable1D &r) const
 
double operator() (const double &x) const override
 
bool operator== (const LinInterpolatedTable1D &r) const
 
bool rightExtrapolationLinear () const
 
double xmax () const
 
double xmin () const
 
 ~LinInterpolatedTable1D () override
 

Static Private Member Functions

static double interpolateSimple (const double x0, const double x1, const double y0, const double y1, const double x)
 

Private Attributes

double binwidth_
 
std::vector< double > data_
 
bool leftExtrapolationLinear_
 
bool monotonicityKnown_
 
bool monotonous_
 
unsigned npoints_
 
bool rightExtrapolationLinear_
 
double xmax_
 
double xmin_
 

Detailed Description

Definition at line 24 of file LinInterpolatedTable1D.h.

Constructor & Destructor Documentation

template<typename RealN >
fftjetcms::LinInterpolatedTable1D::LinInterpolatedTable1D ( const RealN *  data,
unsigned  npoints,
double  x_min,
double  x_max,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
)
inline

Definition at line 108 of file LinInterpolatedTable1D.h.

References Exception, and mitigatedMETSequence_cff::U.

Referenced by inverse().

114  : data_(data, data + npoints),
115  xmin_(x_min),
116  xmax_(x_max),
117  binwidth_((x_max - x_min) / (npoints - 1U)),
118  npoints_(npoints),
121  monotonous_(false),
122  monotonicityKnown_(false) {
123  if (!data)
124  throw cms::Exception("FFTJetBadConfig") << "No data configured" << std::endl;
125  if (npoints <= 1U)
126  throw cms::Exception("FFTJetBadConfig") << "Not enough data points" << std::endl;
127  }
template<typename RealN >
fftjetcms::LinInterpolatedTable1D::LinInterpolatedTable1D ( const std::vector< std::pair< RealN, RealN > > &  v,
unsigned  npoints,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
)

Definition at line 130 of file LinInterpolatedTable1D.h.

References binwidth_, data_, Exception, dqmdumpme::first, mps_fire::i, interpolateSimple(), npoints_, edm::second(), edm::shift, mitigatedMETSequence_cff::U, findQualityFiles::v, xmax_, and xmin_.

134  : xmin_(v[0].first),
135  xmax_(v[v.size() - 1U].first),
136  binwidth_((xmax_ - xmin_) / (npoints - 1U)),
137  npoints_(npoints),
140  monotonous_(false),
141  monotonicityKnown_(false) {
142  const unsigned len = v.size();
143  if (len <= 1U)
144  throw cms::Exception("FFTJetBadConfig") << "Not enough data for interpolation" << std::endl;
145 
146  if (npoints <= 1U)
147  throw cms::Exception("FFTJetBadConfig") << "Not enough interpolation table entries" << std::endl;
148 
149  const std::pair<RealN, RealN>* vdata = &v[0];
150  for (unsigned i = 1; i < len; ++i)
151  if (vdata[i - 1U].first >= vdata[i].first)
152  throw cms::Exception("FFTJetBadConfig") << "Input data is not sorted properly" << std::endl;
153 
154  unsigned shift = 0U;
156  ++npoints_;
157  xmin_ -= binwidth_;
158  shift = 1U;
159  }
161  ++npoints_;
162  xmax_ += binwidth_;
163  }
164 
165  data_.resize(npoints_);
166 
168  data_[0] = interpolateSimple(vdata[0].first, vdata[1].first, vdata[0].second, vdata[1].second, xmin_);
169  }
172  vdata[len - 2U].first, vdata[len - 1U].first, vdata[len - 2U].second, vdata[len - 1U].second, xmax_);
173  }
174 
175  data_[shift] = vdata[0].second;
176  data_[npoints - 1U + shift] = vdata[len - 1U].second;
177  unsigned ibelow = 0, iabove = 1;
178  for (unsigned i = 1; i < npoints - 1; ++i) {
179  const double x = xmin_ + (i + shift) * binwidth_;
180  while (static_cast<double>(v[iabove].first) <= x) {
181  ++ibelow;
182  ++iabove;
183  }
184  if (v[ibelow].first == v[iabove].first)
185  data_[i + shift] = (v[ibelow].second + v[iabove].second) / 2.0;
186  else
187  data_[i + shift] = interpolateSimple(v[ibelow].first, v[iabove].first, v[ibelow].second, v[iabove].second, x);
188  }
189  }
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)
static unsigned int const shift
fftjetcms::LinInterpolatedTable1D::LinInterpolatedTable1D ( double  c)
explicit
fftjetcms::LinInterpolatedTable1D::~LinInterpolatedTable1D ( )
inlineoverride

Definition at line 51 of file LinInterpolatedTable1D.h.

References operator()(), operator==(), and alignCSCRings::r.

51 {}

Member Function Documentation

const double* fftjetcms::LinInterpolatedTable1D::data ( ) const
inline

Definition at line 66 of file LinInterpolatedTable1D.h.

References data_, inverse(), and isMonotonous().

66 { return &data_[0]; }
static double fftjetcms::LinInterpolatedTable1D::interpolateSimple ( const double  x0,
const double  x1,
const double  y0,
const double  y1,
const double  x 
)
inlinestaticprivate
std::unique_ptr< LinInterpolatedTable1D > fftjetcms::LinInterpolatedTable1D::inverse ( unsigned  npoints,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
) const

Definition at line 36 of file LinInterpolatedTable1D.cc.

References binwidth_, data_, mps_fire::i, isMonotonous(), LinInterpolatedTable1D(), npoints_, HLT_2018_cff::points, mitigatedMETSequence_cff::U, xmax_, and xmin_.

Referenced by data().

38  {
39  if (!isMonotonous())
40  return std::unique_ptr<LinInterpolatedTable1D>(nullptr);
41 
42  std::vector<std::pair<double, double> > points;
43  points.reserve(npoints_);
44 
45  if (data_[npoints_ - 1U] > data_[0]) {
46  points.push_back(std::pair<double, double>(data_[0], xmin_));
47  for (unsigned i = 1; i < npoints_ - 1U; ++i)
48  points.push_back(std::pair<double, double>(data_[i], xmin_ + i * binwidth_));
49  points.push_back(std::pair<double, double>(data_[npoints_ - 1U], xmax_));
50  } else {
51  points.push_back(std::pair<double, double>(data_[npoints_ - 1U], xmax_));
52  for (unsigned i = npoints_ - 2U; i > 0; --i)
53  points.push_back(std::pair<double, double>(data_[i], xmin_ + i * binwidth_));
54  points.push_back(std::pair<double, double>(data_[0], xmin_));
55  }
56 
57  return std::unique_ptr<LinInterpolatedTable1D>(
59  }
LinInterpolatedTable1D(const RealN *data, unsigned npoints, double x_min, double x_max, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
bool fftjetcms::LinInterpolatedTable1D::isMonotonous ( ) const

Definition at line 21 of file LinInterpolatedTable1D.cc.

References data_, dumpMFGeometry_cfg::delta, mps_fire::i, monotonicityKnown_, monotonous_, npoints_, and mitigatedMETSequence_cff::U.

Referenced by data(), and inverse().

21  {
22  if (!monotonicityKnown_) {
23  monotonous_ = true;
24  const double delta = data_[npoints_ - 1U] - data_[0];
25  if (delta == 0.0)
26  monotonous_ = false;
27  const double sg = delta > 0.0 ? 1.0 : -1.0;
28  for (unsigned i = 1; i < npoints_ && monotonous_; ++i)
29  if ((data_[i] - data_[i - 1]) * sg <= 0.0)
30  monotonous_ = false;
31  monotonicityKnown_ = true;
32  }
33  return monotonous_;
34  }
bool fftjetcms::LinInterpolatedTable1D::leftExtrapolationLinear ( ) const
inline
unsigned fftjetcms::LinInterpolatedTable1D::npoints ( ) const
inline

Definition at line 63 of file LinInterpolatedTable1D.h.

References npoints_.

bool fftjetcms::LinInterpolatedTable1D::operator!= ( const LinInterpolatedTable1D r) const
inline

Definition at line 58 of file LinInterpolatedTable1D.h.

References alignCSCRings::r.

58 { return !(*this == r); }
double fftjetcms::LinInterpolatedTable1D::operator() ( const double &  x) const
override

Definition at line 61 of file LinInterpolatedTable1D.cc.

References binwidth_, data_, dumpMFGeometry_cfg::delta, leftExtrapolationLinear_, npoints_, rightExtrapolationLinear_, mitigatedMETSequence_cff::U, xmax_, and xmin_.

Referenced by ~LinInterpolatedTable1D().

61  {
62  if (x <= xmin_) {
64  return data_[0] + (data_[1] - data_[0]) * ((x - xmin_) / binwidth_);
65  else
66  return data_[0];
67  } else if (x >= xmax_) {
69  return data_[npoints_ - 1U] - (data_[npoints_ - 2U] - data_[npoints_ - 1U]) * ((x - xmax_) / binwidth_);
70  else
71  return data_[npoints_ - 1U];
72  } else {
73  const unsigned ux = static_cast<unsigned>((x - xmin_) / binwidth_);
74  if (ux >= npoints_ - 1U)
75  return data_[npoints_ - 1U];
76  const double delta = x - (ux * binwidth_ + xmin_);
77  return data_[ux] + (data_[ux + 1U] - data_[ux]) * delta / binwidth_;
78  }
79  }
bool fftjetcms::LinInterpolatedTable1D::operator== ( const LinInterpolatedTable1D r) const
bool fftjetcms::LinInterpolatedTable1D::rightExtrapolationLinear ( ) const
inline
double fftjetcms::LinInterpolatedTable1D::xmax ( ) const
inline

Definition at line 62 of file LinInterpolatedTable1D.h.

References xmax_.

Referenced by svgfig.XAxis::__repr__().

double fftjetcms::LinInterpolatedTable1D::xmin ( ) const
inline

Member Data Documentation

double fftjetcms::LinInterpolatedTable1D::binwidth_
private

Definition at line 96 of file LinInterpolatedTable1D.h.

Referenced by inverse(), LinInterpolatedTable1D(), operator()(), and operator==().

std::vector<double> fftjetcms::LinInterpolatedTable1D::data_
private
bool fftjetcms::LinInterpolatedTable1D::leftExtrapolationLinear_
private

Definition at line 98 of file LinInterpolatedTable1D.h.

Referenced by leftExtrapolationLinear(), operator()(), and operator==().

bool fftjetcms::LinInterpolatedTable1D::monotonicityKnown_
mutableprivate

Definition at line 101 of file LinInterpolatedTable1D.h.

Referenced by isMonotonous().

bool fftjetcms::LinInterpolatedTable1D::monotonous_
mutableprivate

Definition at line 100 of file LinInterpolatedTable1D.h.

Referenced by isMonotonous().

unsigned fftjetcms::LinInterpolatedTable1D::npoints_
private
bool fftjetcms::LinInterpolatedTable1D::rightExtrapolationLinear_
private

Definition at line 99 of file LinInterpolatedTable1D.h.

Referenced by operator()(), operator==(), and rightExtrapolationLinear().

double fftjetcms::LinInterpolatedTable1D::xmax_
private
double fftjetcms::LinInterpolatedTable1D::xmin_
private