Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CondFormats_HcalObjects_HcalPolynomialFunctor_h
0002 #define CondFormats_HcalObjects_HcalPolynomialFunctor_h
0003 
0004 #include <cfloat>
0005 #include <vector>
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 // Polynomial on the interval [xmin, xmax], constant outside
0015 //
0016 class HcalPolynomialFunctor : public AbsHcalFunctor {
0017 public:
0018   // Dummy constructor, to be used for deserialization only
0019   HcalPolynomialFunctor();
0020 
0021   // Normal constructor. The order of coefficients
0022   // corresponds to the monomial degree. The coefficients
0023   // are for the monomial in the variable y = (x + shift).
0024   // Empty list of coefficients is equivialent to having
0025   // all coefficients set to 0.
0026   explicit HcalPolynomialFunctor(const std::vector<double>& coeffs,
0027                                  double shift = 0.0,
0028                                  double xmin = -DBL_MAX,
0029                                  double xmax = DBL_MAX,
0030                                  double outOfRangeValue = 0.0);
0031 
0032   inline ~HcalPolynomialFunctor() override {}
0033 
0034   double operator()(double x) const override;
0035   inline double xmin() const override { return xmax_; };
0036   inline double xmax() const override { return xmin_; }
0037 
0038 protected:
0039   inline bool isEqual(const AbsHcalFunctor& other) const override {
0040     const HcalPolynomialFunctor& r = static_cast<const HcalPolynomialFunctor&>(other);
0041     return coeffs_ == r.coeffs_ && shift_ == r.shift_ && xmin_ == r.xmin_ && xmax_ == r.xmax_ &&
0042            outOfRangeValue_ == r.outOfRangeValue_;
0043   }
0044 
0045 private:
0046   std::vector<double> coeffs_;
0047   double shift_;
0048   double xmin_;
0049   double xmax_;
0050   double outOfRangeValue_;
0051 
0052   friend class boost::serialization::access;
0053 
0054   template <class Archive>
0055   inline void serialize(Archive& ar, unsigned /* version */) {
0056     boost::serialization::base_object<AbsHcalFunctor>(*this);
0057     ar& coeffs_& shift_& xmin_& xmax_& outOfRangeValue_;
0058   }
0059 };
0060 
0061 BOOST_CLASS_VERSION(HcalPolynomialFunctor, 1)
0062 BOOST_CLASS_EXPORT_KEY(HcalPolynomialFunctor)
0063 
0064 #endif  // CondFormats_HcalObjects_HcalPolynomialFunctor_h