CMS 3D CMS Logo

HcalInterpolatedTableFunctor.cc
Go to the documentation of this file.
1 #include <algorithm>
3 
5 
6 inline static double interpolateStep(
7  const double x0, const double step, const double y0, const double y1, const double x) {
8  return y0 + (y1 - y0) * ((x - x0) / step);
9 }
10 
12  : xmin_(0.), xmax_(0.), leftExtrapolationLinear_(false), rightExtrapolationLinear_(false) {}
13 
15  const double ixmin,
16  const double ixmax,
17  const bool leftExtrapolationLinear,
18  const bool rightExtrapolationLinear)
19  : values_(values),
20  xmin_(ixmin),
21  xmax_(ixmax),
22  leftExtrapolationLinear_(leftExtrapolationLinear),
23  rightExtrapolationLinear_(rightExtrapolationLinear) {
24  if (values_.size() < 2)
25  throw cms::Exception(
26  "In HcalInterpolatedTableFunctor constructor:"
27  " insufficient number of points");
28  if (xmin_ >= xmax_)
29  throw cms::Exception(
30  "In HcalInterpolatedTableFunctor constructor:"
31  " invalid min and/or max coordinates");
32 }
33 
34 double HcalInterpolatedTableFunctor::operator()(const double x) const {
35  double result = 0.0;
36  const std::size_t sz = values_.size();
37  const std::size_t szm1 = sz - 1;
38  const double step = (xmax_ - xmin_) / szm1;
39 
40  if (x >= xmax_) {
42  result = interpolateStep(xmax_ - step, step, values_[sz - 2], values_[szm1], x);
43  else
44  result = values_[szm1];
45  } else if (x <= xmin_) {
48  else
49  result = values_[0];
50  } else {
51  const std::size_t ux = static_cast<std::size_t>((x - xmin_) / step);
52  if (ux >= szm1)
53  return values_[szm1];
54  result = interpolateStep(ux * step + xmin_, step, values_[ux], values_[ux + 1], x);
55  }
56 
57  return result;
58 }
59 
61  return isStrictlyIncreasing(values_.begin(), values_.end()) || isStrictlyDecreasing(values_.begin(), values_.end());
62 }
63 
65  if (!isStrictlyMonotonous())
66  throw cms::Exception(
67  "In HcalInterpolatedTableFunctor::inverse:"
68  " can't invert non-monotonous functor");
69  const std::size_t sz = values_.size();
70  const std::size_t szm1 = sz - 1;
71  const double step = (xmax_ - xmin_) / szm1;
72  std::vector<std::pair<double, double> > points;
73  points.reserve(sz);
74  for (std::size_t i = 0; i < sz; ++i) {
75  const double x = (i == szm1 ? xmax_ : xmin_ + step * i);
76  points.push_back(std::make_pair(values_[i], x));
77  }
80  if (values_[0] > values_[sz - 1])
81  std::swap(l, r);
83 }
84 
85 BOOST_CLASS_EXPORT_IMPLEMENT(HcalInterpolatedTableFunctor)
mps_fire.i
i
Definition: mps_fire.py:428
AbsHcalFunctor::isStrictlyDecreasing
static bool isStrictlyDecreasing(Iter begin, Iter const end)
Definition: AbsHcalFunctor.h:56
funct::false
false
Definition: Factorize.h:29
HLT_FULL_cff.points
points
Definition: HLT_FULL_cff.py:21455
step
step
Definition: StallMonitor.cc:94
HcalInterpolatedTableFunctor
Definition: HcalInterpolatedTableFunctor.h:10
HcalInterpolatedTableFunctor::xmin_
double xmin_
Definition: HcalInterpolatedTableFunctor.h:55
interpolateStep
static double interpolateStep(const double x0, const double step, const double y0, const double y1, const double x)
Definition: HcalInterpolatedTableFunctor.cc:6
HcalInterpolatedTableFunctor::leftExtrapolationLinear_
bool leftExtrapolationLinear_
Definition: HcalInterpolatedTableFunctor.h:57
DDAxes::x
HcalPiecewiseLinearFunctor
Definition: HcalPiecewiseLinearFunctor.h:17
AbsHcalFunctor::isStrictlyIncreasing
static bool isStrictlyIncreasing(Iter begin, Iter const end)
Definition: AbsHcalFunctor.h:43
HcalInterpolatedTableFunctor::operator()
double operator()(double x) const override
Definition: HcalInterpolatedTableFunctor.cc:34
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
HcalInterpolatedTableFunctor::values_
std::vector< double > values_
Definition: HcalInterpolatedTableFunctor.h:54
HcalInterpolatedTableFunctor::xmax_
double xmax_
Definition: HcalInterpolatedTableFunctor.h:56
HcalInterpolatedTableFunctor::inverse
HcalPiecewiseLinearFunctor inverse() const
Definition: HcalInterpolatedTableFunctor.cc:64
mixed_calib_calo_ttbar_result.leftExtrapolationLinear
leftExtrapolationLinear
Definition: mixed_calib_calo_ttbar_result.py:10
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
alignCSCRings.r
r
Definition: alignCSCRings.py:93
HcalInterpolatedTableFunctor::HcalInterpolatedTableFunctor
HcalInterpolatedTableFunctor()
Definition: HcalInterpolatedTableFunctor.cc:11
Exception
Definition: hltDiff.cc:246
genVertex_cff.x
x
Definition: genVertex_cff.py:12
HcalInterpolatedTableFunctor::rightExtrapolationLinear_
bool rightExtrapolationLinear_
Definition: HcalInterpolatedTableFunctor.h:58
Exception.h
mps_fire.result
result
Definition: mps_fire.py:311
cms::Exception
Definition: Exception.h:70
mixed_calib_calo_ttbar_result.rightExtrapolationLinear
rightExtrapolationLinear
Definition: mixed_calib_calo_ttbar_result.py:11
HcalInterpolatedTableFunctor::isStrictlyMonotonous
bool isStrictlyMonotonous() const
Definition: HcalInterpolatedTableFunctor.cc:60
HcalInterpolatedTableFunctor.h