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.

Referenced by approximateInverse().

6 {}

◆ HcalCubicInterpolator() [2/2]

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

Definition at line 8 of file HcalCubicInterpolator.cc.

References abscissae_, derivatives_, Exception, mps_fire::i, jetUpdater_cfi::sort, submitPVValidationJobs::t, createJobs::tmp, and values_.

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 }
std::tuple< double, double, double > Triple
std::vector< double > abscissae_
std::vector< double > values_
std::vector< double > derivatives_
tmp
align.sh
Definition: createJobs.py:716

◆ ~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.

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

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  }
92  return HcalCubicInterpolator(points);
93 }
std::tuple< double, double, double > Triple
std::vector< double > abscissae_
static bool isStrictlyIncreasing(Iter begin, Iter const end)
static bool isStrictlyDecreasing(Iter begin, Iter const end)
std::vector< double > values_
std::vector< double > derivatives_

◆ isEqual()

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

Implements AbsHcalFunctor.

Definition at line 41 of file HcalCubicInterpolator.h.

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

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

◆ operator()()

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

Implements AbsHcalFunctor.

Definition at line 31 of file HcalCubicInterpolator.cc.

References abscissae_, derivatives_, PVValHelper::dx, mps_fire::result, submitPVValidationJobs::t, pfDeepBoostedJetPreprocessParams_cfi::upper_bound, values_, and x.

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 }
std::vector< double > abscissae_
std::vector< double > values_
std::vector< double > derivatives_

◆ serialize()

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

Definition at line 54 of file HcalCubicInterpolator.h.

References abscissae_, derivatives_, and values_.

54  {
55  boost::serialization::base_object<AbsHcalFunctor>(*this);
57  }
std::vector< double > abscissae_
std::vector< double > values_
std::vector< double > derivatives_

◆ xmax()

double HcalCubicInterpolator::xmax ( ) const
overridevirtual

Reimplemented from AbsHcalFunctor.

Definition at line 67 of file HcalCubicInterpolator.cc.

References abscissae_, and mps_fire::result.

Referenced by svgfig.XAxis::__repr__().

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

◆ xmin()

double HcalCubicInterpolator::xmin ( ) const
overridevirtual

Reimplemented from AbsHcalFunctor.

Definition at line 60 of file HcalCubicInterpolator.cc.

References abscissae_, and mps_fire::result.

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

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

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