CMS 3D CMS Logo

Polynomial.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_Utilities_Polynomial_h
2 #define PhysicsTools_Utilities_Polynomial_h
4 
5 namespace funct {
6  template <unsigned int n>
7  class Polynomial {
8  public:
9  Polynomial(const double *c);
10  Polynomial(const std::shared_ptr<double> *c);
11  Polynomial(const Parameter *p);
12  double operator()(double x) const;
13 
14  private:
15  std::shared_ptr<double> c0_;
17  };
18 
19  template <unsigned int n>
20  Polynomial<n>::Polynomial(const std::shared_ptr<double> *c) : c0_(*c), poly_(c + 1) {}
21  template <unsigned int n>
22  Polynomial<n>::Polynomial(const Parameter *c) : c0_(c->ptr()), poly_(c + 1) {}
23 
24  template <unsigned int n>
25  Polynomial<n>::Polynomial(const double *c) : c0_(new double(*c)), poly_(c + 1) {}
26 
27  template <unsigned int n>
28  double Polynomial<n>::operator()(double x) const {
29  return *c0_ + x * poly_(x);
30  }
31 
32  template <>
33  class Polynomial<0> {
34  public:
35  Polynomial(const std::shared_ptr<double> *c) : c0_(*c) {}
36  Polynomial(const Parameter *c) : c0_(c->ptr()) {}
37  Polynomial(const double *c) : c0_(new double(*c)) {}
38  Polynomial(std::shared_ptr<double> c0) : c0_(c0) {}
39  Polynomial(const Parameter &c0) : c0_(c0.ptr()) {}
40  Polynomial(double c0) : c0_(new double(c0)) {}
41  double operator()(double x) const { return *c0_; }
42  double operator()() const { return *c0_; }
43 
44  private:
45  std::shared_ptr<double> c0_;
46  };
47 
48  template <>
49  class Polynomial<1> {
50  public:
51  Polynomial(const std::shared_ptr<double> *c) : c0_(*c), poly_(c + 1) {}
52  Polynomial(const Parameter *c) : c0_(c->ptr()), poly_(c + 1) {}
53  Polynomial(const double *c) : c0_(new double(*c)), poly_(c + 1) {}
54  Polynomial(std::shared_ptr<double> c0, std::shared_ptr<double> c1) : c0_(c0), poly_(c1) {}
55  Polynomial(const Parameter &c0, const Parameter &c1) : c0_(c0.ptr()), poly_(c1.ptr()) {}
56  Polynomial(double c0, double c1) : c0_(new double(c0)), poly_(c1) {}
57  double operator()(double x) const { return *c0_ + x * poly_(x); }
58 
59  private:
60  std::shared_ptr<double> c0_;
62  };
63 
64  template <>
65  class Polynomial<2> {
66  public:
67  Polynomial(const std::shared_ptr<double> *c) : c0_(*c), poly_(c + 1) {}
68  Polynomial(const Parameter *c) : c0_(c->ptr()), poly_(c + 1) {}
69  Polynomial(const double *c) : c0_(new double(*c)), poly_(c + 1) {}
70  Polynomial(std::shared_ptr<double> c0, std::shared_ptr<double> c1, std::shared_ptr<double> c2)
71  : c0_(c0), poly_(c1, c2) {}
72  Polynomial(const Parameter &c0, const Parameter &c1, const Parameter &c2) : c0_(c0.ptr()), poly_(c1, c2) {}
73  Polynomial(double c0, double c1, double c2) : c0_(new double(c0)), poly_(c1, c2) {}
74  double operator()(double x) const { return *c0_ + x * poly_(x); }
75 
76  private:
77  std::shared_ptr<double> c0_;
79  };
80 } // namespace funct
81 
82 #endif
funct::Polynomial< 2 >::Polynomial
Polynomial(std::shared_ptr< double > c0, std::shared_ptr< double > c1, std::shared_ptr< double > c2)
Definition: Polynomial.h:70
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
funct::Polynomial< 2 >::poly_
Polynomial< 1 > poly_
Definition: Polynomial.h:78
funct::Polynomial< 0 >::Polynomial
Polynomial(const Parameter *c)
Definition: Polynomial.h:36
funct::Polynomial< 1 >::Polynomial
Polynomial(const Parameter *c)
Definition: Polynomial.h:52
funct::Polynomial< 1 >::Polynomial
Polynomial(const double *c)
Definition: Polynomial.h:53
funct::Polynomial< 0 >::c0_
std::shared_ptr< double > c0_
Definition: Polynomial.h:45
funct::Parameter
Definition: Parameter.h:8
funct::Polynomial< 0 >
Definition: Polynomial.h:33
funct::Polynomial< 0 >::operator()
double operator()() const
Definition: Polynomial.h:42
funct::Polynomial< 1 >::operator()
double operator()(double x) const
Definition: Polynomial.h:57
funct::Polynomial< 1 >::Polynomial
Polynomial(double c0, double c1)
Definition: Polynomial.h:56
funct::Polynomial< 2 >::Polynomial
Polynomial(const std::shared_ptr< double > *c)
Definition: Polynomial.h:67
funct::Polynomial< 1 >::Polynomial
Polynomial(std::shared_ptr< double > c0, std::shared_ptr< double > c1)
Definition: Polynomial.h:54
funct::Polynomial< 0 >::Polynomial
Polynomial(const Parameter &c0)
Definition: Polynomial.h:39
Parameter.h
funct::Polynomial< 0 >::operator()
double operator()(double x) const
Definition: Polynomial.h:41
funct::Polynomial< 2 >::operator()
double operator()(double x) const
Definition: Polynomial.h:74
funct::Polynomial< 2 >::Polynomial
Polynomial(double c0, double c1, double c2)
Definition: Polynomial.h:73
funct::Polynomial< 1 >::Polynomial
Polynomial(const Parameter &c0, const Parameter &c1)
Definition: Polynomial.h:55
funct::Polynomial< 1 >::Polynomial
Polynomial(const std::shared_ptr< double > *c)
Definition: Polynomial.h:51
funct::Polynomial< 0 >::Polynomial
Polynomial(std::shared_ptr< double > c0)
Definition: Polynomial.h:38
funct::Polynomial< 1 >::poly_
Polynomial< 0 > poly_
Definition: Polynomial.h:61
funct::Polynomial::poly_
Polynomial< n - 1 > poly_
Definition: Polynomial.h:16
alignmentValidation.c1
c1
do drawing
Definition: alignmentValidation.py:1025
funct::Polynomial::Polynomial
Polynomial(const double *c)
Definition: Polynomial.h:25
funct::Polynomial< 2 >::c0_
std::shared_ptr< double > c0_
Definition: Polynomial.h:77
funct::p
static const int p
Definition: Factorize.h:48
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
funct::Polynomial::c0_
std::shared_ptr< double > c0_
Definition: Polynomial.h:15
funct::Polynomial< 0 >::Polynomial
Polynomial(double c0)
Definition: Polynomial.h:40
funct::Polynomial< 0 >::Polynomial
Polynomial(const std::shared_ptr< double > *c)
Definition: Polynomial.h:35
funct::Polynomial< 1 >
Definition: Polynomial.h:49
funct::Polynomial< 2 >::Polynomial
Polynomial(const Parameter &c0, const Parameter &c1, const Parameter &c2)
Definition: Polynomial.h:72
fftjetpileupestimator_calo_uncalib_cfi.c0
c0
Definition: fftjetpileupestimator_calo_uncalib_cfi.py:8
funct::Polynomial::operator()
double operator()(double x) const
Definition: Polynomial.h:28
funct::Polynomial
Definition: Polynomial.h:7
funct::Polynomial< 0 >::Polynomial
Polynomial(const double *c)
Definition: Polynomial.h:37
funct::Polynomial< 1 >::c0_
std::shared_ptr< double > c0_
Definition: Polynomial.h:60
funct::Polynomial< 2 >::Polynomial
Polynomial(const double *c)
Definition: Polynomial.h:69
funct
Definition: Abs.h:5
funct::Polynomial< 2 >::Polynomial
Polynomial(const Parameter *c)
Definition: Polynomial.h:68