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 #include "boost/shared_ptr.hpp"
5 
6 namespace funct {
7  template<unsigned int n>
8  class Polynomial {
9  public:
10  Polynomial(const double * c);
11  Polynomial(const boost::shared_ptr<double> * c);
12  Polynomial(const Parameter * p);
13  double operator()(double x) const;
14  private:
15  boost::shared_ptr<double> c0_;
17  };
18 
19  template<unsigned int n>
20  Polynomial<n>::Polynomial(const boost::shared_ptr<double> * c) :
21  c0_(c), poly_(c + 1) {
22  }
23  template<unsigned int n>
25  c0_(c->ptr()), poly_(c + 1) {
26  }
27 
28 
29  template<unsigned int n>
30  Polynomial<n>::Polynomial(const double * c) :
31  c0_(new double(*c)), poly_(c + 1) {
32  }
33 
34  template<unsigned int n>
35  double Polynomial<n>::operator()(double x) const {
36  return *c0_ + x*poly_(x);
37  }
38 
39  template<>
40  class Polynomial<0> {
41  public:
42  Polynomial(const boost::shared_ptr<double> * c) :
43  c0_(*c) {
44  }
45  Polynomial(const Parameter * c) :
46  c0_(c->ptr()) {
47  }
48  Polynomial(const double * c) :
49  c0_(new double(*c)) {
50  }
51  Polynomial(boost::shared_ptr<double> c0) :
52  c0_(c0) {
53  }
54  Polynomial(const Parameter & c0) :
55  c0_(c0.ptr()) {
56  }
57  Polynomial(double c0) :
58  c0_(new double(c0)) {
59  }
60  double operator()(double x) const {
61  return *c0_;
62  }
63  double operator()() const {
64  return *c0_;
65  }
66  private:
67  boost::shared_ptr<double> c0_;
68  };
69 
70  template<>
71  class Polynomial<1> {
72  public:
73  Polynomial(const boost::shared_ptr<double> * c) :
74  c0_(*c), poly_(c + 1) {
75  }
76  Polynomial(const Parameter * c) :
77  c0_(c->ptr()), poly_(c + 1) {
78  }
79  Polynomial(const double * c) :
80  c0_(new double(*c)), poly_(c + 1) {
81  }
82  Polynomial(boost::shared_ptr<double> c0, boost::shared_ptr<double> c1) :
83  c0_(c0), poly_(c1) {
84  }
85  Polynomial(const Parameter& c0, const Parameter& c1) :
86  c0_(c0.ptr()), poly_(c1.ptr()) {
87  }
88  Polynomial(double c0, double c1) :
89  c0_(new double(c0)), poly_(c1) {
90  }
91  double operator()(double x) const {
92  return *c0_ + x*poly_(x);
93  }
94  private:
95  boost::shared_ptr<double> c0_;
97  };
98 
99  template<>
100  class Polynomial<2> {
101  public:
102  Polynomial(const boost::shared_ptr<double> * c) :
103  c0_(*c), poly_(c + 1) {
104  }
105  Polynomial(const Parameter * c) :
106  c0_(c->ptr()), poly_(c + 1) {
107  }
108  Polynomial(const double * c) :
109  c0_(new double(*c)), poly_(c + 1) {
110  }
111  Polynomial(boost::shared_ptr<double> c0,
112  boost::shared_ptr<double> c1,
113  boost::shared_ptr<double> c2) : c0_(c0), poly_(c1, c2) {
114  }
116  const Parameter &c1,
117  const Parameter &c2) : c0_(c0.ptr()), poly_(c1, c2) {
118  }
119  Polynomial(double c0, double c1, double c2) :
120  c0_(new double(c0) ), poly_(c1, c2) {
121  }
122  double operator()(double x) const {
123  return *c0_ + x*poly_(x);
124  }
125  private:
126  boost::shared_ptr<double> c0_;
128  };
129 }
130 
131 #endif
Polynomial(const boost::shared_ptr< double > *c)
Definition: Polynomial.h:102
Definition: Abs.h:5
Polynomial< n-1 > poly_
Definition: Polynomial.h:16
Polynomial(const Parameter &c0)
Definition: Polynomial.h:54
Polynomial(const Parameter &c0, const Parameter &c1)
Definition: Polynomial.h:85
Polynomial(const Parameter *c)
Definition: Polynomial.h:45
Polynomial(const double *c)
Definition: Polynomial.h:79
Polynomial< 0 > poly_
Definition: Polynomial.h:96
boost::shared_ptr< double > c0_
Definition: Polynomial.h:126
boost::shared_ptr< double > c0_
Definition: Polynomial.h:95
Polynomial< 1 > poly_
Definition: Polynomial.h:127
Polynomial(const boost::shared_ptr< double > *c)
Definition: Polynomial.h:42
double operator()() const
Definition: Polynomial.h:63
boost::shared_ptr< double > c0_
Definition: Polynomial.h:67
Polynomial(const boost::shared_ptr< double > *c)
Definition: Polynomial.h:73
Polynomial(const double *c)
Definition: Polynomial.h:30
double operator()(double x) const
Definition: Polynomial.h:122
Polynomial(boost::shared_ptr< double > c0)
Definition: Polynomial.h:51
double operator()(double x) const
Definition: Polynomial.h:91
Polynomial(double c0, double c1)
Definition: Polynomial.h:88
double operator()(double x) const
Definition: Polynomial.h:60
Polynomial(boost::shared_ptr< double > c0, boost::shared_ptr< double > c1)
Definition: Polynomial.h:82
Polynomial(const Parameter *c)
Definition: Polynomial.h:76
Polynomial(double c0)
Definition: Polynomial.h:57
Polynomial(const double *c)
Definition: Polynomial.h:108
Polynomial(const Parameter *c)
Definition: Polynomial.h:105
static const int p
Definition: Factorize.h:58
double operator()(double x) const
Definition: Polynomial.h:35
Polynomial(const Parameter &c0, const Parameter &c1, const Parameter &c2)
Definition: Polynomial.h:115
Polynomial(boost::shared_ptr< double > c0, boost::shared_ptr< double > c1, boost::shared_ptr< double > c2)
Definition: Polynomial.h:111
boost::shared_ptr< double > c0_
Definition: Polynomial.h:15
Polynomial(const double *c)
Definition: Polynomial.h:48
Polynomial(double c0, double c1, double c2)
Definition: Polynomial.h:119