Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CondFormats_HcalObjects_HcalPiecewiseLinearFunctor_h
0002 #define CondFormats_HcalObjects_HcalPiecewiseLinearFunctor_h
0003 
0004 #include <vector>
0005 #include <utility>
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 // Simple piecewise linear interpolator.
0015 // Will invert the curve if needed.
0016 //
0017 class HcalPiecewiseLinearFunctor : public AbsHcalFunctor {
0018 public:
0019   // Dummy constructor, to be used for deserialization only
0020   HcalPiecewiseLinearFunctor();
0021 
0022   // Abscissae are the first elements of the pairs.
0023   // Interpolated values are the second elements.
0024   // The order of the points is arbitrary -- they will
0025   // be sorted internally anyway in the order of
0026   // increasing abscissae.
0027   //
0028   // Argument "leftExtrapolationLinear" determines
0029   // whether the extrapolation to the left of the smallest
0030   // abscissa is going to be constant or linear.
0031   //
0032   // Argument "rightExtrapolationLinear" determines
0033   // whether the extrapolation to the right of the largest
0034   // abscissa is going to be constant or linear.
0035   //
0036   HcalPiecewiseLinearFunctor(const std::vector<std::pair<double, double> >& points,
0037                              bool leftExtrapolationLinear,
0038                              bool rightExtrapolationLinear);
0039 
0040   inline ~HcalPiecewiseLinearFunctor() override {}
0041 
0042   double operator()(double x) const override;
0043   double xmin() const override;
0044   double xmax() const override;
0045 
0046   // Check if the interpolated values are strictly increasing or decreasing
0047   bool isStrictlyMonotonous() const;
0048 
0049   // For strictly monotonous functors,
0050   // we will be able to generate the inverse
0051   HcalPiecewiseLinearFunctor inverse() const;
0052 
0053 protected:
0054   inline bool isEqual(const AbsHcalFunctor& other) const override {
0055     const HcalPiecewiseLinearFunctor& r = static_cast<const HcalPiecewiseLinearFunctor&>(other);
0056     return abscissae_ == r.abscissae_ && values_ == r.values_ &&
0057            leftExtrapolationLinear_ == r.leftExtrapolationLinear_ &&
0058            rightExtrapolationLinear_ == r.rightExtrapolationLinear_;
0059   }
0060 
0061 private:
0062   std::vector<double> abscissae_;
0063   std::vector<double> values_;
0064   bool leftExtrapolationLinear_;
0065   bool rightExtrapolationLinear_;
0066 
0067   friend class boost::serialization::access;
0068 
0069   template <class Archive>
0070   inline void serialize(Archive& ar, unsigned /* version */) {
0071     boost::serialization::base_object<AbsHcalFunctor>(*this);
0072     ar& abscissae_& values_& leftExtrapolationLinear_& rightExtrapolationLinear_;
0073   }
0074 };
0075 
0076 BOOST_CLASS_VERSION(HcalPiecewiseLinearFunctor, 1)
0077 BOOST_CLASS_EXPORT_KEY(HcalPiecewiseLinearFunctor)
0078 
0079 #endif  // CondFormats_HcalObjects_HcalPiecewiseLinearFunctor_h