Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:08

0001 #ifndef CondFormats_HcalObjects_HcalCubicInterpolator_h
0002 #define CondFormats_HcalObjects_HcalCubicInterpolator_h
0003 
0004 #include <vector>
0005 #include <tuple>
0006 
0007 #include "CondFormats/HcalObjects/interface/AbsHcalFunctor.h"
0008 
0009 #include "boost/serialization/access.hpp"
0010 #include "boost/serialization/version.hpp"
0011 #include "boost/serialization/vector.hpp"
0012 
0013 //
0014 // Cubic Hermite spline interpolator in 1-d. See, for example,
0015 // http://en.wikipedia.org/wiki/Cubic_Hermite_spline
0016 //
0017 class HcalCubicInterpolator : public AbsHcalFunctor {
0018 public:
0019   // Order: abscissa, desired value, derivative
0020   typedef std::tuple<double, double, double> Triple;
0021 
0022   // Dummy constructor, to be used for deserialization only
0023   HcalCubicInterpolator();
0024 
0025   // Normal constructor from the set of interpolated points.
0026   // The points will be sorted internally, so they can be
0027   // given in arbitrary order.
0028   explicit HcalCubicInterpolator(const std::vector<Triple>& points);
0029 
0030   inline ~HcalCubicInterpolator() override {}
0031 
0032   double operator()(double x) const override;
0033   double xmin() const override;
0034   double xmax() const override;
0035 
0036   // Cubic approximation to the inverse curve (note, not the real
0037   // solution of the direct cubic equation). Use at your own risc.
0038   HcalCubicInterpolator approximateInverse() const;
0039 
0040 protected:
0041   inline bool isEqual(const AbsHcalFunctor& other) const override {
0042     const HcalCubicInterpolator& r = static_cast<const HcalCubicInterpolator&>(other);
0043     return abscissae_ == r.abscissae_ && values_ == r.values_ && derivatives_ == r.derivatives_;
0044   }
0045 
0046 private:
0047   std::vector<double> abscissae_;
0048   std::vector<double> values_;
0049   std::vector<double> derivatives_;
0050 
0051   friend class boost::serialization::access;
0052 
0053   template <class Archive>
0054   inline void serialize(Archive& ar, unsigned /* version */) {
0055     boost::serialization::base_object<AbsHcalFunctor>(*this);
0056     ar& abscissae_& values_& derivatives_;
0057   }
0058 };
0059 
0060 BOOST_CLASS_VERSION(HcalCubicInterpolator, 1)
0061 BOOST_CLASS_EXPORT_KEY(HcalCubicInterpolator)
0062 
0063 #endif  // CondFormats_HcalObjects_HcalCubicInterpolator_h