CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 public:
19  // Dummy constructor, to be used for deserialization only
21 
22  // Abscissae are the first elements of the pairs.
23  // Interpolated values are the second elements.
24  // The order of the points is arbitrary -- they will
25  // be sorted internally anyway in the order of
26  // increasing abscissae.
27  //
28  // Argument "leftExtrapolationLinear" determines
29  // whether the extrapolation to the left of the smallest
30  // abscissa is going to be constant or linear.
31  //
32  // Argument "rightExtrapolationLinear" determines
33  // whether the extrapolation to the right of the largest
34  // abscissa is going to be constant or linear.
35  //
36  HcalPiecewiseLinearFunctor(const std::vector<std::pair<double, double> >& points,
37  bool leftExtrapolationLinear,
38  bool rightExtrapolationLinear);
39 
40  inline ~HcalPiecewiseLinearFunctor() override {}
41 
42  double operator()(double x) const override;
43  double xmin() const override;
44  double xmax() const override;
45 
46  // Check if the interpolated values are strictly increasing or decreasing
47  bool isStrictlyMonotonous() const;
48 
49  // For strictly monotonous functors,
50  // we will be able to generate the inverse
52 
53 protected:
54  inline bool isEqual(const AbsHcalFunctor& other) const override {
55  const HcalPiecewiseLinearFunctor& r = static_cast<const HcalPiecewiseLinearFunctor&>(other);
56  return abscissae_ == r.abscissae_ && values_ == r.values_ &&
59  }
60 
61 private:
62  std::vector<double> abscissae_;
63  std::vector<double> values_;
66 
68 
69  template <class Archive>
70  inline void serialize(Archive& ar, unsigned /* version */) {
71  boost::serialization::base_object<AbsHcalFunctor>(*this);
73  }
74 };
75 
76 BOOST_CLASS_VERSION(HcalPiecewiseLinearFunctor, 1)
77 BOOST_CLASS_EXPORT_KEY(HcalPiecewiseLinearFunctor)
78 
79 #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