CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends
HcalPiecewiseLinearFunctor Class Reference

#include <HcalPiecewiseLinearFunctor.h>

Inheritance diagram for HcalPiecewiseLinearFunctor:
AbsHcalFunctor

Public Member Functions

 HcalPiecewiseLinearFunctor ()
 
 HcalPiecewiseLinearFunctor (const std::vector< std::pair< double, double > > &points, bool leftExtrapolationLinear, bool rightExtrapolationLinear)
 
HcalPiecewiseLinearFunctor inverse () const
 
bool isStrictlyMonotonous () const
 
double operator() (double x) const override
 
double xmax () const override
 
double xmin () const override
 
 ~HcalPiecewiseLinearFunctor () 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_
 
bool leftExtrapolationLinear_
 
bool rightExtrapolationLinear_
 
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 HcalPiecewiseLinearFunctor.h.

Constructor & Destructor Documentation

HcalPiecewiseLinearFunctor::HcalPiecewiseLinearFunctor ( )
HcalPiecewiseLinearFunctor::HcalPiecewiseLinearFunctor ( const std::vector< std::pair< double, double > > &  points,
bool  leftExtrapolationLinear,
bool  rightExtrapolationLinear 
)

Definition at line 14 of file HcalPiecewiseLinearFunctor.cc.

References abscissae_, Exception, first, mps_fire::i, AbsHcalFunctor::isStrictlyIncreasing(), edm::second(), createJobs::tmp, and values_.

17  : leftExtrapolationLinear_(leftExtrapolationLinear), rightExtrapolationLinear_(rightExtrapolationLinear) {
18  const std::size_t sz = points.size();
19  if (sz) {
20  std::vector<std::pair<double, double> > tmp(points);
21  std::sort(tmp.begin(), tmp.end());
22  abscissae_.reserve(sz);
23  values_.reserve(sz);
24  for (std::size_t i = 0; i < sz; ++i) {
25  abscissae_.push_back(tmp[i].first);
26  values_.push_back(tmp[i].second);
27  }
28  if (!isStrictlyIncreasing(abscissae_.begin(), abscissae_.end()))
29  throw cms::Exception(
30  "In HcalPiecewiseLinearFunctor constructor:"
31  " abscissae must not coincide");
32  }
33 }
static bool isStrictlyIncreasing(Iter begin, Iter const end)
U second(std::pair< T, U > const &p)
tmp
align.sh
Definition: createJobs.py:716
HcalPiecewiseLinearFunctor::~HcalPiecewiseLinearFunctor ( )
inlineoverride

Definition at line 40 of file HcalPiecewiseLinearFunctor.h.

40 {}

Member Function Documentation

HcalPiecewiseLinearFunctor HcalPiecewiseLinearFunctor::inverse ( ) const

Definition at line 65 of file HcalPiecewiseLinearFunctor.cc.

References abscissae_, Exception, HcalPiecewiseLinearFunctor(), mps_fire::i, isStrictlyMonotonous(), cmsLHEtoEOSManager::l, leftExtrapolationLinear_, alignCSCRings::r, rightExtrapolationLinear_, std::swap(), and values_.

65  {
66  if (!isStrictlyMonotonous())
67  throw cms::Exception(
68  "In HcalPiecewiseLinearFunctor::inverse:"
69  " can't invert non-monotonous functor");
70  const std::size_t sz = abscissae_.size();
71  std::vector<std::pair<double, double> > points;
72  points.reserve(sz);
73  for (std::size_t i = 0; i < sz; ++i)
74  points.push_back(std::make_pair(values_[i], abscissae_[i]));
77  if (values_[0] > values_[sz - 1])
78  std::swap(l, r);
79  return HcalPiecewiseLinearFunctor(points, l, r);
80 }
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
bool HcalPiecewiseLinearFunctor::isEqual ( const AbsHcalFunctor other) const
inlineoverrideprotectedvirtual
bool HcalPiecewiseLinearFunctor::isStrictlyMonotonous ( ) const

Definition at line 61 of file HcalPiecewiseLinearFunctor.cc.

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

Referenced by inverse().

61  {
62  return isStrictlyIncreasing(values_.begin(), values_.end()) || isStrictlyDecreasing(values_.begin(), values_.end());
63 }
static bool isStrictlyIncreasing(Iter begin, Iter const end)
static bool isStrictlyDecreasing(Iter begin, Iter const end)
double HcalPiecewiseLinearFunctor::operator() ( double  x) const
overridevirtual

Implements AbsHcalFunctor.

Definition at line 35 of file HcalPiecewiseLinearFunctor.cc.

References abscissae_, interpolateSimple(), leftExtrapolationLinear_, mps_fire::result, rightExtrapolationLinear_, cuda_std::upper_bound(), values_, and x.

35  {
36  double result = 0.0;
37  const std::size_t sz = abscissae_.size();
38  if (sz) {
39  if (sz > 1) {
40  const std::size_t szm1 = sz - 1;
41  if (x >= abscissae_[szm1]) {
43  result = interpolateSimple(abscissae_[sz - 2], abscissae_[szm1], values_[sz - 2], values_[szm1], x);
44  else
45  result = values_[szm1];
46  } else if (x <= abscissae_[0]) {
48  result = interpolateSimple(abscissae_[0], abscissae_[1], values_[0], values_[1], x);
49  else
50  result = values_[0];
51  } else {
52  const std::size_t cell = std::upper_bound(abscissae_.begin(), abscissae_.end(), x) - abscissae_.begin() - 1;
53  result = interpolateSimple(abscissae_[cell], abscissae_[cell + 1], values_[cell], values_[cell + 1], x);
54  }
55  } else
56  result = values_[0];
57  }
58  return result;
59 }
__host__ __device__ constexpr RandomIt upper_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
tuple result
Definition: mps_fire.py:311
static double interpolateSimple(const double x0, const double x1, const double y0, const double y1, const double x)
template<class Archive >
void HcalPiecewiseLinearFunctor::serialize ( Archive &  ar,
unsigned   
)
inlineprivate

Definition at line 70 of file HcalPiecewiseLinearFunctor.h.

References abscissae_, leftExtrapolationLinear_, rightExtrapolationLinear_, and values_.

70  {
71  boost::serialization::base_object<AbsHcalFunctor>(*this);
73  }
double HcalPiecewiseLinearFunctor::xmax ( ) const
overridevirtual

Reimplemented from AbsHcalFunctor.

Definition at line 89 of file HcalPiecewiseLinearFunctor.cc.

References abscissae_, and mps_fire::result.

Referenced by svgfig.XAxis::__repr__().

89  {
90  double result = 0.0;
91  if (!abscissae_.empty())
92  result = abscissae_.back();
93  return result;
94 }
tuple result
Definition: mps_fire.py:311
double HcalPiecewiseLinearFunctor::xmin ( ) const
overridevirtual

Reimplemented from AbsHcalFunctor.

Definition at line 82 of file HcalPiecewiseLinearFunctor.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().

82  {
83  double result = 0.0;
84  if (!abscissae_.empty())
85  result = abscissae_[0];
86  return result;
87 }
tuple result
Definition: mps_fire.py:311

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 67 of file HcalPiecewiseLinearFunctor.h.

Member Data Documentation

std::vector<double> HcalPiecewiseLinearFunctor::abscissae_
private
bool HcalPiecewiseLinearFunctor::leftExtrapolationLinear_
private

Definition at line 64 of file HcalPiecewiseLinearFunctor.h.

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

bool HcalPiecewiseLinearFunctor::rightExtrapolationLinear_
private

Definition at line 65 of file HcalPiecewiseLinearFunctor.h.

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

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