CMS 3D CMS Logo

HcalPiecewiseLinearFunctor.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_HcalPiecewiseLinearFunctor_h
2 #define CondFormats_HcalObjects_HcalPiecewiseLinearFunctor_h
3 
4 #include <vector>
5 #include <utility>
6 
8 
9 #include "boost/serialization/access.hpp"
10 #include "boost/serialization/version.hpp"
11 #include "boost/serialization/vector.hpp"
12 
13 //
14 // Simple piecewise linear interpolator.
15 // Will invert the curve if needed.
16 //
18 {
19 public:
20  // Dummy constructor, to be used for deserialization only
22 
23  // Abscissae are the first elements of the pairs.
24  // Interpolated values are the second elements.
25  // The order of the points is arbitrary -- they will
26  // be sorted internally anyway in the order of
27  // increasing abscissae.
28  //
29  // Argument "leftExtrapolationLinear" determines
30  // whether the extrapolation to the left of the smallest
31  // abscissa is going to be constant or linear.
32  //
33  // Argument "rightExtrapolationLinear" determines
34  // whether the extrapolation to the right of the largest
35  // abscissa is going to be constant or linear.
36  //
37  HcalPiecewiseLinearFunctor(const std::vector<std::pair<double, double> >& points,
40 
41  inline ~HcalPiecewiseLinearFunctor() override {}
42 
43  double operator()(double x) const override;
44  double xmin() const override;
45  double xmax() const override;
46 
47  // Check if the interpolated values are strictly increasing or decreasing
48  bool isStrictlyMonotonous() const;
49 
50  // For strictly monotonous functors,
51  // we will be able to generate the inverse
53 
54 protected:
55  inline bool isEqual(const AbsHcalFunctor& other) const override
56  {
58  static_cast<const HcalPiecewiseLinearFunctor&>(other);
59  return abscissae_ == r.abscissae_ &&
60  values_ == r.values_ &&
63  }
64 
65 private:
66  std::vector<double> abscissae_;
67  std::vector<double> values_;
70 
72 
73  template<class Archive>
74  inline void serialize(Archive & ar, unsigned /* version */)
75  {
76  boost::serialization::base_object<AbsHcalFunctor>(*this);
77  ar & abscissae_
78  & values_
79  & leftExtrapolationLinear_
81  }
82 };
83 
84 BOOST_CLASS_VERSION(HcalPiecewiseLinearFunctor, 1)
85 BOOST_CLASS_EXPORT_KEY(HcalPiecewiseLinearFunctor)
86 
87 #endif // CondFormats_HcalObjects_HcalPiecewiseLinearFunctor_h
double operator()(double x) const override
friend class boost::serialization::access
void serialize(Archive &ar, unsigned)
HcalPiecewiseLinearFunctor inverse() const
bool isEqual(const AbsHcalFunctor &other) const override