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
 
virtual double operator() (double x) const override
 
virtual double xmax () const override
 
virtual double xmin () const override
 
virtual ~HcalInterpolatedTableFunctor ()
 
- 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

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::HcalInterpolatedTableFunctor ( )
HcalInterpolatedTableFunctor::HcalInterpolatedTableFunctor ( const std::vector< double > &  values,
double  xmin,
double  xmax,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
)

Definition at line 20 of file HcalInterpolatedTableFunctor.cc.

References Exception, values_, xmax_, and xmin_.

25  : values_(values),
26  xmin_(ixmin),
27  xmax_(ixmax),
30 {
31  if (values_.size() < 2)
32  throw cms::Exception("In HcalInterpolatedTableFunctor constructor:"
33  " insufficient number of points");
34  if (xmin_ >= xmax_)
35  throw cms::Exception("In HcalInterpolatedTableFunctor constructor:"
36  " invalid min and/or max coordinates");
37 }
virtual HcalInterpolatedTableFunctor::~HcalInterpolatedTableFunctor ( )
inlinevirtual

Definition at line 32 of file HcalInterpolatedTableFunctor.h.

References operator()(), and x.

32 {}

Member Function Documentation

HcalPiecewiseLinearFunctor HcalInterpolatedTableFunctor::inverse ( ) const

Definition at line 79 of file HcalInterpolatedTableFunctor.cc.

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

Referenced by xmax().

80 {
81  if (!isStrictlyMonotonous())
82  throw cms::Exception("In HcalInterpolatedTableFunctor::inverse:"
83  " can't invert non-monotonous functor");
84  const std::size_t sz = values_.size();
85  const std::size_t szm1 = sz - 1;
86  const double step = (xmax_ - xmin_)/szm1;
87  std::vector<std::pair<double, double> > points;
88  points.reserve(sz);
89  for (std::size_t i=0; i<sz; ++i)
90  {
91  const double x = (i == szm1 ? xmax_ : xmin_ + step*i);
92  points.push_back(std::make_pair(values_[i], x));
93  }
96  if (values_[0] > values_[sz - 1])
97  std::swap(l, r);
98  return HcalPiecewiseLinearFunctor(points, l, r);
99 }
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
step
virtual bool HcalInterpolatedTableFunctor::isEqual ( const AbsHcalFunctor other) const
inlineoverrideprotectedvirtual
bool HcalInterpolatedTableFunctor::isStrictlyMonotonous ( ) const

Definition at line 73 of file HcalInterpolatedTableFunctor.cc.

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

Referenced by inverse(), and xmax().

74 {
75  return isStrictlyIncreasing(values_.begin(), values_.end()) ||
76  isStrictlyDecreasing(values_.begin(), values_.end());
77 }
static bool isStrictlyIncreasing(Iter begin, Iter const end)
static bool isStrictlyDecreasing(Iter begin, Iter const end)
double HcalInterpolatedTableFunctor::operator() ( double  x) const
overridevirtual

Implements AbsHcalFunctor.

Definition at line 39 of file HcalInterpolatedTableFunctor.cc.

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

Referenced by ~HcalInterpolatedTableFunctor().

40 {
41  double result = 0.0;
42  const std::size_t sz = values_.size();
43  const std::size_t szm1 = sz - 1;
44  const double step = (xmax_ - xmin_)/szm1;
45 
46  if (x >= xmax_)
47  {
49  result = interpolateStep(xmax_ - step, step,
50  values_[sz-2], values_[szm1], x);
51  else
52  result = values_[szm1];
53  }
54  else if (x <= xmin_)
55  {
57  result = interpolateStep(xmin_, step, values_[0], values_[1], x);
58  else
59  result = values_[0];
60  }
61  else
62  {
63  const std::size_t ux = static_cast<std::size_t>((x - xmin_)/step);
64  if (ux >= szm1)
65  return values_[szm1];
66  result = interpolateStep(ux*step + xmin_, step,
67  values_[ux], values_[ux+1], x);
68  }
69 
70  return result;
71 }
static double interpolateStep(const double x0, const double step, const double y0, const double y1, const double x)
step
template<class Archive >
void HcalInterpolatedTableFunctor::serialize ( Archive &  ar,
unsigned   
)
inlineprivate
virtual double HcalInterpolatedTableFunctor::xmax ( ) const
inlineoverridevirtual

Reimplemented from AbsHcalFunctor.

Definition at line 36 of file HcalInterpolatedTableFunctor.h.

References inverse(), isStrictlyMonotonous(), and xmax_.

Referenced by svgfig.XAxis::__repr__().

virtual double HcalInterpolatedTableFunctor::xmin ( ) const
inlineoverridevirtual

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 63 of file HcalInterpolatedTableFunctor.h.

Member Data Documentation

bool HcalInterpolatedTableFunctor::leftExtrapolationLinear_
private

Definition at line 60 of file HcalInterpolatedTableFunctor.h.

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

bool HcalInterpolatedTableFunctor::rightExtrapolationLinear_
private

Definition at line 61 of file HcalInterpolatedTableFunctor.h.

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

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