CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends
HcalCubicInterpolator Class Reference

#include <HcalCubicInterpolator.h>

Inheritance diagram for HcalCubicInterpolator:
AbsHcalFunctor

Public Types

typedef std::tuple< double, double, double > Triple
 

Public Member Functions

HcalCubicInterpolator approximateInverse () const
 
 HcalCubicInterpolator ()
 
 HcalCubicInterpolator (const std::vector< Triple > &points)
 
double operator() (double x) const override
 
double xmax () const override
 
double xmin () const override
 
 ~HcalCubicInterpolator () override
 
- Public Member Functions inherited from AbsHcalFunctor
bool operator!= (const AbsHcalFunctor &r) const
 
bool operator== (const AbsHcalFunctor &r) const
 
virtual ~AbsHcalFunctor ()
 

Protected Member Functions

bool isEqual (const AbsHcalFunctor &other) const override
 

Private Member Functions

template<class Archive >
void serialize (Archive &ar, unsigned)
 

Private Attributes

std::vector< double > abscissae_
 
std::vector< double > derivatives_
 
std::vector< double > values_
 

Friends

class boost::serialization::access
 

Additional Inherited Members

- Static Protected Member Functions inherited from AbsHcalFunctor
template<class Iter >
static bool isStrictlyDecreasing (Iter begin, Iter const end)
 
template<class Iter >
static bool isStrictlyIncreasing (Iter begin, Iter const end)
 

Detailed Description

Definition at line 17 of file HcalCubicInterpolator.h.

Member Typedef Documentation

◆ Triple

typedef std::tuple<double, double, double> HcalCubicInterpolator::Triple

Definition at line 20 of file HcalCubicInterpolator.h.

Constructor & Destructor Documentation

◆ HcalCubicInterpolator() [1/2]

HcalCubicInterpolator::HcalCubicInterpolator ( )

Definition at line 6 of file HcalCubicInterpolator.cc.

6 {}

Referenced by approximateInverse().

◆ HcalCubicInterpolator() [2/2]

HcalCubicInterpolator::HcalCubicInterpolator ( const std::vector< Triple > &  points)
explicit

Definition at line 8 of file HcalCubicInterpolator.cc.

8  {
9  const std::size_t sz = points.size();
10  if (sz) {
11  std::vector<Triple> tmp(points);
12  std::sort(tmp.begin(), tmp.end());
13  abscissae_.reserve(sz);
14  values_.reserve(sz);
15  derivatives_.reserve(sz);
16  for (std::size_t i = 0; i < sz; ++i) {
17  const Triple& t(tmp[i]);
18  abscissae_.push_back(std::get<0>(t));
19  values_.push_back(std::get<1>(t));
20  derivatives_.push_back(std::get<2>(t));
21  }
22  const std::size_t szm1 = sz - 1;
23  for (std::size_t i = 0; i < szm1; ++i)
24  if (abscissae_[i] == abscissae_[i + 1])
25  throw cms::Exception(
26  "In HcalCubicInterpolator constructor:"
27  " abscissae must not coincide");
28  }
29 }

References abscissae_, derivatives_, Exception, mps_fire::i, HLT_2018_cff::points, OrderedSet::t, createJobs::tmp, and values_.

◆ ~HcalCubicInterpolator()

HcalCubicInterpolator::~HcalCubicInterpolator ( )
inlineoverride

Definition at line 30 of file HcalCubicInterpolator.h.

30 {}

Member Function Documentation

◆ approximateInverse()

HcalCubicInterpolator HcalCubicInterpolator::approximateInverse ( ) const

Definition at line 74 of file HcalCubicInterpolator.cc.

74  {
75  const bool monotonous =
76  isStrictlyIncreasing(values_.begin(), values_.end()) || isStrictlyDecreasing(values_.begin(), values_.end());
77  if (!monotonous)
78  throw cms::Exception(
79  "In HcalCubicInterpolator::inverse:"
80  " can't invert non-monotonous functor");
81  const std::size_t sz = abscissae_.size();
82  std::vector<Triple> points;
83  points.reserve(sz);
84  for (std::size_t i = 0; i < sz; ++i) {
85  const double dydx = derivatives_[i];
86  if (dydx == 0.0)
87  throw cms::Exception(
88  "In HcalCubicInterpolator::inverse:"
89  " can't invert functor with derivatives of 0");
90  points.push_back(Triple(values_[i], abscissae_[i], 1.0 / dydx));
91  }
93 }

References abscissae_, derivatives_, Exception, HcalCubicInterpolator(), mps_fire::i, AbsHcalFunctor::isStrictlyDecreasing(), AbsHcalFunctor::isStrictlyIncreasing(), HLT_2018_cff::points, and values_.

◆ isEqual()

bool HcalCubicInterpolator::isEqual ( const AbsHcalFunctor other) const
inlineoverrideprotectedvirtual

Implements AbsHcalFunctor.

Definition at line 41 of file HcalCubicInterpolator.h.

41  {
42  const HcalCubicInterpolator& r = static_cast<const HcalCubicInterpolator&>(other);
43  return abscissae_ == r.abscissae_ && values_ == r.values_ && derivatives_ == r.derivatives_;
44  }

