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.

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  }

References data(), Exception, npoints(), and mitigatedMETSequence_cff::U.

◆ 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.

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  }

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

◆ LinInterpolatedTable1D() [3/3]

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

Definition at line 6 of file LinInterpolatedTable1D.cc.

7  : data_(2, c),
8  xmin_(0.0),
9  xmax_(1.0),
10  binwidth_(1.0),
11  npoints_(2U),
14  monotonous_(false),
15  monotonicityKnown_(true) {}

◆ ~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.

66 { return &data_[0]; }

References data_.

Referenced by LinInterpolatedTable1D().

◆ interpolateSimple()

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

Definition at line 88 of file LinInterpolatedTable1D.h.

89  {
90  return y0 + (y1 - y0) * ((x - x0) / (x1 - x0));
91  }

References testProducerWithPsetDescEmpty_cfi::x1, and testProducerWithPsetDescEmpty_cfi::y1.

Referenced by LinInterpolatedTable1D().

◆ inverse()

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

Definition at line 38 of file LinInterpolatedTable1D.cc.

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  }

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

◆ isMonotonous()

bool fftjetcms::LinInterpolatedTable1D::isMonotonous ( ) const

Definition at line 23 of file LinInterpolatedTable1D.cc.

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  }

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

Referenced by inverse().

◆ leftExtrapolationLinear()

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

Definition at line 64 of file LinInterpolatedTable1D.h.

64 { return leftExtrapolationLinear_; }

References leftExtrapolationLinear_.

Referenced by inverse(), and LinInterpolatedTable1D().

◆ npoints()

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

Definition at line 63 of file LinInterpolatedTable1D.h.

63 { return npoints_; }

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); }

References alignCSCRings::r.

◆ operator()()

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

Definition at line 62 of file LinInterpolatedTable1D.cc.

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  }

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

◆ operator==()

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

Definition at line 17 of file LinInterpolatedTable1D.cc.

17  {
18  return xmin_ == r.xmin_ && xmax_ == r.xmax_ && binwidth_ == r.binwidth_ && npoints_ == r.npoints_ &&
19  leftExtrapolationLinear_ == r.leftExtrapolationLinear_ &&
20  rightExtrapolationLinear_ == r.rightExtrapolationLinear_ && data_ == r.data_;
21  }

References binwidth_, data_, leftExtrapolationLinear_, npoints_, alignCSCRings::r, rightExtrapolationLinear_, xmax_, and xmin_.

◆ rightExtrapolationLinear()

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

Definition at line 65 of file LinInterpolatedTable1D.h.

65 { return rightExtrapolationLinear_; }

References rightExtrapolationLinear_.

Referenced by inverse(), and LinInterpolatedTable1D().

◆ xmax()

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

Definition at line 62 of file LinInterpolatedTable1D.h.

62 { return xmax_; }

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
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.points
points
Definition: HLT_FULL_cff.py:21469
fftjetcms::LinInterpolatedTable1D::rightExtrapolationLinear
bool rightExtrapolationLinear() const
Definition: LinInterpolatedTable1D.h:65
fftjetcms::LinInterpolatedTable1D::xmax_
double xmax_
Definition: LinInterpolatedTable1D.h:95
fftjetcms::LinInterpolatedTable1D::monotonous_
bool monotonous_
Definition: LinInterpolatedTable1D.h:100
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
DDAxes::x
fftjetcms::LinInterpolatedTable1D::npoints
unsigned npoints() const
Definition: LinInterpolatedTable1D.h:63
findQualityFiles.v
v
Definition: findQualityFiles.py:179
fftjetcms::LinInterpolatedTable1D::rightExtrapolationLinear_
bool rightExtrapolationLinear_
Definition: LinInterpolatedTable1D.h:99
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
fftjetcms::LinInterpolatedTable1D::binwidth_
double binwidth_
Definition: LinInterpolatedTable1D.h:96
fftjetcms::LinInterpolatedTable1D::monotonicityKnown_
bool monotonicityKnown_
Definition: LinInterpolatedTable1D.h:101
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:125
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
fftjetcms::LinInterpolatedTable1D::isMonotonous
bool isMonotonous() const
Definition: LinInterpolatedTable1D.cc:23
fftjetcms::LinInterpolatedTable1D::leftExtrapolationLinear
bool leftExtrapolationLinear() const
Definition: LinInterpolatedTable1D.h:64
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
fftjetcms::LinInterpolatedTable1D::data
const double * data() const
Definition: LinInterpolatedTable1D.h:66
fftjetcms::LinInterpolatedTable1D::interpolateSimple
static double interpolateSimple(const double x0, const double x1, const double y0, const double y1, const double x)
Definition: LinInterpolatedTable1D.h:88
fftjetcms::LinInterpolatedTable1D::xmin_
double xmin_
Definition: LinInterpolatedTable1D.h:94
alignCSCRings.r
r
Definition: alignCSCRings.py:93
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
fftjetcms::LinInterpolatedTable1D::npoints_
unsigned npoints_
Definition: LinInterpolatedTable1D.h:97
Exception
Definition: hltDiff.cc:245
fftjetcms::LinInterpolatedTable1D::leftExtrapolationLinear_
bool leftExtrapolationLinear_
Definition: LinInterpolatedTable1D.h:98
fftjetcms::LinInterpolatedTable1D::data_
std::vector< double > data_
Definition: LinInterpolatedTable1D.h:93
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56