Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CondFormats_HcalObjects_ScalingExponential_h_
0002 #define CondFormats_HcalObjects_ScalingExponential_h_
0003 
0004 #include <cmath>
0005 
0006 #include "boost/serialization/access.hpp"
0007 #include "boost/serialization/version.hpp"
0008 #include <cstdint>
0009 
0010 class ScalingExponential {
0011 public:
0012   inline ScalingExponential() : p0_(0.0), p1_(0.0), linear_(0) {}
0013 
0014   inline ScalingExponential(const double p0, const double p1, const bool isLinear = false)
0015       : p0_(p0), p1_(p1), linear_(isLinear) {}
0016 
0017   inline double operator()(const double x) const {
0018     const double scale = linear_ ? p0_ * x + p1_ : p0_ * (1.0 - exp(-x / p1_));
0019     return scale * x;
0020   }
0021 
0022   inline bool operator==(const ScalingExponential& r) const {
0023     return p0_ == r.p0_ && p1_ == r.p1_ && linear_ == r.linear_;
0024   }
0025 
0026   inline bool operator!=(const ScalingExponential& r) const { return !(*this == r); }
0027 
0028 private:
0029   double p0_;
0030   double p1_;
0031   uint8_t linear_;
0032 
0033   friend class boost::serialization::access;
0034 
0035   template <class Archive>
0036   inline void serialize(Archive& ar, unsigned /* version */) {
0037     ar& p0_& p1_& linear_;
0038   }
0039 };
0040 
0041 BOOST_CLASS_VERSION(ScalingExponential, 1)
0042 
0043 #endif  // CondFormats_HcalObjects_ScalingExponential_h_