CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
TRadSpline.h
Go to the documentation of this file.
1#ifndef ROOT_TRadSpline
2#define ROOT_TRadSpline
3
4class TRadSpline {
5protected:
6 double fDelta; // Distance between equidistant knots
7 double fXmin; // Minimum value of abscissa
8 double fXmax; // Maximum value of abscissa
9 int fNp; // Number of knots
10 bool fKstep; // True of equidistant knots
11 int fNpx; // Number of points used for graphical representation
12
13 virtual void BuildCoeff()=0;
14
15public:
16 TRadSpline() : fDelta(-1), fXmin(0), fXmax(0),
17 fNp(0), fKstep(false), fNpx(100) {}
18 TRadSpline(const char *title, double delta, double xmin,
19 double xmax, int np, bool step) :
20 fDelta(delta), fXmin(xmin),
21 fXmax(xmax), fNp(np), fKstep(step),
22 fNpx(100) {}
23 virtual ~TRadSpline() {}
24 virtual void GetKnot(int i, double &x, double &y) const =0;
25 // virtual void Draw(const char *option="");
26 virtual int GetNpx() const {return fNpx;}
27 // virtual void Paint(const char *option="");
28 virtual double Eval(double x) const=0;
29 virtual void SaveAs(const char * /*filename*/) const {;}
30 void SetNpx(int n) {fNpx=n;}
31
32};
33
34
35//________________________________________________________________________
37protected:
38 double fX; // abscissa
39 double fY; // constant term
40public:
42 fX(0), fY(0) {}
43 TRadSplinePoly(double x, double y) :
44 fX(x), fY(y) {}
45 virtual ~TRadSplinePoly() {}
46 double &X() {return fX;}
47 double &Y() {return fY;}
48 void GetKnot(double &x, double &y) const {x=fX; y=fY;}
49
50 virtual double Eval(double) const {return fY;}
51
52};
53
54
55//________________________________________________________________________
57private:
58 double fB; // first order expansion coefficient : fB*1! is the first derivative at x
59 double fC; // second order expansion coefficient : fC*2! is the second derivative at x
60 double fD; // third order expansion coefficient : fD*3! is the third derivative at x
61public:
63 fB(0), fC(0), fD(0) {}
64 TRadSplinePoly3(double x, double y, double b, double c, double d) :
65 TRadSplinePoly(x,y), fB(b), fC(c), fD(d) {}
66 double &B() {return fB;}
67 double &C() {return fC;}
68 double &D() {return fD;}
69 double Eval(double x) const {
70 double dx=x-fX;
71 return (fY+dx*(fB+dx*(fC+dx*fD)));
72 }
73 double Derivative(double x) const {
74 double dx=x-fX;
75 return (fB+2*fC*dx+3*fD*dx*dx);
76 }
77
78};
79
80
81//________________________________________________________________________
83private:
84 double fB; // first order expansion coefficient : fB*1! is the first derivative at x
85 double fC; // second order expansion coefficient : fC*2! is the second derivative at x
86 double fD; // third order expansion coefficient : fD*3! is the third derivative at x
87 double fE; // fourth order expansion coefficient : fE*4! is the fourth derivative at x
88 double fF; // fifth order expansion coefficient : fF*5! is the fifth derivative at x
89public:
91 fB(0), fC(0), fD(0), fE(0), fF(0) {}
92 TRadSplinePoly5(double x, double y, double b, double c,
93 double d, double e, double f) :
94 TRadSplinePoly(x,y), fB(b), fC(c), fD(d), fE(e), fF(f) {}
95 double &B() {return fB;}
96 double &C() {return fC;}
97 double &D() {return fD;}
98 double &E() {return fE;}
99 double &F() {return fF;}
100 double Eval(double x) const {
101 double dx=x-fX;
102 return (fY+dx*(fB+dx*(fC+dx*(fD+dx*(fE+dx*fF)))));
103 }
104 double Derivative(double x) const{
105 double dx=x-fX;
106 return (fB+2*fC*dx+3*fD*dx*dx+4*fE*dx*dx*dx+5*fF*dx*dx*dx*dx);
107 }
108
109};
110
111
112//________________________________________________________________________
113class TRadSpline3 : public TRadSpline {
114private:
115 TRadSplinePoly3 *fPoly; //[fNp] Array of polynomial terms
116 double fValBeg; // Initial value of first or second derivative
117 double fValEnd; // End value of first or second derivative
118 int fBegCond; // 0=no beg cond, 1=first derivative, 2=second derivative
119 int fEndCond; // 0=no end cond, 1=first derivative, 2=second derivative
120
121 void BuildCoeff();
122 void SetCond(const char *opt);
123
124public:
125 TRadSpline3() : fPoly(0), fValBeg(0), fValEnd(0),
126 fBegCond(-1), fEndCond(-1) {}
127 TRadSpline3(const char *title,
128 double x[], double y[], int n, const char *opt=0,
129 double valbeg=0, double valend=0);
130 TRadSpline3(const char *title,
131 double xmin, double xmax,
132 double y[], int n, const char *opt=0,
133 double valbeg=0, double valend=0);
134 TRadSpline3(const char *title,
135 double xmin, double xmax,
136 double (*func)(const double&), int n, const char *opt=0,
137 double valbeg=0, double valend=0);
138 int FindX(double x) const;
139 double Eval(double x) const;
140 double Derivative(double x) const;
141 virtual ~TRadSpline3() {if (fPoly) delete [] fPoly;}
142 void GetCoeff(int i, double &x, double &y, double &b,
143 double &c, double &d) {x=fPoly[i].X();y=fPoly[i].Y();
144 b=fPoly[i].B();c=fPoly[i].C();d=fPoly[i].D();}
145 void GetKnot(int i, double &x, double &y) const
146 {x=fPoly[i].X(); y=fPoly[i].Y();}
147 virtual void SaveAs(const char *filename) const;
148 static void Test();
149
150};
151
152
153//________________________________________________________________________
154class TRadSpline5 : public TRadSpline {
155private:
156 TRadSplinePoly5 *fPoly; //[fNp] Array of polynomial terms
157
158 void BuildCoeff();
159 void BoundaryConditions(const char *opt, int &beg, int &end,
160 const char *&cb1, const char *&ce1, const char *&cb2,
161 const char *&ce2);
162 void SetBoundaries(double b1, double e1, double b2, double e2,
163 const char *cb1, const char *ce1, const char *cb2,
164 const char *ce2);
165
166public:
167 TRadSpline5() : fPoly(0) {}
168 TRadSpline5(const char *title,
169 double x[], double y[], int n,
170 const char *opt=0, double b1=0, double e1=0,
171 double b2=0, double e2=0);
172 TRadSpline5(const char *title,
173 double xmin, double xmax,
174 double y[], int n,
175 const char *opt=0, double b1=0, double e1=0,
176 double b2=0, double e2=0);
177 TRadSpline5(const char *title,
178 double xmin, double xmax,
179 double(*func)(const double&),
180 int n, const char *opt=0,
181 double b1=0, double e1=0,
182 double b2=0, double e2=0);
183 int FindX(double x) const;
184 double Eval(double x) const;
185 double Derivative(double x) const;
186 ~TRadSpline5() {if (fPoly) delete [] fPoly;}
187 void GetCoeff(int i, double &x, double &y, double &b,
188 double &c, double &d, double &e, double &f)
189 {x=fPoly[i].X();y=fPoly[i].Y();b=fPoly[i].B();
190 c=fPoly[i].C();d=fPoly[i].D();
191 e=fPoly[i].E();f=fPoly[i].F();}
192 void GetKnot(int i, double &x, double &y) const
193 {x=fPoly[i].X(); y=fPoly[i].Y();}
194 virtual void SaveAs(const char *filename) const;
195 static void Test();
196
197};
198
199#endif
const Int_t n
Double_t x[10]
Double_t e1
Double_t e2
void GetCoeff(int i, double &x, double &y, double &b, double &c, double &d)
Definition TRadSpline.h:142
int FindX(double x) const
virtual ~TRadSpline3()
Definition TRadSpline.h:141
double Derivative(double x) const
static void Test()
double Eval(double x) const
TRadSpline3(const char *title, double xmin, double xmax, double y[], int n, const char *opt=0, double valbeg=0, double valend=0)
void GetKnot(int i, double &x, double &y) const
Definition TRadSpline.h:145
TRadSpline3(const char *title, double xmin, double xmax, double(*func)(const double &), int n, const char *opt=0, double valbeg=0, double valend=0)
TRadSpline3(const char *title, double x[], double y[], int n, const char *opt=0, double valbeg=0, double valend=0)
virtual void SaveAs(const char *filename) const
TRadSpline5(const char *title, double x[], double y[], int n, const char *opt=0, double b1=0, double e1=0, double b2=0, double e2=0)
void GetCoeff(int i, double &x, double &y, double &b, double &c, double &d, double &e, double &f)
Definition TRadSpline.h:187
double Derivative(double x) const
int FindX(double x) const
virtual void SaveAs(const char *filename) const
double Eval(double x) const
TRadSpline5(const char *title, double xmin, double xmax, double y[], int n, const char *opt=0, double b1=0, double e1=0, double b2=0, double e2=0)
void GetKnot(int i, double &x, double &y) const
Definition TRadSpline.h:192
static void Test()
TRadSpline5(const char *title, double xmin, double xmax, double(*func)(const double &), int n, const char *opt=0, double b1=0, double e1=0, double b2=0, double e2=0)
double & C()
Definition TRadSpline.h:67
double & D()
Definition TRadSpline.h:68
double & B()
Definition TRadSpline.h:66
double Eval(double x) const
Definition TRadSpline.h:69
TRadSplinePoly3(double x, double y, double b, double c, double d)
Definition TRadSpline.h:64
double Derivative(double x) const
Definition TRadSpline.h:73
double Derivative(double x) const
Definition TRadSpline.h:104
double & B()
Definition TRadSpline.h:95
double & D()
Definition TRadSpline.h:97
double & C()
Definition TRadSpline.h:96
double & F()
Definition TRadSpline.h:99
double & E()
Definition TRadSpline.h:98
TRadSplinePoly5(double x, double y, double b, double c, double d, double e, double f)
Definition TRadSpline.h:92
double Eval(double x) const
Definition TRadSpline.h:100
virtual double Eval(double) const
Definition TRadSpline.h:50
virtual ~TRadSplinePoly()
Definition TRadSpline.h:45
double & Y()
Definition TRadSpline.h:47
double & X()
Definition TRadSpline.h:46
void GetKnot(double &x, double &y) const
Definition TRadSpline.h:48
TRadSplinePoly(double x, double y)
Definition TRadSpline.h:43
bool fKstep
Definition TRadSpline.h:10
virtual int GetNpx() const
Definition TRadSpline.h:26
virtual ~TRadSpline()
Definition TRadSpline.h:23
virtual void GetKnot(int i, double &x, double &y) const =0
TRadSpline(const char *title, double delta, double xmin, double xmax, int np, bool step)
Definition TRadSpline.h:18
virtual void BuildCoeff()=0
virtual double Eval(double x) const =0
double fXmin
Definition TRadSpline.h:7
void SetNpx(int n)
Definition TRadSpline.h:30
virtual void SaveAs(const char *) const
Definition TRadSpline.h:29
double fDelta
Definition TRadSpline.h:6
double fXmax
Definition TRadSpline.h:8