CMS 3D CMS Logo

LinInterpolatedTable1D.cc
Go to the documentation of this file.
2 
3 namespace fftjetcms {
5  : data_(2, c),
6  xmin_(0.0),
7  xmax_(1.0),
8  binwidth_(1.0),
9  npoints_(2U),
10  leftExtrapolationLinear_(false),
11  rightExtrapolationLinear_(false),
12  monotonous_(false),
13  monotonicityKnown_(true) {}
14 
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  }
20 
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  }
35 
36  std::unique_ptr<LinInterpolatedTable1D> LinInterpolatedTable1D::inverse(const unsigned npoints,
37  const bool leftExtrapolationLinear,
38  const bool rightExtrapolationLinear) const {
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  }
60 
61  double LinInterpolatedTable1D::operator()(const double& x) const {
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  }
80 } // namespace fftjetcms
HLT_2018_cff.points
points
Definition: HLT_2018_cff.py:20125
npoints
static const int npoints
Definition: NuclearInteractionFTFSimulator.h:38
mps_fire.i
i
Definition: mps_fire.py:355
funct::false
false
Definition: Factorize.h:34
fftjetcms
Definition: AbsPileupCalculator.h:15
fftjetcms::LinInterpolatedTable1D::operator==
bool operator==(const LinInterpolatedTable1D &r) const
Definition: LinInterpolatedTable1D.cc:15
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
fftjetcms::LinInterpolatedTable1D::npoints
unsigned npoints() const
Definition: LinInterpolatedTable1D.h:63
fftjetcms::LinInterpolatedTable1D::rightExtrapolationLinear_
bool rightExtrapolationLinear_
Definition: LinInterpolatedTable1D.h:99
fftjetcms::LinInterpolatedTable1D::binwidth_
double binwidth_
Definition: LinInterpolatedTable1D.h:96
fftjetcms::LinInterpolatedTable1D::monotonicityKnown_
bool monotonicityKnown_
Definition: LinInterpolatedTable1D.h:101
fftjetcms::LinInterpolatedTable1D::inverse
std::unique_ptr< LinInterpolatedTable1D > inverse(unsigned npoints, bool leftExtrapolationLinear, bool rightExtrapolationLinear) const
Definition: LinInterpolatedTable1D.cc:36
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
fftjetcms::LinInterpolatedTable1D::isMonotonous
bool isMonotonous() const
Definition: LinInterpolatedTable1D.cc:21
mixed_calib_calo_ttbar_result.leftExtrapolationLinear
leftExtrapolationLinear
Definition: mixed_calib_calo_ttbar_result.py:10
funct::true
true
Definition: Factorize.h:173
fftjetcms::LinInterpolatedTable1D::operator()
double operator()(const double &x) const override
Definition: LinInterpolatedTable1D.cc:61
fftjetcms::LinInterpolatedTable1D::leftExtrapolationLinear
bool leftExtrapolationLinear() const
Definition: LinInterpolatedTable1D.h:64
dumpMFGeometry_cfg.delta
delta
Definition: dumpMFGeometry_cfg.py:25
fftjetcms::LinInterpolatedTable1D::xmin_
double xmin_
Definition: LinInterpolatedTable1D.h:94
fftjetcms::LinInterpolatedTable1D
Definition: LinInterpolatedTable1D.h:24
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
alignCSCRings.r
r
Definition: alignCSCRings.py:93
fftjetcms::LinInterpolatedTable1D::npoints_
unsigned npoints_
Definition: LinInterpolatedTable1D.h:97
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
mixed_calib_calo_ttbar_result.rightExtrapolationLinear
rightExtrapolationLinear
Definition: mixed_calib_calo_ttbar_result.py:11
fftjetcms::LinInterpolatedTable1D::data_
std::vector< double > data_
Definition: LinInterpolatedTable1D.h:93
LinInterpolatedTable1D.h