CMS 3D CMS Logo

LinInterpolatedTable1D.cc
Go to the documentation of this file.
1 #include <memory>
2 
4 
5 namespace fftjetcms {
7  : data_(2, c),
8  xmin_(0.0),
9  xmax_(1.0),
10  binwidth_(1.0),
11  npoints_(2U),
12  leftExtrapolationLinear_(false),
13  rightExtrapolationLinear_(false),
14  monotonous_(false),
15  monotonicityKnown_(true) {}
16 
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  }
22 
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  }
37 
38  std::unique_ptr<LinInterpolatedTable1D> LinInterpolatedTable1D::inverse(const unsigned npoints,
39  const bool leftExtrapolationLinear,
40  const bool rightExtrapolationLinear) const {
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  }
61 
62  double LinInterpolatedTable1D::operator()(const double& x) const {
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  }
81 } // namespace fftjetcms
npoints
static const int npoints
Definition: NuclearInteractionFTFSimulator.h:38
mps_fire.i
i
Definition: mps_fire.py:428
funct::false
false
Definition: Factorize.h:29
fftjetcms
Definition: AbsPileupCalculator.h:15
HLT_FULL_cff.points
points
Definition: HLT_FULL_cff.py:21469
fftjetcms::LinInterpolatedTable1D::operator==
bool operator==(const LinInterpolatedTable1D &r) const
Definition: LinInterpolatedTable1D.cc:17
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:38
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
fftjetcms::LinInterpolatedTable1D::isMonotonous
bool isMonotonous() const
Definition: LinInterpolatedTable1D.cc:23
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:62
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
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
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56