CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
std::shared_ptr< double > c0_
Definition: Polynomial.h:45
std::shared_ptr< double > c0_
Definition: Polynomial.h:15
const edm::EventSetup & c
std::shared_ptr< double > c0_
Definition: Polynomial.h:60
Polynomial(const Parameter &c0)
Definition: Polynomial.h:39
Polynomial(const Parameter &c0, const Parameter &c1)
Definition: Polynomial.h:55
Polynomial(const Parameter *c)
Definition: Polynomial.h:36
Polynomial(std::shared_ptr< double > c0, std::shared_ptr< double > c1, std::shared_ptr< double > c2)
Definition: Polynomial.h:70
Polynomial(std::shared_ptr< double > c0, std::shared_ptr< double > c1)
Definition: Polynomial.h:54
Polynomial(const double *c)
Definition: Polynomial.h:53
Polynomial(const std::shared_ptr< double > *c)
Definition: Polynomial.h:67
Polynomial(const std::shared_ptr< double > *c)
Definition: Polynomial.h:51
Polynomial< 0 > poly_
Definition: Polynomial.h:61
Polynomial< 1 > poly_
Definition: Polynomial.h:78
double operator()() const
Definition: Polynomial.h:42
Polynomial< n-1 > poly_
Definition: Polynomial.h:16
Polynomial(const double *c)
Definition: Polynomial.h:25
std::shared_ptr< double > c0_
Definition: Polynomial.h:77
double operator()(double x) const
Definition: Polynomial.h:74
double operator()(double x) const
Definition: Polynomial.h:57
Polynomial(double c0, double c1)
Definition: Polynomial.h:56
double operator()(double x) const
Definition: Polynomial.h:41
Polynomial(std::shared_ptr< double > c0)
Definition: Polynomial.h:38
Polynomial(const Parameter *c)
Definition: Polynomial.h:52
Polynomial(double c0)
Definition: Polynomial.h:40
Polynomial(const double *c)
Definition: Polynomial.h:69
Polynomial(const Parameter *c)
Definition: Polynomial.h:68
static const int p
Definition: Factorize.h:48
double operator()(double x) const
Definition: Polynomial.h:28
Polynomial(const Parameter &c0, const Parameter &c1, const Parameter &c2)
Definition: Polynomial.h:72
Polynomial(const std::shared_ptr< double > *c)
Definition: Polynomial.h:35
Polynomial(const double *c)
Definition: Polynomial.h:37
Polynomial(double c0, double c1, double c2)
Definition: Polynomial.h:73