CMS 3D CMS Logo

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

#include <HcalInterpolatedTableFunctor.h>

Inheritance diagram for HcalInterpolatedTableFunctor:
AbsHcalFunctor

Public Member Functions

 HcalInterpolatedTableFunctor ()
 
 HcalInterpolatedTableFunctor (const std::vector< double > &values, double xmin, double xmax, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
 
HcalPiecewiseLinearFunctor inverse () const
 
bool isStrictlyMonotonous () const
 
double operator() (double x) const override
 
double xmax () const override
 
double xmin () const override
 
 ~HcalInterpolatedTableFunctor () 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

bool leftExtrapolationLinear_
 
bool rightExtrapolationLinear_
 
std::vector< double > values_
 
double xmax_
 
double xmin_
 

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 10 of file HcalInterpolatedTableFunctor.h.

Constructor & Destructor Documentation

◆ HcalInterpolatedTableFunctor() [1/2]

HcalInterpolatedTableFunctor::HcalInterpolatedTableFunctor ( )

◆ HcalInterpolatedTableFunctor() [2/2]

HcalInterpolatedTableFunctor::HcalInterpolatedTableFunctor ( const std::vector< double > &  values,
double  xmin,
double  xmax,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
)

Definition at line 14 of file HcalInterpolatedTableFunctor.cc.

References Exception, values_, xmax_, and xmin_.

19  : values_(values),
20  xmin_(ixmin),
21  xmax_(ixmax),
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 }

◆ ~HcalInterpolatedTableFunctor()

HcalInterpolatedTableFunctor::~HcalInterpolatedTableFunctor ( )
inlineoverride

Definition at line 32 of file HcalInterpolatedTableFunctor.h.

32 {}

Member Function Documentation

◆ inverse()

HcalPiecewiseLinearFunctor HcalInterpolatedTableFunctor::inverse ( ) const

Definition at line 64 of file HcalInterpolatedTableFunctor.cc.

References Exception, mps_fire::i, isStrictlyMonotonous(), MainPageGenerator::l, leftExtrapolationLinear_, hiPixelPairStep_cff::points, alignCSCRings::r, rightExtrapolationLinear_, edm::swap(), values_, x, xmax_, and xmin_.

64  {
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 }
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
step
Definition: StallMonitor.cc:83

◆ isEqual()

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

◆ isStrictlyMonotonous()

bool HcalInterpolatedTableFunctor::isStrictlyMonotonous ( ) const

Definition at line 60 of file HcalInterpolatedTableFunctor.cc.

References AbsHcalFunctor::isStrictlyDecreasing(), AbsHcalFunctor::isStrictlyIncreasing(), and values_.

Referenced by inverse().

60  {
61  return isStrictlyIncreasing(values_.begin(), values_.end()) || isStrictlyDecreasing(values_.begin(), values_.end());
62 }
static bool isStrictlyIncreasing(Iter begin, Iter const end)
static bool isStrictlyDecreasing(Iter begin, Iter const end)

◆ operator()()

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

Implements AbsHcalFunctor.

Definition at line 34 of file HcalInterpolatedTableFunctor.cc.

References interpolateStep(), leftExtrapolationLinear_, mps_fire::result, rightExtrapolationLinear_, values_, x, xmax_, and xmin_.

34  {
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 }
static double interpolateStep(const double x0, const double step, const double y0, const double y1, const double x)
step
Definition: StallMonitor.cc:83

◆ serialize()

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

◆ xmax()

double HcalInterpolatedTableFunctor::xmax ( ) const
inlineoverridevirtual

Reimplemented from AbsHcalFunctor.

Definition at line 36 of file HcalInterpolatedTableFunctor.h.

References xmax_.

Referenced by svgfig.XAxis::__repr__().

◆ xmin()

double HcalInterpolatedTableFunctor::xmin ( ) const
inlineoverridevirtual

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 60 of file HcalInterpolatedTableFunctor.h.

Member Data Documentation

◆ leftExtrapolationLinear_

bool HcalInterpolatedTableFunctor::leftExtrapolationLinear_
private

Definition at line 57 of file HcalInterpolatedTableFunctor.h.

Referenced by inverse(), isEqual(), operator()(), and serialize().

◆ rightExtrapolationLinear_

bool HcalInterpolatedTableFunctor::rightExtrapolationLinear_
private

Definition at line 58 of file HcalInterpolatedTableFunctor.h.

Referenced by inverse(), isEqual(), operator()(), and serialize().

◆ values_

std::vector<double> HcalInterpolatedTableFunctor::values_
private

◆ xmax_

double HcalInterpolatedTableFunctor::xmax_
private

◆ xmin_

double HcalInterpolatedTableFunctor::xmin_
private