Logo ROOT  
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#ifdef R__LESS_INCLUDES
16#include "TNamed.h"
17#include "TAttLine.h"
18#include "TAttFill.h"
19#include "TAttMarker.h"
20#else
21#include "TGraph.h"
22#endif
23
24class TH1;
25class TH1F;
26class TF1;
27class TGraph;
28
29class TSpline : public TNamed, public TAttLine,
30 public TAttFill, public TAttMarker
31{
32protected:
33 Double_t fDelta; ///< Distance between equidistant knots
34 Double_t fXmin; ///< Minimum value of abscissa
35 Double_t fXmax; ///< Maximum value of abscissa
36 Int_t fNp; ///< Number of knots
37 Bool_t fKstep; ///< True of equidistant knots
38 TH1F *fHistogram; ///< Temporary histogram
39 TGraph *fGraph; ///< Graph for drawing the knots
40 Int_t fNpx; ///< Number of points used for graphical representation
41
42 TSpline(const TSpline&);
43 TSpline& operator=(const TSpline&);
44 virtual void BuildCoeff()=0;
45
46public:
47 TSpline() : fDelta(-1), fXmin(0), fXmax(0),
48 fNp(0), fKstep(kFALSE), fHistogram(0), fGraph(0), fNpx(100) {}
49 TSpline(const char *title, Double_t delta, Double_t xmin,
50 Double_t xmax, Int_t np, Bool_t step) :
51 TNamed("Spline",title), TAttFill(0,1),
52 fDelta(delta), fXmin(xmin),
53 fXmax(xmax), fNp(np), fKstep(step),
54 fHistogram(0), fGraph(0), fNpx(100) {}
55 virtual ~TSpline();
56
57 virtual void GetKnot(Int_t i, Double_t &x, Double_t &y) const =0;
58 virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
59 virtual void Draw(Option_t *option="");
60 virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
61 virtual Double_t GetDelta() const {return fDelta;}
62 TH1F *GetHistogram() const {return fHistogram;}
63 virtual Int_t GetNp() const {return fNp;}
64 virtual Int_t GetNpx() const {return fNpx;}
65 virtual Double_t GetXmin() const {return fXmin;}
66 virtual Double_t GetXmax() const {return fXmax;}
67 virtual void Paint(Option_t *option="");
68 virtual Double_t Eval(Double_t x) const=0;
69 virtual void SaveAs(const char * /*filename*/,Option_t * /*option*/) const {;}
70 void SetNpx(Int_t n) {fNpx=n;}
71
72 ClassDef (TSpline,2) // Spline base class
73};
74
75
76//______________________________________________________________________________
77class TSplinePoly : public TObject
78{
79protected:
80 Double_t fX; ///< Abscissa
81 Double_t fY; ///< Constant term
82
83public:
85 fX(0), fY(0) {}
87 fX(x), fY(y) {}
88 TSplinePoly(TSplinePoly const &other);
89 TSplinePoly &operator=(TSplinePoly const &other);
90
91 Double_t &X() {return fX;}
92 Double_t &Y() {return fY;}
93 void GetKnot(Double_t &x, Double_t &y) const {x=fX; y=fY;}
94
95 virtual Double_t Eval(Double_t) const {return fY;}
96
97 private:
98 void CopyPoly(TSplinePoly const &other);
99
100 ClassDef(TSplinePoly,2) // Spline polynomial terms
101};
102
104:
105 TObject(other), fX(0), fY(0)
106{
107 CopyPoly(other);
108}
109
110
111//______________________________________________________________________________
113{
114private:
115 Double_t fB; ///< First order expansion coefficient : fB*1! is the first derivative at x
116 Double_t fC; ///< Second order expansion coefficient : fC*2! is the second derivative at x
117 Double_t fD; ///< Third order expansion coefficient : fD*3! is the third derivative at x
118
119public:
121 fB(0), fC(0), fD(0) {}
123 TSplinePoly(x,y), fB(b), fC(c), fD(d) {}
124 TSplinePoly3(TSplinePoly3 const &other);
125 TSplinePoly3 &operator=(TSplinePoly3 const &other);
126
127 Double_t &B() {return fB;}
128 Double_t &C() {return fC;}
129 Double_t &D() {return fD;}
131 Double_t dx=x-fX;
132 return (fY+dx*(fB+dx*(fC+dx*fD)));
133 }
135 Double_t dx=x-fX;
136 return (fB+dx*(2*fC+3*fD*dx));
137 }
138
139private:
140 void CopyPoly(TSplinePoly3 const &other);
141
142 ClassDef(TSplinePoly3,1) // Third spline polynomial terms
143};
144
146 :
147 TSplinePoly(other), fB(0), fC(0), fD(0)
148{
149 CopyPoly(other);
150}
151
152//______________________________________________________________________________
154{
155private:
156 Double_t fB; ///< First order expansion coefficient : fB*1! is the first derivative at x
157 Double_t fC; ///< Second order expansion coefficient : fC*2! is the second derivative at x
158 Double_t fD; ///< Third order expansion coefficient : fD*3! is the third derivative at x
159 Double_t fE; ///< Fourth order expansion coefficient : fE*4! is the fourth derivative at x
160 Double_t fF; ///< Fifth order expansion coefficient : fF*5! is the fifth derivative at x
161
162public:
164 fB(0), fC(0), fD(0), fE(0), fF(0) {}
167 TSplinePoly(x,y), fB(b), fC(c), fD(d), fE(e), fF(f) {}
168 TSplinePoly5(TSplinePoly5 const &other);
169 TSplinePoly5 &operator=(TSplinePoly5 const &other);
170
171 Double_t &B() {return fB;}
172 Double_t &C() {return fC;}
173 Double_t &D() {return fD;}
174 Double_t &E() {return fE;}
175 Double_t &F() {return fF;}
177 Double_t dx=x-fX;
178 return (fY+dx*(fB+dx*(fC+dx*(fD+dx*(fE+dx*fF)))));
179 }
181 Double_t dx=x-fX;
182 return (fB+dx*(2*fC+dx*(3*fD+dx*(4*fE+dx*(5*fF)))));
183 }
184
185private:
186 void CopyPoly(TSplinePoly5 const &other);
187
188 ClassDef(TSplinePoly5,1) // Quintic spline polynomial terms
189};
190
192:
193 TSplinePoly(other), fB(0), fC(0), fD(0), fE(0), fF(0)
194{
195 CopyPoly(other);
196}
197
198
199//______________________________________________________________________________
200class TSpline3 : public TSpline
201{
202protected:
203 TSplinePoly3 *fPoly; ///<[fNp] Array of polynomial terms
204 Double_t fValBeg; ///< Initial value of first or second derivative
205 Double_t fValEnd; ///< End value of first or second derivative
206 Int_t fBegCond; ///< 0=no beg cond, 1=first derivative, 2=second derivative
207 Int_t fEndCond; ///< 0=no end cond, 1=first derivative, 2=second derivative
208
209 void BuildCoeff();
210 void SetCond(const char *opt);
211
212public:
214 fBegCond(-1), fEndCond(-1) {}
215 TSpline3(const char *title,
216 Double_t x[], Double_t y[], Int_t n, const char *opt=0,
217 Double_t valbeg=0, Double_t valend=0);
218 TSpline3(const char *title,
220 Double_t y[], Int_t n, const char *opt=0,
221 Double_t valbeg=0, Double_t valend=0);
222 TSpline3(const char *title,
223 Double_t x[], const TF1 *func, Int_t n, const char *opt=0,
224 Double_t valbeg=0, Double_t valend=0);
225 TSpline3(const char *title,
227 const TF1 *func, Int_t n, const char *opt=0,
228 Double_t valbeg=0, Double_t valend=0);
229 TSpline3(const char *title,
230 const TGraph *g, const char *opt=0,
231 Double_t valbeg=0, Double_t valend=0);
232 TSpline3(const TH1 *h, const char *opt=0,
233 Double_t valbeg=0, Double_t valend=0);
234 TSpline3(const TSpline3&);
235 TSpline3& operator=(const TSpline3&);
236 Int_t FindX(Double_t x) const;
237 Double_t Eval(Double_t x) const;
239 virtual ~TSpline3() {if (fPoly) delete [] fPoly;}
241 Double_t &c, Double_t &d) {x=fPoly[i].X();y=fPoly[i].Y();
242 b=fPoly[i].B();c=fPoly[i].C();d=fPoly[i].D();}
243 void GetKnot(Int_t i, Double_t &x, Double_t &y) const
244 {x=fPoly[i].X(); y=fPoly[i].Y();}
245 virtual void SaveAs(const char *filename,Option_t *option="") const;
246 virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
247 virtual void SetPoint(Int_t i, Double_t x, Double_t y);
248 virtual void SetPointCoeff(Int_t i, Double_t b, Double_t c, Double_t d);
249 static void Test();
250
251 ClassDef (TSpline3,2) // Class to create third natural splines
252};
253
254
255//______________________________________________________________________________
256class TSpline5 : public TSpline
257{
258protected:
259 TSplinePoly5 *fPoly; ///<[fNp] Array of polynomial terms
260
261 void BuildCoeff();
262 void BoundaryConditions(const char *opt, Int_t &beg, Int_t &end,
263 const char *&cb1, const char *&ce1, const char *&cb2,
264 const char *&ce2);
265 void SetBoundaries(Double_t b1, Double_t e1, Double_t b2, Double_t e2,
266 const char *cb1, const char *ce1, const char *cb2,
267 const char *ce2);
268public:
269 TSpline5() : TSpline() , fPoly(0) {}
270 TSpline5(const char *title,
271 Double_t x[], Double_t y[], 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 Double_t y[], 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 Double_t x[], const TF1 *func, Int_t n,
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 char *title,
285 const TF1 *func, Int_t n,
286 const char *opt=0, Double_t b1=0, Double_t e1=0,
287 Double_t b2=0, Double_t e2=0);
288 TSpline5(const char *title,
289 const TGraph *g,
290 const char *opt=0, Double_t b1=0, Double_t e1=0,
291 Double_t b2=0, Double_t e2=0);
292 TSpline5(const TH1 *h,
293 const char *opt=0, Double_t b1=0, Double_t e1=0,
294 Double_t b2=0, Double_t e2=0);
295 TSpline5(const TSpline5&);
296 TSpline5& operator=(const TSpline5&);
297 Int_t FindX(Double_t x) const;
298 Double_t Eval(Double_t x) const;
300 virtual ~TSpline5() {if (fPoly) delete [] fPoly;}
303 {x=fPoly[i].X();y=fPoly[i].Y();b=fPoly[i].B();
304 c=fPoly[i].C();d=fPoly[i].D();
305 e=fPoly[i].E();f=fPoly[i].F();}
306 void GetKnot(Int_t i, Double_t &x, Double_t &y) const
307 {x=fPoly[i].X(); y=fPoly[i].Y();}
308 virtual void SaveAs(const char *filename,Option_t *option="") const;
309 virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
310 virtual void SetPoint(Int_t i, Double_t x, Double_t y);
311 virtual void SetPointCoeff(Int_t i, Double_t b, Double_t c, Double_t d,
313 static void Test();
314
315 ClassDef (TSpline5,2) // Class to create quintic natural splines
316};
317
318#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:45
const Bool_t kFALSE
Definition: RtypesCore.h:101
bool Bool_t
Definition: RtypesCore.h:63
double Double_t
Definition: RtypesCore.h:59
const char Option_t
Definition: RtypesCore.h:66
#define ClassDef(name, id)
Definition: Rtypes.h:325
float xmin
Definition: THbookFile.cxx:95
float xmax
Definition: THbookFile.cxx:95
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:213
A TGraph is an 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:575
TH1 is the base class of all histogram classes in ROOT.
Definition: TH1.h:58
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:201
Int_t fEndCond
0=no end cond, 1=first derivative, 2=second derivative
Definition: TSpline.h:207
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TSpline.cxx:966
Int_t fBegCond
0=no beg cond, 1=first derivative, 2=second derivative
Definition: TSpline.h:206
Int_t FindX(Double_t x) const
Find X.
Definition: TSpline.cxx:744
void GetKnot(Int_t i, Double_t &x, Double_t &y) const
Definition: TSpline.h:243
static void Test()
Test method for TSpline5.
Definition: TSpline.cxx:613
Double_t fValBeg
Initial value of first or second derivative.
Definition: TSpline.h:204
virtual ~TSpline3()
Definition: TSpline.h:239
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:807
Double_t fValEnd
End value of first or second derivative.
Definition: TSpline.h:205
void SetCond(const char *opt)
Check the boundary conditions.
Definition: TSpline.cxx:574
Double_t Derivative(Double_t x) const
Derivative.
Definition: TSpline.cxx:796
TSplinePoly3 * fPoly
[fNp] Array of polynomial terms
Definition: TSpline.h:203
TSpline3 & operator=(const TSpline3 &)
Assignment operator.
Definition: TSpline.cxx:554
Double_t Eval(Double_t x) const
Eval this spline at x.
Definition: TSpline.cxx:786
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set point number i.
Definition: TSpline.cxx:995
TSpline3()
Definition: TSpline.h:213
void BuildCoeff()
Build coefficients.
Definition: TSpline.cxx:1048
void GetCoeff(Int_t i, Double_t &x, Double_t &y, Double_t &b, Double_t &c, Double_t &d)
Definition: TSpline.h:240
virtual void SetPointCoeff(Int_t i, Double_t b, Double_t c, Double_t d)
Set point coefficient number i.
Definition: TSpline.cxx:1005
Class to create quintic natural splines to interpolate knots Arbitrary conditions can be introduced f...
Definition: TSpline.h:257
static void Test()
Test method for TSpline5.
Definition: TSpline.cxx:2082
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:301
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:1581
void GetKnot(Int_t i, Double_t &x, Double_t &y) const
Definition: TSpline.h:306
TSplinePoly5 * fPoly
[fNp] Array of polynomial terms
Definition: TSpline.h:259
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save primitive as a C++ statement(s) on output stream out.
Definition: TSpline.cxx:1772
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:1816
TSpline5()
Definition: TSpline.h:269
Double_t Derivative(Double_t x) const
Derivative.
Definition: TSpline.cxx:1571
Double_t Eval(Double_t x) const
Eval this spline at x.
Definition: TSpline.cxx:1562
virtual ~TSpline5()
Definition: TSpline.h:300
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:1446
void BuildCoeff()
Algorithm 600, collected algorithms from acm.
Definition: TSpline.cxx:1904
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:1477
Int_t FindX(Double_t x) const
Find X.
Definition: TSpline.cxx:1526
virtual void SetPoint(Int_t i, Double_t x, Double_t y)
Set point number i.
Definition: TSpline.cxx:1805
TSpline5 & operator=(const TSpline5 &)
Assignment operator.
Definition: TSpline.cxx:1429
Class for TSpline3 knot.
Definition: TSpline.h:113
TSplinePoly3(Double_t x, Double_t y, Double_t b, Double_t c, Double_t d)
Definition: TSpline.h:122
Double_t fC
Second order expansion coefficient : fC*2! is the second derivative at x.
Definition: TSpline.h:116
Double_t & D()
Definition: TSpline.h:129
Double_t fD
Third order expansion coefficient : fD*3! is the third derivative at x.
Definition: TSpline.h:117
Double_t Derivative(Double_t x) const
Definition: TSpline.h:134
Double_t Eval(Double_t x) const
Definition: TSpline.h:130
Double_t & C()
Definition: TSpline.h:128
Double_t fB
First order expansion coefficient : fB*1! is the first derivative at x.
Definition: TSpline.h:115
Double_t & B()
Definition: TSpline.h:127
void CopyPoly(TSplinePoly3 const &other)
Utility called by the copy constructors and = operator.
Definition: TSpline.cxx:311
TSplinePoly3()
Definition: TSpline.h:120
TSplinePoly3 & operator=(TSplinePoly3 const &other)
Assignment operator.
Definition: TSpline.cxx:299
Class for TSpline5 knot.
Definition: TSpline.h:154
Double_t & C()
Definition: TSpline.h:172
void CopyPoly(TSplinePoly5 const &other)
Utility called by the copy constructors and = operator.
Definition: TSpline.cxx:338
TSplinePoly5 & operator=(TSplinePoly5 const &other)
Assignment operator.
Definition: TSpline.cxx:326
Double_t fF
Fifth order expansion coefficient : fF*5! is the fifth derivative at x.
Definition: TSpline.h:160
Double_t Derivative(Double_t x) const
Definition: TSpline.h:180
TSplinePoly5()
Definition: TSpline.h:163
Double_t fB
First order expansion coefficient : fB*1! is the first derivative at x.
Definition: TSpline.h:156
Double_t fC
Second order expansion coefficient : fC*2! is the second derivative at x.
Definition: TSpline.h:157
Double_t Eval(Double_t x) const
Definition: TSpline.h:176
Double_t & B()
Definition: TSpline.h:171
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:165
Double_t & F()
Definition: TSpline.h:175
Double_t fD
Third order expansion coefficient : fD*3! is the third derivative at x.
Definition: TSpline.h:158
Double_t & E()
Definition: TSpline.h:174
Double_t fE
Fourth order expansion coefficient : fE*4! is the fourth derivative at x.
Definition: TSpline.h:159
Double_t & D()
Definition: TSpline.h:173
Base class for TSpline knot.
Definition: TSpline.h:78
virtual Double_t Eval(Double_t) const
Definition: TSpline.h:95
Double_t & Y()
Definition: TSpline.h:92
Double_t & X()
Definition: TSpline.h:91
void CopyPoly(TSplinePoly const &other)
Utility called by the copy constructors and = operator.
Definition: TSpline.cxx:285
TSplinePoly & operator=(TSplinePoly const &other)
Assignment operator.
Definition: TSpline.cxx:273
TSplinePoly()
Definition: TSpline.h:84
Double_t fY
Constant term.
Definition: TSpline.h:81
void GetKnot(Double_t &x, Double_t &y) const
Definition: TSpline.h:93
TSplinePoly(Double_t x, Double_t y)
Definition: TSpline.h:86
Double_t fX
Abscissa.
Definition: TSpline.h:80
Base class for spline implementation containing the Draw/Paint methods.
Definition: TSpline.h:31
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TSpline.cxx:122
virtual Double_t Eval(Double_t x) const =0
TH1F * GetHistogram() const
Definition: TSpline.h:62
TGraph * fGraph
Graph for drawing the knots.
Definition: TSpline.h:39
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TSpline.cxx:101
Double_t fXmin
Minimum value of abscissa.
Definition: TSpline.h:34
void SetNpx(Int_t n)
Definition: TSpline.h:70
TH1F * fHistogram
Temporary histogram.
Definition: TSpline.h:38
TSpline()
Definition: TSpline.h:47
Double_t fDelta
Distance between equidistant knots.
Definition: TSpline.h:33
virtual void GetKnot(Int_t i, Double_t &x, Double_t &y) const =0
TSpline & operator=(const TSpline &)
Assignment operator.
Definition: TSpline.cxx:69
virtual Int_t GetNpx() const
Definition: TSpline.h:64
Bool_t fKstep
True of equidistant knots.
Definition: TSpline.h:37
virtual void Paint(Option_t *option="")
Paint this function with its current attributes.
Definition: TSpline.cxx:131
virtual Int_t GetNp() const
Definition: TSpline.h:63
Int_t fNp
Number of knots.
Definition: TSpline.h:36
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a spline.
Definition: TSpline.cxx:113
virtual ~TSpline()
Destructor.
Definition: TSpline.cxx:60
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:49
virtual Double_t GetXmin() const
Definition: TSpline.h:65
virtual Double_t GetDelta() const
Definition: TSpline.h:61
virtual Double_t GetXmax() const
Definition: TSpline.h:66
Double_t fXmax
Maximum value of abscissa.
Definition: TSpline.h:35
virtual void SaveAs(const char *, Option_t *) const
Save this object in the file specified by filename.
Definition: TSpline.h:69
Int_t fNpx
Number of points used for graphical representation.
Definition: TSpline.h:40
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
const Int_t n
Definition: legend1.C:16