CMS 3D CMS Logo

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
 
virtual double operator() (double x) const override
 
virtual double xmax () const override
 
virtual double xmin () const override
 
virtual ~HcalPiecewiseLinearFunctor ()
 
- 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_
 
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 19 of file HcalPiecewiseLinearFunctor.cc.

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

25 {
26  const std::size_t sz = points.size();
27  if (sz)
28  {
29  std::vector<std::pair<double, double> > tmp(points);
30  std::sort(tmp.begin(), tmp.end());
31  abscissae_.reserve(sz);
32  values_.reserve(sz);
33  for (std::size_t i=0; i<sz; ++i)
34  {
35  abscissae_.push_back(tmp[i].first);
36  values_.push_back(tmp[i].second);
37  }
38  if (!isStrictlyIncreasing(abscissae_.begin(), abscissae_.end()))
39  throw cms::Exception("In HcalPiecewiseLinearFunctor constructor:"
40  " abscissae must not coincide");
41  }
42 }
static bool isStrictlyIncreasing(Iter begin, Iter const end)
U second(std::pair< T, U > const &p)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
virtual HcalPiecewiseLinearFunctor::~HcalPiecewiseLinearFunctor ( )
inlinevirtual

Definition at line 41 of file HcalPiecewiseLinearFunctor.h.

References inverse(), isStrictlyMonotonous(), operator()(), x, xmax(), and xmin().

41 {}

Member Function Documentation

HcalPiecewiseLinearFunctor HcalPiecewiseLinearFunctor::inverse ( ) const

Definition at line 89 of file HcalPiecewiseLinearFunctor.cc.

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

Referenced by ~HcalPiecewiseLinearFunctor().

90 {
91  if (!isStrictlyMonotonous())
92  throw cms::Exception("In HcalPiecewiseLinearFunctor::inverse:"
93  " can't invert non-monotonous functor");
94  const std::size_t sz = abscissae_.size();
95  std::vector<std::pair<double, double> > points;
96  points.reserve(sz);
97  for (std::size_t i=0; i<sz; ++i)
98  points.push_back(std::make_pair(values_[i], abscissae_[i]));
101  if (values_[0] > values_[sz - 1])
102  std::swap(l, r);
103  return HcalPiecewiseLinearFunctor(points, l, r);
104 }
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
virtual bool HcalPiecewiseLinearFunctor::isEqual ( const AbsHcalFunctor other) const
inlineoverrideprotectedvirtual
bool HcalPiecewiseLinearFunctor::isStrictlyMonotonous ( ) const

Definition at line 83 of file HcalPiecewiseLinearFunctor.cc.

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

Referenced by inverse(), and ~HcalPiecewiseLinearFunctor().

84 {
85  return isStrictlyIncreasing(values_.begin(), values_.end()) ||
86  isStrictlyDecreasing(values_.begin(), values_.end());
87 }
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 44 of file HcalPiecewiseLinearFunctor.cc.

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

Referenced by ~HcalPiecewiseLinearFunctor().

45 {
46  double result = 0.0;
47  const std::size_t sz = abscissae_.size();
48  if (sz)
49  {
50  if (sz > 1)
51  {
52  const std::size_t szm1 = sz - 1;
53  if (x >= abscissae_[szm1])
54  {
56  result = interpolateSimple(abscissae_[sz-2], abscissae_[szm1],
57  values_[sz-2], values_[szm1], x);
58  else
59  result = values_[szm1];
60  }
61  else if (x <= abscissae_[0])
62  {
64  result = interpolateSimple(abscissae_[0], abscissae_[1],
65  values_[0], values_[1], x);
66  else
67  result = values_[0];
68  }
69  else
70  {
71  const std::size_t cell = std::upper_bound(abscissae_.begin(), abscissae_.end(), x) -
72  abscissae_.begin() - 1;
73  result = interpolateSimple(abscissae_[cell], abscissae_[cell+1],
74  values_[cell], values_[cell+1], x);
75  }
76  }
77  else
78  result = values_[0];
79  }
80  return result;
81 }
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 74 of file HcalPiecewiseLinearFunctor.h.

References rightExtrapolationLinear_.

75  {
76  boost::serialization::base_object<AbsHcalFunctor>(*this);
77  ar & abscissae_
78  & values_
81  }
double HcalPiecewiseLinearFunctor::xmax ( ) const
overridevirtual

Reimplemented from AbsHcalFunctor.

Definition at line 114 of file HcalPiecewiseLinearFunctor.cc.

References abscissae_, and mps_fire::result.

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

115 {
116  double result = 0.0;
117  if (!abscissae_.empty())
118  result = abscissae_.back();
119  return result;
120 }
double HcalPiecewiseLinearFunctor::xmin ( ) const
overridevirtual

Reimplemented from AbsHcalFunctor.

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

107 {
108  double result = 0.0;
109  if (!abscissae_.empty())
110  result = abscissae_[0];
111  return result;
112 }

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 71 of file HcalPiecewiseLinearFunctor.h.

Member Data Documentation

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

Definition at line 68 of file HcalPiecewiseLinearFunctor.h.

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

bool HcalPiecewiseLinearFunctor::rightExtrapolationLinear_
private

Definition at line 69 of file HcalPiecewiseLinearFunctor.h.

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

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