Logo ROOT   6.08/07
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 #ifndef ROOT_TGraph
16 #include "TGraph.h"
17 #endif
18 
19 class TH1;
20 class TF1;
21 
22 class TSpline : public TNamed, public TAttLine,
23  public TAttFill, public TAttMarker
24 {
25 protected:
26  Double_t fDelta; // Distance between equidistant knots
27  Double_t fXmin; // Minimum value of abscissa
28  Double_t fXmax; // Maximum value of abscissa
29  Int_t fNp; // Number of knots
30  Bool_t fKstep; // True of equidistant knots
31  TH1F *fHistogram; // Temporary histogram
32  TGraph *fGraph; // Graph for drawing the knots
33  Int_t fNpx; // Number of points used for graphical representation
34 
35  TSpline(const TSpline&);
36  TSpline& operator=(const TSpline&);
37  virtual void BuildCoeff()=0;
38 
39 public:
40  TSpline() : fDelta(-1), fXmin(0), fXmax(0),
41  fNp(0), fKstep(kFALSE), fHistogram(0), fGraph(0), fNpx(100) {}
42  TSpline(const char *title, Double_t delta, Double_t xmin,
43  Double_t xmax, Int_t np, Bool_t step) :
44  TNamed("Spline",title), TAttFill(0,1),
45  fDelta(delta), fXmin(xmin),
46  fXmax(xmax), fNp(np), fKstep(step),
47  fHistogram(0), fGraph(0), fNpx(100) {}
48  virtual ~TSpline();
49 
50  virtual void GetKnot(Int_t i, Double_t &x, Double_t &y) const =0;
51  virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
52  virtual void Draw(Option_t *option="");
53  virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py);
54  virtual Double_t GetDelta() const {return fDelta;}
55  TH1F *GetHistogram() const {return fHistogram;}
56  virtual Int_t GetNp() const {return fNp;}
57  virtual Int_t GetNpx() const {return fNpx;}
58  virtual Double_t GetXmin() const {return fXmin;}
59  virtual Double_t GetXmax() const {return fXmax;}
60  virtual void Paint(Option_t *option="");
61  virtual Double_t Eval(Double_t x) const=0;
62  virtual void SaveAs(const char * /*filename*/,Option_t * /*option*/) const {;}
63  void SetNpx(Int_t n) {fNpx=n;}
64 
65  ClassDef (TSpline,2) // Spline base class
66 };
67 
68 
69 //______________________________________________________________________________
70 class TSplinePoly : public TObject
71 {
72 protected:
73  Double_t fX; // abscissa
74  Double_t fY; // constant term
75 
76 public:
78  fX(0), fY(0) {}
80  fX(x), fY(y) {}
81  TSplinePoly(TSplinePoly const &other);
82  TSplinePoly &operator=(TSplinePoly const &other);
83 
84  Double_t &X() {return fX;}
85  Double_t &Y() {return fY;}
86  void GetKnot(Double_t &x, Double_t &y) const {x=fX; y=fY;}
87 
88  virtual Double_t Eval(Double_t) const {return fY;}
89 
90  private:
91  void CopyPoly(TSplinePoly const &other);
92 
93  ClassDef(TSplinePoly,2) // Spline polynomial terms
94 };
95 
97 :
98  TObject(other), fX(0), fY(0)
99 {
100  CopyPoly(other);
101 }
102 
103 
104 //______________________________________________________________________________
105 class TSplinePoly3 : public TSplinePoly
106 {
107 private:
108  Double_t fB; // first order expansion coefficient : fB*1! is the first derivative at x
109  Double_t fC; // second order expansion coefficient : fC*2! is the second derivative at x
110  Double_t fD; // third order expansion coefficient : fD*3! is the third derivative at x
111 
112 public:
114  fB(0), fC(0), fD(0) {}
116  TSplinePoly(x,y), fB(b), fC(c), fD(d) {}
117  TSplinePoly3(TSplinePoly3 const &other);
118  TSplinePoly3 &operator=(TSplinePoly3 const &other);
119 
120  Double_t &B() {return fB;}
121  Double_t &C() {return fC;}
122  Double_t &D() {return fD;}
124  Double_t dx=x-fX;
125  return (fY+dx*(fB+dx*(fC+dx*fD)));
126  }
128  Double_t dx=x-fX;
129  return (fB+dx*(2*fC+3*fD*dx));
130  }
131 
132 private:
133  void CopyPoly(TSplinePoly3 const &other);
134 
135  ClassDef(TSplinePoly3,1) // Third spline polynomial terms
136 };
137 
139  :
140  TSplinePoly(other), fB(0), fC(0), fD(0)
141 {
142  CopyPoly(other);
143 }
144 
145 //______________________________________________________________________________
146 class TSplinePoly5 : public TSplinePoly
147 {
148 private:
149  Double_t fB; // first order expansion coefficient : fB*1! is the first derivative at x
150  Double_t fC; // second order expansion coefficient : fC*2! is the second derivative at x
151  Double_t fD; // third order expansion coefficient : fD*3! is the third derivative at x
152  Double_t fE; // fourth order expansion coefficient : fE*4! is the fourth derivative at x
153  Double_t fF; // fifth order expansion coefficient : fF*5! is the fifth derivative at x
154 
155 public:
157  fB(0), fC(0), fD(0), fE(0), fF(0) {}
159  Double_t d, Double_t e, Double_t f) :
160  TSplinePoly(x,y), fB(b), fC(c), fD(d), fE(e), fF(f) {}
161  TSplinePoly5(TSplinePoly5 const &other);
162  TSplinePoly5 &operator=(TSplinePoly5 const &other);
163 
164  Double_t &B() {return fB;}
165  Double_t &C() {return fC;}
166  Double_t &D() {return fD;}
167  Double_t &E() {return fE;}
168  Double_t &F() {return fF;}
170  Double_t dx=x-fX;
171  return (fY+dx*(fB+dx*(fC+dx*(fD+dx*(fE+dx*fF)))));
172  }
174  Double_t dx=x-fX;
175  return (fB+dx*(2*fC+dx*(3*fD+dx*(4*fE+dx*(5*fF)))));
176  }
177 
178 private:
179  void CopyPoly(TSplinePoly5 const &other);
180 
181  ClassDef(TSplinePoly5,1) // Quintic spline polynomial terms
182 };
183 
185 :
186  TSplinePoly(other), fB(0), fC(0), fD(0), fE(0), fF(0)
187 {
188  CopyPoly(other);
189 }
190 
191 
192 //______________________________________________________________________________
193 class TSpline3 : public TSpline
194 {
195 protected:
196  TSplinePoly3 *fPoly; //[fNp] Array of polynomial terms
197  Double_t fValBeg; // Initial value of first or second derivative
198  Double_t fValEnd; // End value of first or second derivative
199  Int_t fBegCond; // 0=no beg cond, 1=first derivative, 2=second derivative
200  Int_t fEndCond; // 0=no end cond, 1=first derivative, 2=second derivative
201 
202  void BuildCoeff();
203  void SetCond(const char *opt);
204 
205 public:
206  TSpline3() : TSpline() , fPoly(0), fValBeg(0), fValEnd(0),
207  fBegCond(-1), fEndCond(-1) {}
208  TSpline3(const char *title,
209  Double_t x[], Double_t y[], Int_t n, const char *opt=0,
210  Double_t valbeg=0, Double_t valend=0);
211  TSpline3(const char *title,
213  Double_t y[], Int_t n, const char *opt=0,
214  Double_t valbeg=0, Double_t valend=0);
215  TSpline3(const char *title,
216  Double_t x[], const TF1 *func, Int_t n, const char *opt=0,
217  Double_t valbeg=0, Double_t valend=0);
218  TSpline3(const char *title,
219  Double_t xmin, Double_t xmax,
220  const TF1 *func, Int_t n, const char *opt=0,
221  Double_t valbeg=0, Double_t valend=0);
222  TSpline3(const char *title,
223  const TGraph *g, const char *opt=0,
224  Double_t valbeg=0, Double_t valend=0);
225  TSpline3(const TH1 *h, const char *opt=0,
226  Double_t valbeg=0, Double_t valend=0);
227  TSpline3(const TSpline3&);
228  TSpline3& operator=(const TSpline3&);
229  Int_t FindX(Double_t x) const;
230  Double_t Eval(Double_t x) const;
231  Double_t Derivative(Double_t x) const;
232  virtual ~TSpline3() {if (fPoly) delete [] fPoly;}
234  Double_t &c, Double_t &d) {x=fPoly[i].X();y=fPoly[i].Y();
235  b=fPoly[i].B();c=fPoly[i].C();d=fPoly[i].D();}
236  void GetKnot(Int_t i, Double_t &x, Double_t &y) const
237  {x=fPoly[i].X(); y=fPoly[i].Y();}
238  virtual void SaveAs(const char *filename,Option_t *option="") const;
239  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
240  virtual void SetPoint(Int_t i, Double_t x, Double_t y);
241  virtual void SetPointCoeff(Int_t i, Double_t b, Double_t c, Double_t d);
242  static void Test();
243 
244  ClassDef (TSpline3,2) // Class to create third natural splines
245 };
246 
247 
248 //______________________________________________________________________________
249 class TSpline5 : public TSpline
250 {
251 protected:
252  TSplinePoly5 *fPoly; //[fNp] Array of polynomial terms
253 
254  void BuildCoeff();
255  void BoundaryConditions(const char *opt, Int_t &beg, Int_t &end,
256  const char *&cb1, const char *&ce1, const char *&cb2,
257  const char *&ce2);
258  void SetBoundaries(Double_t b1, Double_t e1, Double_t b2, Double_t e2,
259  const char *cb1, const char *ce1, const char *cb2,
260  const char *ce2);
261 public:
262  TSpline5() : TSpline() , fPoly(0) {}
263  TSpline5(const char *title,
264  Double_t x[], Double_t y[], Int_t n,
265  const char *opt=0, Double_t b1=0, Double_t e1=0,
266  Double_t b2=0, Double_t e2=0);
267  TSpline5(const char *title,
269  Double_t y[], Int_t n,
270  const char *opt=0, Double_t b1=0, Double_t e1=0,
271  Double_t b2=0, Double_t e2=0);
272  TSpline5(const char *title,
273  Double_t x[], const TF1 *func, Int_t n,
274  const char *opt=0, Double_t b1=0, Double_t e1=0,
275  Double_t b2=0, Double_t e2=0);
276  TSpline5(const char *title,
277  Double_t xmin, Double_t xmax,
278  const TF1 *func, Int_t n,
279  const char *opt=0, Double_t b1=0, Double_t e1=0,
280  Double_t b2=0, Double_t e2=0);
281  TSpline5(const char *title,
282  const TGraph *g,
283  const char *opt=0, Double_t b1=0, Double_t e1=0,
284  Double_t b2=0, Double_t e2=0);
285  TSpline5(const TH1 *h,
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 TSpline5&);
289  TSpline5& operator=(const TSpline5&);
290  Int_t FindX(Double_t x) const;
291  Double_t Eval(Double_t x) const;
292  Double_t Derivative(Double_t x) const;
293  virtual ~TSpline5() {if (fPoly) delete [] fPoly;}
296  {x=fPoly[i].X();y=fPoly[i].Y();b=fPoly[i].B();
297  c=fPoly[i].C();d=fPoly[i].D();
298  e=fPoly[i].E();f=fPoly[i].F();}
299  void GetKnot(Int_t i, Double_t &x, Double_t &y) const
300  {x=fPoly[i].X(); y=fPoly[i].Y();}
301  virtual void SaveAs(const char *filename,Option_t *option="") const;
302  virtual void SavePrimitive(std::ostream &out, Option_t *option = "");
303  virtual void SetPoint(Int_t i, Double_t x, Double_t y);
304  virtual void SetPointCoeff(Int_t i, Double_t b, Double_t c, Double_t d,
305  Double_t e, Double_t f);
306  static void Test();
307 
308  ClassDef (TSpline5,2) // Class to create quintic natural splines
309 };
310 
311 #endif
TSplinePoly3(Double_t x, Double_t y, Double_t b, Double_t c, Double_t d)
Definition: TSpline.h:115
TSplinePoly5()
Definition: TSpline.h:156
TSplinePoly3 & operator=(TSplinePoly3 const &other)
assignment operator
Definition: TSpline.cxx:311
TSplinePoly & operator=(TSplinePoly const &other)
assignment operator
Definition: TSpline.cxx:281
float xmin
Definition: THbookFile.cxx:93
TSpline3()
Definition: TSpline.h:206
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TSpline.cxx:123
void GetKnot(Double_t &x, Double_t &y) const
Definition: TSpline.h:86
TSplinePoly(Double_t x, Double_t y)
Definition: TSpline.h:79
return c
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a spline.
Definition: TSpline.cxx:113
const char Option_t
Definition: RtypesCore.h:62
Double_t fE
Definition: TSpline.h:152
Double_t fF
Definition: TSpline.h:153
Double_t fX
Definition: TSpline.h:73
Double_t fValBeg
Definition: TSpline.h:197
Double_t & Y()
Definition: TSpline.h:85
Double_t & E()
Definition: TSpline.h:167
Double_t fB
Definition: TSpline.h:108
TH1 * h
Definition: legend2.C:5
Base class for spline implementation containing the Draw/Paint methods //.
Definition: TSpline.h:22
Double_t & C()
Definition: TSpline.h:165
Double_t fD
Definition: TSpline.h:110
void CopyPoly(TSplinePoly3 const &other)
utility called by the copy constructors and = operator
Definition: TSpline.cxx:323
virtual Double_t GetXmax() const
Definition: TSpline.h:59
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:575
virtual Double_t GetXmin() const
Definition: TSpline.h:58
int Int_t
Definition: RtypesCore.h:41
virtual ~TSpline5()
Definition: TSpline.h:293
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual Int_t GetNpx() const
Definition: TSpline.h:57
Int_t fNp
Definition: TSpline.h:29
void GetKnot(Int_t i, Double_t &x, Double_t &y) const
Definition: TSpline.h:236
Marker Attributes class.
Definition: TAttMarker.h:24
virtual Double_t GetDelta() const
Definition: TSpline.h:54
Double_t & B()
Definition: TSpline.h:164
void GetKnot(Int_t i, Double_t &x, Double_t &y) const
Definition: TSpline.h:299
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:158
Double_t fDelta
Definition: TSpline.h:26
Fill Area Attributes class.
Definition: TAttFill.h:24
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual void SaveAs(const char *filename="", Option_t *option="") const
Save this object in the file specified by filename.
Definition: TObject.cxx:644
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
void CopyPoly(TSplinePoly const &other)
utility called by the copy constructors and = operator
Definition: TSpline.cxx:293
TSpline & operator=(const TSpline &)
assignment operator
Definition: TSpline.cxx:68
TSplinePoly5 * fPoly
Definition: TSpline.h:252
Double_t & X()
Definition: TSpline.h:84
TSpline5()
Definition: TSpline.h:262
TGraph * fGraph
Definition: TSpline.h:32
Double_t fXmax
Definition: TSpline.h:28
Double_t Derivative(Double_t x) const
Definition: TSpline.h:127
Double_t & F()
Definition: TSpline.h:168
Double_t fC
Definition: TSpline.h:109
Bool_t fKstep
Definition: TSpline.h:30
TSplinePoly5 & operator=(TSplinePoly5 const &other)
assignment operator
Definition: TSpline.cxx:342
TSpline()
Definition: TSpline.h:40
Double_t & C()
Definition: TSpline.h:121
Double_t Derivative(Double_t x) const
Definition: TSpline.h:173
Int_t fBegCond
Definition: TSpline.h:199
Int_t fEndCond
Definition: TSpline.h:200
void SetNpx(Int_t n)
Definition: TSpline.h:63
TSplinePoly3 * fPoly
Definition: TSpline.h:196
Double_t Eval(Double_t x) const
Definition: TSpline.h:123
virtual void SaveAs(const char *, Option_t *) const
Save this object in the file specified by filename.
Definition: TSpline.h:62
virtual Double_t Eval(Double_t x) const =0
Double_t fC
Definition: TSpline.h:150
float xmax
Definition: THbookFile.cxx:93
Double_t & B()
Definition: TSpline.h:120
Double_t fD
Definition: TSpline.h:151
TH1F * fHistogram
Definition: TSpline.h:31
virtual void GetKnot(Int_t i, Double_t &x, Double_t &y) const =0
virtual ~TSpline()
destructor
Definition: TSpline.cxx:58
virtual Double_t Eval(Double_t) const
Definition: TSpline.h:88
TSpline(const char *title, Double_t delta, Double_t xmin, Double_t xmax, Int_t np, Bool_t step)
Definition: TSpline.h:42
double f(double x)
double Double_t
Definition: RtypesCore.h:55
Int_t fNpx
Definition: TSpline.h:33
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TSpline.cxx:100
Double_t & D()
Definition: TSpline.h:166
Double_t y[n]
Definition: legend1.C:17
double func(double *x, double *p)
Definition: stressTF1.cxx:213
The TH1 histogram class.
Definition: TH1.h:80
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
Double_t fB
Definition: TSpline.h:149
Mother of all ROOT objects.
Definition: TObject.h:37
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:294
void GetCoeff(Int_t i, Double_t &x, Double_t &y, Double_t &b, Double_t &c, Double_t &d)
Definition: TSpline.h:233
Double_t fXmin
Definition: TSpline.h:27
TSplinePoly3()
Definition: TSpline.h:113
1-Dim function class
Definition: TF1.h:149
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
virtual void Paint(Option_t *option="")
Paint this function with its current attributes.
Definition: TSpline.cxx:133
virtual ~TSpline3()
Definition: TSpline.h:232
Double_t & D()
Definition: TSpline.h:122
TSplinePoly()
Definition: TSpline.h:77
void CopyPoly(TSplinePoly5 const &other)
utility called by the copy constructors and = operator
Definition: TSpline.cxx:354
Double_t fValEnd
Definition: TSpline.h:198
TH1F * GetHistogram() const
Definition: TSpline.h:55
const Int_t n
Definition: legend1.C:16
Line Attributes class.
Definition: TAttLine.h:24
virtual Int_t GetNp() const
Definition: TSpline.h:56
Double_t Eval(Double_t x) const
Definition: TSpline.h:169
virtual void BuildCoeff()=0
Double_t fY
Definition: TSpline.h:74
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:709