CMS 3D CMS Logo

PiecewiseScalingPolynomial.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_PiecewiseScalingPolynomial_h_
2 #define CondFormats_HcalObjects_PiecewiseScalingPolynomial_h_
3 
5 
6 #include "boost/serialization/vector.hpp"
7 #include "boost/serialization/version.hpp"
8 
9 #include <vector>
10 
12 public:
14 
15  PiecewiseScalingPolynomial(const std::vector<std::vector<double> >& coeffs, const std::vector<double>& limits);
16 
17  inline double operator()(const double x) const {
18  double scale(0.0);
19  if (x > 0.0) {
20  const unsigned nLimits(limits_.size());
21  if (nLimits) {
22  const double* limits(&limits_[0]);
23  unsigned which(0U);
24  for (; which < nLimits; ++which)
25  if (x < limits[which])
26  break;
27  const std::vector<double>& c(coeffs_[which]);
28  const double* a = &c[0];
29  for (int deg = c.size() - 1; deg >= 0; --deg) {
30  scale *= x;
31  scale += a[deg];
32  }
33  }
34  }
35  return scale * x;
36  }
37 
38  inline bool operator==(const PiecewiseScalingPolynomial& r) const {
39  return coeffs_ == r.coeffs_ && limits_ == r.limits_;
40  }
41 
42  inline bool operator!=(const PiecewiseScalingPolynomial& r) const { return !(*this == r); }
43 
44 private:
45  bool validate() const;
46 
47  std::vector<std::vector<double> > coeffs_;
48  std::vector<double> limits_;
49 
51 
52  template <class Archive>
53  inline void save(Archive& ar, const unsigned /* version */) const {
54  if (!validate())
55  throw cms::Exception("In PiecewiseScalingPolynomial::save: invalid data");
56  ar& coeffs_& limits_;
57  }
58 
59  template <class Archive>
60  inline void load(Archive& ar, const unsigned /* version */) {
61  ar& coeffs_& limits_;
62  if (!validate())
63  throw cms::Exception("In PiecewiseScalingPolynomial::load: invalid data");
64  }
65 
66  BOOST_SERIALIZATION_SPLIT_MEMBER()
67 };
68 
69 BOOST_CLASS_VERSION(PiecewiseScalingPolynomial, 1)
70 
71 #endif // CondFormats_HcalObjects_PiecewiseScalingPolynomial_h_
PiecewiseScalingPolynomial::save
void save(Archive &ar, const unsigned) const
Definition: PiecewiseScalingPolynomial.h:53
L1EGammaCrystalsEmulatorProducer_cfi.scale
scale
Definition: L1EGammaCrystalsEmulatorProducer_cfi.py:10
PiecewiseScalingPolynomial::access
friend class boost::serialization::access
Definition: PiecewiseScalingPolynomial.h:50
PiecewiseScalingPolynomial::load
void load(Archive &ar, const unsigned)
Definition: PiecewiseScalingPolynomial.h:60
DDAxes::x
PiecewiseScalingPolynomial::PiecewiseScalingPolynomial
PiecewiseScalingPolynomial()
Definition: PiecewiseScalingPolynomial.h:13
PiecewiseScalingPolynomial::operator!=
bool operator!=(const PiecewiseScalingPolynomial &r) const
Definition: PiecewiseScalingPolynomial.h:42
PiecewiseScalingPolynomial
Definition: PiecewiseScalingPolynomial.h:11
PiecewiseScalingPolynomial::operator==
bool operator==(const PiecewiseScalingPolynomial &r) const
Definition: PiecewiseScalingPolynomial.h:38
PiecewiseScalingPolynomial::limits_
std::vector< double > limits_
Definition: PiecewiseScalingPolynomial.h:48
PiecewiseScalingPolynomial::operator()
double operator()(const double x) const
Definition: PiecewiseScalingPolynomial.h:17
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
a
double a
Definition: hdecay.h:119
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
PiecewiseScalingPolynomial::validate
bool validate() const
Definition: PiecewiseScalingPolynomial.cc:12
alignCSCRings.r
r
Definition: alignCSCRings.py:93
TH2PolyOfflineMaps.limits
limits
Definition: TH2PolyOfflineMaps.py:45
Exception
Definition: hltDiff.cc:245
Exception.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
PiecewiseScalingPolynomial::coeffs_
std::vector< std::vector< double > > coeffs_
Definition: PiecewiseScalingPolynomial.h:47
eostools.which
def which(cmd)
Definition: eostools.py:336