References abscissae_, derivatives_, trackingPlots::other, alignCSCRings::r, and values_.

◆ operator()()

double HcalCubicInterpolator::operator() ( double  x) const
overridevirtual

Implements AbsHcalFunctor.

Definition at line 31 of file HcalCubicInterpolator.cc.

31  {
32  double result = 0.0;
33  const std::size_t sz = abscissae_.size();
34  if (sz) {
35  if (sz > 1) {
36  const std::size_t szm1 = sz - 1;
37  if (x >= abscissae_[szm1])
38  result = values_[szm1] + derivatives_[szm1] * (x - abscissae_[szm1]);
39  else if (x <= abscissae_[0])
40  result = values_[0] + derivatives_[0] * (x - abscissae_[0]);
41  else {
42  const std::size_t cell = std::upper_bound(abscissae_.begin(), abscissae_.end(), x) - abscissae_.begin() - 1;
43  const std::size_t cellp1 = cell + 1;
44  const double dx = abscissae_[cellp1] - abscissae_[cell];
45  const double t = (x - abscissae_[cell]) / dx;
46  const double onemt = 1.0 - t;
47  const double h00 = onemt * onemt * (1.0 + 2.0 * t);
48  const double h10 = onemt * onemt * t;
49  const double h01 = t * t * (3.0 - 2.0 * t);
50  const double h11 = t * t * onemt;
51  result = h00 * values_[cell] + h10 * dx * derivatives_[cell] + h01 * values_[cellp1] -
52  h11 * dx * derivatives_[cellp1];
53  }
54  } else
55  result = values_[0] + derivatives_[0] * (x - abscissae_[0]);
56  }
57  return result;
58 }

References abscissae_, derivatives_, PVValHelper::dx, mps_fire::result, OrderedSet::t, cuda_std::upper_bound(), values_, and x.

◆ serialize()

template<class Archive >
void HcalCubicInterpolator::serialize ( Archive &  ar,
unsigned   
)
inlineprivate

Definition at line 54 of file HcalCubicInterpolator.h.

54  {
55  boost::serialization::base_object<AbsHcalFunctor>(*this);
57  }

References abscissae_, derivatives_, and values_.

◆ xmax()

double HcalCubicInterpolator::xmax ( ) const
overridevirtual

Reimplemented from AbsHcalFunctor.

Definition at line 67 of file HcalCubicInterpolator.cc.

67  {
68  double result = 0.0;
69  if (!abscissae_.empty())
70  result = abscissae_.back();
71  return result;
72 }

References abscissae_, and mps_fire::result.

Referenced by svgfig.XAxis::__repr__().

◆ xmin()

double HcalCubicInterpolator::xmin ( ) const
overridevirtual

Reimplemented from AbsHcalFunctor.

Definition at line 60 of file HcalCubicInterpolator.cc.

60  {
61  double result = 0.0;
62  if (!abscissae_.empty())
63  result = abscissae_[0];
64  return result;
65 }

References abscissae_, and mps_fire::result.

Referenced by svgfig.XAxis::__repr__(), svgfig.Axes::__repr__(), svgfig.HGrid::__repr__(), svgfig.Grid::__repr__(), and svgfig.Axes::SVG().

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 51 of file HcalCubicInterpolator.h.

Member Data Documentation

◆ abscissae_

std::vector<double> HcalCubicInterpolator::abscissae_
private

◆ derivatives_

std::vector<double> HcalCubicInterpolator::derivatives_
private

◆ values_

std::vector<double> HcalCubicInterpolator::values_
private
HLT_2018_cff.points
points
Definition: HLT_2018_cff.py:20125
mps_fire.i
i
Definition: mps_fire.py:355
AbsHcalFunctor::isStrictlyDecreasing
static bool isStrictlyDecreasing(Iter begin, Iter const end)
Definition: AbsHcalFunctor.h:56
HcalCubicInterpolator::abscissae_
std::vector< double > abscissae_
Definition: HcalCubicInterpolator.h:47
DDAxes::x
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
AbsHcalFunctor::isStrictlyIncreasing
static bool isStrictlyIncreasing(Iter begin, Iter const end)
Definition: AbsHcalFunctor.h:43
HcalCubicInterpolator::derivatives_
std::vector< double > derivatives_
Definition: HcalCubicInterpolator.h:49
cuda_std::upper_bound
__host__ constexpr __device__ RandomIt upper_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:45
trackingPlots.other
other
Definition: trackingPlots.py:1465
OrderedSet.t
t
Definition: OrderedSet.py:90
HcalCubicInterpolator
Definition: HcalCubicInterpolator.h:17
HcalCubicInterpolator::Triple
std::tuple< double, double, double > Triple
Definition: HcalCubicInterpolator.h:20
alignCSCRings.r
r
Definition: alignCSCRings.py:93
Exception
Definition: hltDiff.cc:246
mps_fire.result
result
Definition: mps_fire.py:303
HcalCubicInterpolator::values_
std::vector< double > values_
Definition: HcalCubicInterpolator.h:48
PVValHelper::dx
Definition: PVValidationHelpers.h:48
HcalCubicInterpolator::HcalCubicInterpolator
HcalCubicInterpolator()
Definition: HcalCubicInterpolator.cc:6