Logo ROOT   6.16/01
Reference Guide
TSpline.h
Go to the documentation of this file.
1// @(#)root/hist:$Id$
2// Author: Federico Carminati 28/02/2000
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TSpline
13#define ROOT_TSpline
14
15#include "TGraph.h"
16
17class TH1;
18class TF1;
19
20class TSpline : public TNamed, public TAttLine,
21 public TAttFill, public TAttMarker
22{
23protected:
24 Double_t fDelta; // Distance between equidistant knots
25 Double_t fXmin; // Minimum value of abscissa
26 Double_t fXmax; // Maximum value of abscissa
27 Int_t fNp; // Number of knots
28 Bool_t fKstep; // True of equidistant knots
29 TH1F *fHistogram; // Temporary histogram
30 TGraph *fGraph; // Graph for drawing the knots
31 Int_t fNpx; // Number of points used for graphical representation
32
33 TSpline(const TSpline&);
34 TSpline& operator=(const TSpline&);
35 virtual void BuildCoeff()=0;
36
37public:
38 TSpline() : fDelta(-1), fXmin(0), fXmax(0),
39 fNp(0), fKstep(kFALSE), fHistogram(0), fGraph(0), fNpx(100) {}
40 TSpline(const char *title, Double_t delta, Double_t xmin,
41 Double_t xmax, Int_t np, Bool_t step) :
42 TNamed("Spline",title), TAttFill(0,1),
43 fDelta(delta), fXmin(xmin),
44 fXmax(xmax), fNp(np), fKstep(step),
45 fHistogram(0), fGraph(0), fNpx(100) {}
46 virtual ~TSpline();
47
48 virtual void GetKnot(Int_t i, Double_t &x, Double_t &y) const =0;
49 virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
50 virtual void Draw(Option_t *option="");
51 virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
52 virtual Double_t GetDelta() const {return fDelta;}
53 TH1F *GetHistogram() const {return fHistogram;}
54 virtual Int_t GetNp() const {return fNp;}
55 virtual Int_t GetNpx() const {return fNpx;}
56 virtual Double_t GetXmin() const {return fXmin;}
57 virtual Double_t GetXmax() const {return fXmax;}
58 virtual void Paint(Option_t *option="");
59 virtual Double_t Eval(Double_t x) const=0;
60 virtual void SaveAs(const char * /*filename*/,Option_t * /*option*/) const {;}
61 void SetNpx(Int_t n) {fNpx=n;}
62
63 ClassDef (TSpline,2) // Spline base class
64};
65
66
67//______________________________________________________________________________
68class TSplinePoly : public TObject
69{
70protected:
71 Double_t fX; // abscissa
72 Double_t fY; // constant term
73
74public:
76 fX(0), fY(0) {}
78 fX(x), fY(y) {}
79 TSplinePoly(TSplinePoly const &other);
80 TSplinePoly &operator=(TSplinePoly const &other);
81
82 Double_t &X() {return fX;}
83 Double_t &Y() {return fY;}
84 void GetKnot(Double_t &x, Double_t &y) const {x=fX; y=fY;}
85
86 virtual Double_t Eval(Double_t) const {return fY;}
87
88 private:
89 void CopyPoly(TSplinePoly const &other);
90
91 ClassDef(TSplinePoly,2) // Spline polynomial terms
92};
93
95:
96 TObject(other), fX(0), fY(0)
97{
98 CopyPoly(other);
99}
100
101
102//______________________________________________________________________________
104{
105private:
106 Double_t fB; // first order expansion coefficient : fB*1! is the first derivative at x
107 Double_t fC; // second order expansion coefficient : fC*2! is the second derivative at x
108 Double_t fD; // third order expansion coefficient : fD*3! is the third derivative at x
109
110public:
112 fB(0), fC(0), fD(0) {}
114 TSplinePoly(x,y), fB(b), fC(c), fD(d) {}
115 TSplinePoly3(TSplinePoly3 const &other);
116 TSplinePoly3 &operator=(TSplinePoly3 const &other);
117
118 Double_t &B() {return fB;}
119 Double_t &C() {return fC;}
120 Double_t &D() {return fD;}
122 Double_t dx=x-fX;
123 return (fY+dx*(fB+dx*(fC+dx*fD)));
124 }
126 Double_t dx=x-fX;
127 return (fB+dx*(2*fC+3*fD*dx));
128 }
129
130private:
131 void CopyPoly(TSplinePoly3 const &other);
132
133 ClassDef(TSplinePoly3,1) // Third spline polynomial terms
134};
135
137 :
138 TSplinePoly(other), fB(0), fC(0), fD(0)
139{
140 CopyPoly(other);
141}
142
143//______________________________________________________________________________
145{
146private:
147 Double_t fB; // first order expansion coefficient : fB*1! is the first derivative at x
148 Double_t fC; // second order expansion coefficient : fC*2! is the second derivative at x
149 Double_t fD; // third order expansion coefficient : fD*3! is the third derivative at x
150 Double_t fE; // fourth order expansion coefficient : fE*4! is the fourth derivative at x
151 Double_t fF; // fifth order expansion coefficient : fF*5! is the fifth derivative at x
152
153public:
155 fB(0), fC(0), fD(0), fE(0), fF(0) {}
158 TSplinePoly(x,y), fB(b), fC(c), fD(d), fE(e), fF(f) {}
159 TSplinePoly5(TSplinePoly5 const &other);
160 TSplinePoly5 &operator=(TSplinePoly5 const &other);
161
162 Double_t &B() {return fB;}
163 Double_t &C() {return fC;}
164 Double_t &D() {return fD;}
165 Double_t &E() {return fE;}
166 Double_t &F() {return fF;}
168 Double_t dx=x-fX;
169 return (fY+dx*(fB+dx*(fC+dx*(fD+dx*(fE+dx*fF)))));
170 }
172 Double_t dx=x-fX;
173 return (fB+dx*(2*fC+dx*(3*fD+dx*(4*fE+dx*(5*fF)))));
174 }
175
176private:
177 void CopyPoly(TSplinePoly5 const &other);
178
179 ClassDef(TSplinePoly5,1) // Quintic spline polynomial terms
180};
181
183:
184 TSplinePoly(other), fB(0), fC(0), fD(0), fE(0), fF(0)
185{
186 CopyPoly(other);
187}
188
189
190//______________________________________________________________________________
191class TSpline3 : public TSpline
192{
193protected:
194 TSplinePoly3 *fPoly; //[fNp] Array of polynomial terms
195 Double_t fValBeg; // Initial value of first or second derivative
196 Double_t fValEnd; // End value of first or second derivative
197 Int_t fBegCond; // 0=no beg cond, 1=first derivative, 2=second derivative
198 Int_t fEndCond; // 0=no end cond, 1=first derivative, 2=second derivative
199
200 void BuildCoeff();
201 void SetCond(const char *opt);
202
203public:
205 fBegCond(-1), fEndCond(-1) {}
206 TSpline3(const char *title,
207 Double_t x[], Double_t y[], Int_t n, const char *opt=0,
208 Double_t valbeg=0, Double_t valend=0);
209 TSpline3(const char *title,
211 Double_t y[], Int_t n, const char *opt=0,
212 Double_t valbeg=0, Double_t valend=0);
213 TSpline3(const char *title,
214 Double_t x[], const TF1 *func, Int_t n, const char *opt=0,
215 Double_t valbeg=0, Double_t valend=0);
216 TSpline3(const char *title,
218 const TF1 *func, Int_t n, const char *opt=0,
219 Double_t valbeg=0, Double_t valend=0);
220 TSpline3(const char *title,
221 const TGraph *g, const char *opt=0,
222 Double_t valbeg=0, Double_t valend=0);
223 TSpline3(const TH1 *h, const char *opt=0,
224 Double_t valbeg=0, Double_t valend=0);
225 TSpline3(const TSpline3&);
226 TSpline3& operator=(const TSpline3&);
227 Int_t FindX(Double_t x) const;
228 Double_t Eval(Double_t x) const;
230 virtual ~TSpline3() {if (fPoly) delete [] fPoly;}
232 Double_t &c, Double_t &d) {x=fPoly[i].X();y=fPoly[i].Y();
233 b=fPoly[i].B();c=fPoly[i].C();d=fPoly[i].D();}
234 void GetKnot(Int_t i, Double_t &x, Double_t &y) const
235 {x=fPoly[i].X(); y=fPoly[i].Y();}
236 virtual void SaveAs(const char *filename,Option_t *option="") const;
237 virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
238 virtual void SetPoint(Int_t i, Double_t x, Double_t y);
239 virtual void SetPointCoeff(Int_t i, Double_t b, Double_t c, Double_t d);
240 static void Test();
241
242 ClassDef (TSpline3,2) // Class to create third natural splines
243};
244
245
246//______________________________________________________________________________
247class TSpline5 : public TSpline
248{
249protected:
250 TSplinePoly5 *fPoly; //[fNp] Array of polynomial terms
251
252 void BuildCoeff();
253 void BoundaryConditions(const char *opt, Int_t &beg, Int_t &end,
254 const char *&cb1, const char *&ce1, const char *&cb2,
255 const char *&ce2);
256 void SetBoundaries(Double_t b1, Double_t e1, Double_t b2, Double_t e2,
257 const char *cb1, const char *ce1, const char *cb2,
258 const char *ce2);
259public:
260 TSpline5() : TSpline() , fPoly(0) {}
261 TSpline5(const char *title,
262 Double_t x[], Double_t y[], Int_t n,
263 const char *opt=0, Double_t b1=0, Double_t e1=0,
264 Double_t b2=0, Double_t e2=0);
265 TSpline5(const char *title,
267 Double_t y[], Int_t n,
268 const char *opt=0, Double_t b1=0, Double_t e1=0,
269 Double_t b2=0, Double_t e2=0);
270 TSpline5(const char *title,
271 Double_t x[], const TF1 *func, Int_t n,
272 const char *opt=0, Double_t b1=0, Double_t e1=0,
273 Double_t b2=0, Double_t e2=0);
274 TSpline5(const char *title,
276 const TF1 *func, Int_t n,
277 const char *opt=0, Double_t b1=0, Double_t e1=0,
278 Double_t b2=0, Double_t e2=0);
279 TSpline5(const char *title,
280 const TGraph *g,
281 const char *opt=0, Double_t b1=0, Double_t e1=0,
282 Double_t b2=0, Double_t e2=0);
283 TSpline5(const TH1 *h,
284 const char *opt=0, Double_t b1=0, Double_t e1=0,
285 Double_t b2=0, Double_t e2=0);
286 TSpline5(const TSpline5&);
287 TSpline5& operator=(const TSpline5&);
288 Int_t FindX(Double_t x) const;
289 Double_t Eval(Double_t x) const;
291 virtual ~TSpline5() {if (fPoly) delete [] fPoly;}
294 {x=fPoly[i].X();y=fPoly[i].Y();b=fPoly[i].B();
295 c=fPoly[i].C();d=fPoly[i].D();
296 e=fPoly[i].E();f=fPoly[i].F();}
297 void GetKnot(Int_t i, Double_t &x, Double_t &y) const
298 {x=fPoly[i].X(); y=fPoly[i].Y();}
299 virtual void SaveAs(const char *filename,Option_t *option="") const;
300 virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
301 virtual void SetPoint(Int_t i, Double_t x, Double_t y);
302 virtual void SetPointCoeff(Int_t i, Double_t b, Double_t c, Double_t d,
304 static void Test();
305
306 ClassDef (TSpline5,2) // Class to create quintic natural splines
307};
308
309#endif
#define d(i)
Definition: RSha256.hxx:102
#define b(i)
Definition: RSha256.hxx:100
#define f(i)
Definition: RSha256.hxx:104
#define c(i)
Definition: RSha256.hxx:101
#define g(i)
Definition: RSha256.hxx:105
#define h(i)
Definition: RSha256.hxx:106
#define e(i)
Definition: RSha256.hxx:103
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:324
float xmin
Definition: THbookFile.cxx:93
float xmax
Definition: THbookFile.cxx:93
Fill Area Attributes class.
Definition: TAttFill.h:19
Line Attributes class.
Definition: TAttLine.h:18
Marker Attributes class.
Definition: TAttMarker.h:19
1-Dim function class
Definition: TF1.h:211
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:571
The TH1 histogram class.
Definition: TH1.h:56
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Mother of all ROOT objects.
Definition: TObject.h:37
Class to create third splines to interpolate knots Arbitrary conditions can be introduced for first a...
Definition: TSpline.h:192
Int_t fEndCond
Definition: TSpline.h:198
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TSpline.cxx:962
Int_t fBegCond
Definition: TSpline.h:197
Int_t FindX(Double_t x) const
Find X.
Definition: TSpline.cxx:740
void GetKnot(Int_t i, Double_t &x, Double_t &y) const
Definition: TSpline.h:234
static void Test()
Test method for TSpline5.
Definition: TSpline.cxx:609
Double_t fValBeg
Definition: TSpline.h:195
virtual ~TSpline3()
Definition: TSpline.h:230
virtual void SaveAs(const char *filename, Option_t *option="") const
Write this spline as a C++ function that can be executed without ROOT the name of the function is the...
Definition: TSpline.cxx:803
Double_t fValEnd
Definition: TSpline.h:196
void SetCond(const char *opt)
Check the boundary conditions.
Definition: TSpline.cxx:570
Double_t Derivative(Double_t x) const
Derivative.
Definition: TSpline.cxx:792
TSplinePoly3 * fPoly
Definition: TSpline.h:194
TSpline3 & operator=(const TSpline3 &)
Assignment operator.
Definition: TSpline.cxx:550
Double_t Eval(Double_t x) const
Eval this spline at x.
Definition: TSpline.cxx:782
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set point number i.
Definition: TSpline.cxx:991
TSpline3()
Definition: TSpline.h:204
void BuildCoeff()
Build coefficients.
Definition: TSpline.cxx:1044
void GetCoeff(Int_t i, Double_t &x, Double_t &y, Double_t &b, Double_t &c, Double_t &d)
Definition: TSpline.h:231
virtual void SetPointCoeff(Int_t i, Double_t b, Double_t c, Double_t d)
Set point coefficient number i.
Definition: TSpline.cxx:1001
Class to create quintic natural splines to interpolate knots Arbitrary conditions can be introduced f...
Definition: TSpline.h:248
static void Test()
Test method for TSpline5.
Definition: TSpline.cxx:2078
void GetCoeff(Int_t i, Double_t &x, Double_t &y, Double_t &b, Double_t &c, Double_t &d, Double_t &e, Double_t &f)
Definition: TSpline.h:292
virtual void SaveAs(const char *filename, Option_t *option="") const
Write this spline as a C++ function that can be executed without ROOT the name of the function is the...
Definition: TSpline.cxx:1577
void GetKnot(Int_t i, Double_t &x, Double_t &y) const
Definition: TSpline.h:297
TSplinePoly5 * fPoly
Definition: TSpline.h:250
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TSpline.cxx:1768
virtual void SetPointCoeff(Int_t i, Double_t b, Double_t c, Double_t d, Double_t e, Double_t f)
Set point coefficient number i.
Definition: TSpline.cxx:1812
TSpline5()
Definition: TSpline.h:260
Double_t Derivative(Double_t x) const
Derivative.
Definition: TSpline.cxx:1567
Double_t Eval(Double_t x) const
Eval this spline at x.
Definition: TSpline.cxx:1558
virtual ~TSpline5()
Definition: TSpline.h:291
void BoundaryConditions(const char *opt, Int_t &beg, Int_t &end, const char *&cb1, const char *&ce1, const char *&cb2, const char *&ce2)
Check the boundary conditions and the amount of extra double knots needed.
Definition: TSpline.cxx:1442
void BuildCoeff()
Algorithm 600, collected algorithms from acm.
Definition: TSpline.cxx:1900
void SetBoundaries(Double_t b1, Double_t e1, Double_t b2, Double_t e2, const char *cb1, const char *ce1, const char *cb2, const char *ce2)
Set the boundary conditions at double/triple knots.
Definition: TSpline.cxx:1473
Int_t FindX(Double_t x) const
Find X.
Definition: TSpline.cxx:1522
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set point number i.
Definition: TSpline.cxx:1801
TSpline5 & operator=(const TSpline5 &)
Assignment operator.
Definition: TSpline.cxx:1425
Class for TSpline3 knot.
Definition: TSpline.h:104
TSplinePoly3(Double_t x, Double_t y, Double_t b, Double_t c, Double_t d)
Definition: TSpline.h:113
Double_t fC
Definition: TSpline.h:107
Double_t & D()
Definition: TSpline.h:120
Double_t fD
Definition: TSpline.h:108
Double_t Derivative(Double_t x) const
Definition: TSpline.h:125
Double_t Eval(Double_t x) const
Definition: TSpline.h:121
Double_t & C()
Definition: TSpline.h:119
Double_t fB
Definition: TSpline.h:106
Double_t & B()
Definition: TSpline.h:118
void CopyPoly(TSplinePoly3 const &other)
Utility called by the copy constructors and = operator.
Definition: TSpline.cxx:307
TSplinePoly3()
Definition: TSpline.h:111
TSplinePoly3 & operator=(TSplinePoly3 const &other)
Assignment operator.
Definition: TSpline.cxx:295
Class for TSpline5 knot.
Definition: TSpline.h:145
Double_t & C()
Definition: TSpline.h:163
void CopyPoly(TSplinePoly5 const &other)
Utility called by the copy constructors and = operator.
Definition: TSpline.cxx:334
TSplinePoly5 & operator=(TSplinePoly5 const &other)
Assignment operator.
Definition: TSpline.cxx:322
Double_t fF
Definition: TSpline.h:151
Double_t Derivative(Double_t x) const
Definition: TSpline.h:171
TSplinePoly5()
Definition: TSpline.h:154
Double_t fB
Definition: TSpline.h:147
Double_t fC
Definition: TSpline.h:148
Double_t Eval(Double_t x) const
Definition: TSpline.h:167
Double_t & B()
Definition: TSpline.h:162
TSplinePoly5(Double_t x, Double_t y, Double_t b, Double_t c, Double_t d, Double_t e, Double_t f)
Definition: TSpline.h:156
Double_t & F()
Definition: TSpline.h:166
Double_t fD
Definition: TSpline.h:149
Double_t & E()
Definition: TSpline.h:165
Double_t fE
Definition: TSpline.h:150
Double_t & D()
Definition: TSpline.h:164
Base class for TSpline knot.
Definition: TSpline.h:69
virtual Double_t Eval(Double_t) const
Definition: TSpline.h:86
Double_t & Y()
Definition: TSpline.h:83
Double_t & X()
Definition: TSpline.h:82
void CopyPoly(TSplinePoly const &other)
Utility called by the copy constructors and = operator.
Definition: TSpline.cxx:281
TSplinePoly & operator=(TSplinePoly const &other)
Assignment operator.
Definition: TSpline.cxx:269
TSplinePoly()
Definition: TSpline.h:75
Double_t fY
Definition: TSpline.h:72
void GetKnot(Double_t &x, Double_t &y) const
Definition: TSpline.h:84
TSplinePoly(Double_t x, Double_t y)
Definition: TSpline.h:77
Double_t fX
Definition: TSpline.h:71
Base class for spline implementation containing the Draw/Paint methods.
Definition: TSpline.h:22
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TSpline.cxx:118
virtual Double_t Eval(Double_t x) const =0
TH1F * GetHistogram() const
Definition: TSpline.h:53
TGraph * fGraph
Definition: TSpline.h:30
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TSpline.cxx:97
Double_t fXmin
Definition: TSpline.h:25
void SetNpx(Int_t n)
Definition: TSpline.h:61
TH1F * fHistogram
Definition: TSpline.h:29
TSpline()
Definition: TSpline.h:38
Double_t fDelta
Definition: TSpline.h:24
virtual void GetKnot(Int_t i, Double_t &x, Double_t &y) const =0
TSpline & operator=(const TSpline &)
Assignment operator.
Definition: TSpline.cxx:65
virtual Int_t GetNpx() const
Definition: TSpline.h:55
Bool_t fKstep
Definition: TSpline.h:28
virtual void Paint(Option_t *option="")
Paint this function with its current attributes.
Definition: TSpline.cxx:127
virtual Int_t GetNp() const
Definition: TSpline.h:54
Int_t fNp
Definition: TSpline.h:27
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a spline.
Definition: TSpline.cxx:109
virtual ~TSpline()
Destructor.
Definition: TSpline.cxx:56
virtual void BuildCoeff()=0
TSpline(const char *title, Double_t delta, Double_t xmin, Double_t xmax, Int_t np, Bool_t step)
Definition: TSpline.h:40
virtual Double_t GetXmin() const
Definition: TSpline.h:56
virtual Double_t GetDelta() const
Definition: TSpline.h:52
virtual Double_t GetXmax() const
Definition: TSpline.h:57
Double_t fXmax
Definition: TSpline.h:26
virtual void SaveAs(const char *, Option_t *) const
Save this object in the file specified by filename.
Definition: TSpline.h:60
Int_t fNpx
Definition: TSpline.h:31
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16