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)
 
virtual double operator() (double x) const override
 
virtual double xmax () const override
 
virtual double xmin () const override
 
virtual ~HcalCubicInterpolator ()
 
- Public Member Functions inherited from AbsHcalFunctor
bool operator!= (const AbsHcalFunctor &r) const
 
bool operator== (const AbsHcalFunctor &r) const
 
virtual ~AbsHcalFunctor ()
 

Protected Member Functions

virtual 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

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

Definition at line 21 of file HcalCubicInterpolator.h.

Constructor & Destructor Documentation

HcalCubicInterpolator::HcalCubicInterpolator ( )

Definition at line 6 of file HcalCubicInterpolator.cc.

Referenced by approximateInverse().

7 {
8 }
HcalCubicInterpolator::HcalCubicInterpolator ( const std::vector< Triple > &  points)
explicit

Definition at line 10 of file HcalCubicInterpolator.cc.

References abscissae_, derivatives_, Exception, mps_fire::i, lumiQTWidget::t, tmp, and values_.

12 {
13  const std::size_t sz = points.size();
14  if (sz)
15  {
16  std::vector<Triple> tmp(points);
17  std::sort(tmp.begin(), tmp.end());
18  abscissae_.reserve(sz);
19  values_.reserve(sz);
20  derivatives_.reserve(sz);
21  for (std::size_t i=0; i<sz; ++i)
22  {
23  const Triple& t(tmp[i]);
24  abscissae_.push_back(std::get<0>(t));
25  values_.push_back(std::get<1>(t));
26  derivatives_.push_back(std::get<2>(t));
27  }
28  const std::size_t szm1 = sz - 1;
29  for (std::size_t i=0; i<szm1; ++i)
30  if (abscissae_[i] == abscissae_[i+1])
31  throw cms::Exception("In HcalCubicInterpolator constructor:"
32  " abscissae must not coincide");
33  }
34 }
std::vector< double > abscissae_
std::tuple< double, double, double > Triple
std::vector< double > values_
std::vector< double > derivatives_
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
virtual HcalCubicInterpolator::~HcalCubicInterpolator ( )
inlinevirtual

Definition at line 31 of file HcalCubicInterpolator.h.

References approximateInverse(), operator()(), x, xmax(), and xmin().

31 {}

Member Function Documentation

HcalCubicInterpolator HcalCubicInterpolator::approximateInverse ( ) const

Definition at line 87 of file HcalCubicInterpolator.cc.

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

Referenced by ~HcalCubicInterpolator().

88 {
89  const bool monotonous = isStrictlyIncreasing(values_.begin(), values_.end()) ||
90  isStrictlyDecreasing(values_.begin(), values_.end());
91  if (!monotonous)
92  throw cms::Exception("In HcalCubicInterpolator::inverse:"
93  " can't invert non-monotonous functor");
94  const std::size_t sz = abscissae_.size();
95  std::vector<Triple> points;
96  points.reserve(sz);
97  for (std::size_t i=0; i<sz; ++i)
98  {
99  const double dydx = derivatives_[i];
100  if (dydx == 0.0)
101  throw cms::Exception("In HcalCubicInterpolator::inverse:"
102  " can't invert functor with derivatives of 0");
103  points.push_back(Triple(values_[i], abscissae_[i], 1.0/dydx));
104  }
105  return HcalCubicInterpolator(points);
106 }
std::vector< double > abscissae_
std::tuple< double, double, double > Triple
static bool isStrictlyIncreasing(Iter begin, Iter const end)
static bool isStrictlyDecreasing(Iter begin, Iter const end)
std::vector< double > values_
std::vector< double > derivatives_
virtual bool HcalCubicInterpolator::isEqual ( const AbsHcalFunctor other) const
inlineoverrideprotectedvirtual

Implements AbsHcalFunctor.

Definition at line 42 of file HcalCubicInterpolator.h.

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

43  {
44  const HcalCubicInterpolator& r =
45  static_cast<const HcalCubicInterpolator&>(other);
46  return abscissae_ == r.abscissae_ &&
47  values_ == r.values_ &&
49  }
std::vector< double > abscissae_
std::vector< double > values_
std::vector< double > derivatives_
double HcalCubicInterpolator::operator() ( double  x) const
overridevirtual

Implements AbsHcalFunctor.

Definition at line 36 of file HcalCubicInterpolator.cc.

References abscissae_, derivatives_, PVValHelper::dx, mps_fire::result, lumiQTWidget::t, values_, and x.

Referenced by ~HcalCubicInterpolator().

37 {
38  double result = 0.0;
39  const std::size_t sz = abscissae_.size();
40  if (sz)
41  {
42  if (sz > 1)
43  {
44  const std::size_t szm1 = sz - 1;
45  if (x >= abscissae_[szm1])
46  result = values_[szm1] + derivatives_[szm1]*(x - abscissae_[szm1]);
47  else if (x <= abscissae_[0])
48  result = values_[0] + derivatives_[0]*(x - abscissae_[0]);
49  else
50  {
51  const std::size_t cell = std::upper_bound(abscissae_.begin(), abscissae_.end(), x) -
52  abscissae_.begin() - 1;
53  const std::size_t cellp1 = cell + 1;
54  const double dx = abscissae_[cellp1] - abscissae_[cell];
55  const double t = (x - abscissae_[cell])/dx;
56  const double onemt = 1.0 - t;
57  const double h00 = onemt*onemt*(1.0 + 2.0*t);
58  const double h10 = onemt*onemt*t;
59  const double h01 = t*t*(3.0 - 2.0*t);
60  const double h11 = t*t*onemt;
61  result = h00*values_[cell] + h10*dx*derivatives_[cell] +
62  h01*values_[cellp1] - h11*dx*derivatives_[cellp1];
63  }
64  }
65  else
66  result = values_[0] + derivatives_[0]*(x - abscissae_[0]);
67  }
68  return result;
69 }
std::vector< double > abscissae_
std::vector< double > values_
std::vector< double > derivatives_
template<class Archive >
void HcalCubicInterpolator::serialize ( Archive &  ar,
unsigned   
)
inlineprivate

Definition at line 59 of file HcalCubicInterpolator.h.

References derivatives_.

60  {
61  boost::serialization::base_object<AbsHcalFunctor>(*this);
63  }
std::vector< double > abscissae_
std::vector< double > values_
std::vector< double > derivatives_
double HcalCubicInterpolator::xmax ( ) const
overridevirtual

Reimplemented from AbsHcalFunctor.

Definition at line 79 of file HcalCubicInterpolator.cc.

References abscissae_, and mps_fire::result.

Referenced by svgfig.XAxis::__repr__(), and ~HcalCubicInterpolator().

80 {
81  double result = 0.0;
82  if (!abscissae_.empty())
83  result = abscissae_.back();
84  return result;
85 }
std::vector< double > abscissae_
double HcalCubicInterpolator::xmin ( ) const
overridevirtual

Reimplemented from AbsHcalFunctor.

Definition at line 71 of file HcalCubicInterpolator.cc.

References abscissae_, and mps_fire::result.

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

72 {
73  double result = 0.0;
74  if (!abscissae_.empty())
75  result = abscissae_[0];
76  return result;
77 }
std::vector< double > abscissae_

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 56 of file HcalCubicInterpolator.h.

Member Data Documentation

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