Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:38

0001 #ifndef CondFormats_HcalObjects_HcalInterpolatedTableFunctor_h
0002 #define CondFormats_HcalObjects_HcalInterpolatedTableFunctor_h
0003 
0004 #include "CondFormats/HcalObjects/interface/HcalPiecewiseLinearFunctor.h"
0005 
0006 //
0007 // Simple linear interpolator from equidistant points.
0008 // Need O(1) operations no matter how many points are used.
0009 //
0010 class HcalInterpolatedTableFunctor : public AbsHcalFunctor {
0011 public:
0012   // Dummy constructor, to be used for deserialization only
0013   HcalInterpolatedTableFunctor();
0014 
0015   // The vector of values must have at least two elements
0016   // (for xmin and xmax).
0017   //
0018   // Argument "leftExtrapolationLinear" determines
0019   // whether the extrapolation to the left of xmin
0020   // is going to be constant or linear.
0021   //
0022   // Argument "rightExtrapolationLinear" determines
0023   // whether the extrapolation to the right of xmax
0024   // is going to be constant or linear.
0025   //
0026   HcalInterpolatedTableFunctor(const std::vector<double>& values,
0027                                double xmin,
0028                                double xmax,
0029                                bool leftExtrapolationLinear,
0030                                bool rightExtrapolationLinear);
0031 
0032   inline ~HcalInterpolatedTableFunctor() override {}
0033 
0034   double operator()(double x) const override;
0035   inline double xmin() const override { return xmin_; }
0036   inline double xmax() const override { return xmax_; }
0037 
0038   // Check if the interpolated values are strictly increasing or decreasing
0039   bool isStrictlyMonotonous() const;
0040 
0041   // For strictly monotonous functors,
0042   // we will be able to generate the inverse
0043   HcalPiecewiseLinearFunctor inverse() const;
0044 
0045 protected:
0046   inline bool isEqual(const AbsHcalFunctor& other) const override {
0047     const HcalInterpolatedTableFunctor& r = static_cast<const HcalInterpolatedTableFunctor&>(other);
0048     return values_ == r.values_ && xmin_ == r.xmin_ && xmax_ == r.xmax_ &&
0049            leftExtrapolationLinear_ == r.leftExtrapolationLinear_ &&
0050            rightExtrapolationLinear_ == r.rightExtrapolationLinear_;
0051   }
0052 
0053 private:
0054   std::vector<double> values_;
0055   double xmin_;
0056   double xmax_;
0057   bool leftExtrapolationLinear_;
0058   bool rightExtrapolationLinear_;
0059 
0060   friend class boost::serialization::access;
0061 
0062   template <class Archive>
0063   inline void serialize(Archive& ar, unsigned /* version */) {
0064     boost::serialization::base_object<AbsHcalFunctor>(*this);
0065     ar & values_ & xmin_ & xmax_ & leftExtrapolationLinear_ & rightExtrapolationLinear_;
0066   }
0067 };
0068 
0069 BOOST_CLASS_VERSION(HcalInterpolatedTableFunctor, 1)
0070 BOOST_CLASS_EXPORT_KEY(HcalInterpolatedTableFunctor)
0071 
0072 #endif  // CondFormats_HcalObjects_HcalInterpolatedTableFunctor_h