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

◆ LinInterpolatedTable1D() [1/3]

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 data(), Exception, npoints(), and mitigatedMETSequence_cff::U.

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  }

◆ LinInterpolatedTable1D() [2/3]

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(), leftExtrapolationLinear(), npoints(), npoints_, rightExtrapolationLinear(), edm::second(), edm::shift, mitigatedMETSequence_cff::U, findQualityFiles::v, x, 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

◆ LinInterpolatedTable1D() [3/3]

fftjetcms::LinInterpolatedTable1D::LinInterpolatedTable1D ( double  c)
explicit

◆ ~LinInterpolatedTable1D()

fftjetcms::LinInterpolatedTable1D::~LinInterpolatedTable1D ( )
inlineoverride

Definition at line 51 of file LinInterpolatedTable1D.h.

51 {}

Member Function Documentation

◆ data()

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

Definition at line 66 of file LinInterpolatedTable1D.h.

References data_.

Referenced by LinInterpolatedTable1D().

66 { return &data_[0]; }

◆ interpolateSimple()

static double fftjetcms::LinInterpolatedTable1D::interpolateSimple ( const double  x0,
const double  x1,
const double  y0,
const double  y1,
const double  x 
)
inlinestaticprivate

◆ inverse()

std::unique_ptr< LinInterpolatedTable1D > fftjetcms::LinInterpolatedTable1D::inverse ( unsigned  npoints,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
) const

Definition at line 38 of file LinInterpolatedTable1D.cc.

References binwidth_, data_, mps_fire::i, isMonotonous(), leftExtrapolationLinear(), npoints(), npoints_, rightExtrapolationLinear(), mitigatedMETSequence_cff::U, xmax_, and xmin_.

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

◆ isMonotonous()

bool fftjetcms::LinInterpolatedTable1D::isMonotonous ( ) const

Definition at line 23 of file LinInterpolatedTable1D.cc.

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

Referenced by inverse().

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

◆ leftExtrapolationLinear()

bool fftjetcms::LinInterpolatedTable1D::leftExtrapolationLinear ( ) const
inline

◆ npoints()

unsigned fftjetcms::LinInterpolatedTable1D::npoints ( ) const
inline

Definition at line 63 of file LinInterpolatedTable1D.h.

References npoints_.

Referenced by inverse(), and LinInterpolatedTable1D().

◆ operator!=()

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

Definition at line 58 of file LinInterpolatedTable1D.h.

58 { return !(*this == r); }

◆ operator()()

double fftjetcms::LinInterpolatedTable1D::operator() ( const double &  x) const
override

Definition at line 62 of file LinInterpolatedTable1D.cc.

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

62  {
63  if (x <= xmin_) {
65  return data_[0] + (data_[1] - data_[0]) * ((x - xmin_) / binwidth_);
66  else
67  return data_[0];
68  } else if (x >= xmax_) {
70  return data_[npoints_ - 1U] - (data_[npoints_ - 2U] - data_[npoints_ - 1U]) * ((x - xmax_) / binwidth_);
71  else
72  return data_[npoints_ - 1U];
73  } else {
74  const unsigned ux = static_cast<unsigned>((x - xmin_) / binwidth_);
75  if (ux >= npoints_ - 1U)
76  return data_[npoints_ - 1U];
77  const double delta = x - (ux * binwidth_ + xmin_);
78  return data_[ux] + (data_[ux + 1U] - data_[ux]) * delta / binwidth_;
79  }
80  }

◆ operator==()

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

◆ rightExtrapolationLinear()

bool fftjetcms::LinInterpolatedTable1D::rightExtrapolationLinear ( ) const
inline

◆ xmax()

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

Definition at line 62 of file LinInterpolatedTable1D.h.

References xmax_.

Referenced by svgfig.XAxis::__repr__().

◆ xmin()

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

Member Data Documentation

◆ binwidth_

double fftjetcms::LinInterpolatedTable1D::binwidth_
private

Definition at line 96 of file LinInterpolatedTable1D.h.

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

◆ data_

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

◆ leftExtrapolationLinear_

bool fftjetcms::LinInterpolatedTable1D::leftExtrapolationLinear_
private

Definition at line 98 of file LinInterpolatedTable1D.h.

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

◆ monotonicityKnown_

bool fftjetcms::LinInterpolatedTable1D::monotonicityKnown_
mutableprivate

Definition at line 101 of file LinInterpolatedTable1D.h.

Referenced by isMonotonous().

◆ monotonous_

bool fftjetcms::LinInterpolatedTable1D::monotonous_
mutableprivate

Definition at line 100 of file LinInterpolatedTable1D.h.

Referenced by isMonotonous().

◆ npoints_

unsigned fftjetcms::LinInterpolatedTable1D::npoints_
private

◆ rightExtrapolationLinear_

bool fftjetcms::LinInterpolatedTable1D::rightExtrapolationLinear_
private

Definition at line 99 of file LinInterpolatedTable1D.h.

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

◆ xmax_

double fftjetcms::LinInterpolatedTable1D::xmax_
private

◆ xmin_

double fftjetcms::LinInterpolatedTable1D::xmin_
private