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.

Referenced by inverse().

◆ 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, dqmdumpme::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 4 of file LinInterpolatedTable1D.cc.

5  : data_(2, c),
6  xmin_(0.0),
7  xmax_(1.0),
8  binwidth_(1.0),
9  npoints_(2U),
12  monotonous_(false),
13  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 36 of file LinInterpolatedTable1D.cc.

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  }

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

◆ isMonotonous()

bool fftjetcms::LinInterpolatedTable1D::isMonotonous ( ) const

Definition at line 21 of file LinInterpolatedTable1D.cc.

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  }

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 61 of file LinInterpolatedTable1D.cc.

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  }

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 15 of file LinInterpolatedTable1D.cc.

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

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
HLT_2018_cff.points
points
Definition: HLT_2018_cff.py:20125
mps_fire.i
i
Definition: mps_fire.py:355
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:215
DDAxes::x
fftjetcms::LinInterpolatedTable1D::npoints
unsigned npoints() const
Definition: LinInterpolatedTable1D.h:63
findQualityFiles.v
v
Definition: findQualityFiles.py:179
dqmdumpme.first
first
Definition: dqmdumpme.py:55
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
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
fftjetcms::LinInterpolatedTable1D::isMonotonous
bool isMonotonous() const
Definition: LinInterpolatedTable1D.cc:21
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
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
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:246
fftjetcms::LinInterpolatedTable1D::leftExtrapolationLinear_
bool leftExtrapolationLinear_
Definition: LinInterpolatedTable1D.h:98
fftjetcms::LinInterpolatedTable1D::LinInterpolatedTable1D
LinInterpolatedTable1D(const RealN *data, unsigned npoints, double x_min, double x_max, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
Definition: LinInterpolatedTable1D.h:108
fftjetcms::LinInterpolatedTable1D::data_
std::vector< double > data_
Definition: LinInterpolatedTable1D.h:93