Logo ROOT   6.12/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 #include "TGraph.h"
16 
17 class TH1;
18 class TF1;
19 
20 class TSpline : public TNamed, public TAttLine,
21  public TAttFill, public TAttMarker
22 {
23 protected:
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 
37 public:
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 //______________________________________________________________________________
68 class TSplinePoly : public TObject
69 {
70 protected:
71  Double_t fX; // abscissa
72  Double_t fY; // constant term
73 
74 public:
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 //______________________________________________________________________________
103 class TSplinePoly3 : public TSplinePoly
104 {
105 private:
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 
110 public:
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 
130 private:
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 //______________________________________________________________________________
144 class TSplinePoly5 : public TSplinePoly
145 {
146 private:
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 
153 public:
155  fB(0), fC(0), fD(0), fE(0), fF(0) {}
157  Double_t d, Double_t e, Double_t f) :
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 
176 private:
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 //______________________________________________________________________________
191 class TSpline3 : public TSpline
192 {
193 protected:
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 
203 public:
204  TSpline3() : TSpline() , fPoly(0), fValBeg(0), fValEnd(0),
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,
217  Double_t xmin, Double_t xmax,
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;
229  Double_t Derivative(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 //______________________________________________________________________________
247 class TSpline5 : public TSpline
248 {
249 protected:
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);
259 public:
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,
275  Double_t xmin, Double_t xmax,
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;
290  Double_t Derivative(Double_t x) const;
291  virtual ~TSpline5() {if (fPoly) delete [] fPoly;}
293  Double_t &c, Double_t &d, Double_t &e, Double_t &f)
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,
303  Double_t e, Double_t f);
304  static void Test();
305 
306  ClassDef (TSpline5,2) // Class to create quintic natural splines
307 };
308 
309 #endif
Class for TSpline3 knot.
Definition: TSpline.h:103
TSplinePoly3(Double_t x, Double_t y, Double_t b, Double_t c, Double_t d)
Definition: TSpline.h:113
TSplinePoly5()
Definition: TSpline.h:154
TSplinePoly3 & operator=(TSplinePoly3 const &other)
Assignment operator.
Definition: TSpline.cxx:295
TSplinePoly & operator=(TSplinePoly const &other)
Assignment operator.
Definition: TSpline.cxx:269
float xmin
Definition: THbookFile.cxx:93
TSpline3()
Definition: TSpline.h:204
virtual void ExecuteEvent(Int_t event, Int_t px, Int_t py)
Execute action corresponding to one event.
Definition: TSpline.cxx:118
void GetKnot(Double_t &x, Double_t &y) const
Definition: TSpline.h:84
TSplinePoly(Double_t x, Double_t y)
Definition: TSpline.h:77
virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
Compute distance from point px,py to a spline.
Definition: TSpline.cxx:109
const char Option_t
Definition: RtypesCore.h:62
Double_t fE
Definition: TSpline.h:150
Double_t fF
Definition: TSpline.h:151
Double_t fX
Definition: TSpline.h:71
Double_t fValBeg
Definition: TSpline.h:195
Double_t & Y()
Definition: TSpline.h:83
Double_t & E()
Definition: TSpline.h:165
Double_t fB
Definition: TSpline.h:106
TH1 * h
Definition: legend2.C:5
Base class for spline implementation containing the Draw/Paint methods.
Definition: TSpline.h:20
Double_t & C()
Definition: TSpline.h:163
Double_t fD
Definition: TSpline.h:108
void CopyPoly(TSplinePoly3 const &other)
Utility called by the copy constructors and = operator.
Definition: TSpline.cxx:307
virtual Double_t GetXmax() const
Definition: TSpline.h:57
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:567
virtual Double_t GetXmin() const
Definition: TSpline.h:56
int Int_t
Definition: RtypesCore.h:41
virtual ~TSpline5()
Definition: TSpline.h:291
bool Bool_t
Definition: RtypesCore.h:59
virtual Int_t GetNpx() const
Definition: TSpline.h:55
Int_t fNp
Definition: TSpline.h:27
Class to create third splines to interpolate knots Arbitrary conditions can be introduced for first a...
Definition: TSpline.h:191
void GetKnot(Int_t i, Double_t &x, Double_t &y) const
Definition: TSpline.h:234
Marker Attributes class.
Definition: TAttMarker.h:19
virtual Double_t GetDelta() const
Definition: TSpline.h:52
Double_t & B()
Definition: TSpline.h:162
void GetKnot(Int_t i, Double_t &x, Double_t &y) const
Definition: TSpline.h:297
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 fDelta
Definition: TSpline.h:24
Fill Area Attributes class.
Definition: TAttFill.h:19
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:320
virtual void SaveAs(const char *filename="", Option_t *option="") const
Save this object in the file specified by filename.
Definition: TObject.cxx:599
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Base class for TSpline knot.
Definition: TSpline.h:68
void CopyPoly(TSplinePoly const &other)
Utility called by the copy constructors and = operator.
Definition: TSpline.cxx:281
TSpline & operator=(const TSpline &)
Assignment operator.
Definition: TSpline.cxx:65
TSplinePoly5 * fPoly
Definition: TSpline.h:250
Double_t & X()
Definition: TSpline.h:82
TSpline5()
Definition: TSpline.h:260
TGraph * fGraph
Definition: TSpline.h:30
Double_t fXmax
Definition: TSpline.h:26
Double_t Derivative(Double_t x) const
Definition: TSpline.h:125
Double_t & F()
Definition: TSpline.h:166
Double_t fC
Definition: TSpline.h:107
Bool_t fKstep
Definition: TSpline.h:28
TSplinePoly5 & operator=(TSplinePoly5 const &other)
Assignment operator.
Definition: TSpline.cxx:322
TSpline()
Definition: TSpline.h:38
Double_t & C()
Definition: TSpline.h:119
Double_t Derivative(Double_t x) const
Definition: TSpline.h:171
Int_t fBegCond
Definition: TSpline.h:197
Class for TSpline5 knot.
Definition: TSpline.h:144
Int_t fEndCond
Definition: TSpline.h:198
void SetNpx(Int_t n)
Definition: TSpline.h:61
TSplinePoly3 * fPoly
Definition: TSpline.h:194
Double_t Eval(Double_t x) const
Definition: TSpline.h:121
virtual void SaveAs(const char *, Option_t *) const
Save this object in the file specified by filename.
Definition: TSpline.h:60
virtual Double_t Eval(Double_t x) const =0
Double_t fC
Definition: TSpline.h:148
float xmax
Definition: THbookFile.cxx:93
Double_t & B()
Definition: TSpline.h:118
Double_t fD
Definition: TSpline.h:149
TH1F * fHistogram
Definition: TSpline.h:29
const Bool_t kFALSE
Definition: RtypesCore.h:88
virtual void GetKnot(Int_t i, Double_t &x, Double_t &y) const =0
virtual ~TSpline()
Destructor.
Definition: TSpline.cxx:56
virtual Double_t Eval(Double_t) const
Definition: TSpline.h:86
TSpline(const char *title, Double_t delta, Double_t xmin, Double_t xmax, Int_t np, Bool_t step)
Definition: TSpline.h:40
double Double_t
Definition: RtypesCore.h:55
Int_t fNpx
Definition: TSpline.h:31
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TSpline.cxx:97
Double_t & D()
Definition: TSpline.h:164
Double_t y[n]
Definition: legend1.C:17
The TH1 histogram class.
Definition: TH1.h:56
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:147
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:292
void GetCoeff(Int_t i, Double_t &x, Double_t &y, Double_t &b, Double_t &c, Double_t &d)
Definition: TSpline.h:231
Double_t fXmin
Definition: TSpline.h:25
TSplinePoly3()
Definition: TSpline.h:111
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
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
Class to create quintic natural splines to interpolate knots Arbitrary conditions can be introduced f...
Definition: TSpline.h:247
virtual void Paint(Option_t *option="")
Paint this function with its current attributes.
Definition: TSpline.cxx:127
virtual ~TSpline3()
Definition: TSpline.h:230
Double_t & D()
Definition: TSpline.h:120
TSplinePoly()
Definition: TSpline.h:75
void CopyPoly(TSplinePoly5 const &other)
Utility called by the copy constructors and = operator.
Definition: TSpline.cxx:334
Double_t fValEnd
Definition: TSpline.h:196
TH1F * GetHistogram() const
Definition: TSpline.h:53
const Int_t n
Definition: legend1.C:16
Line Attributes class.
Definition: TAttLine.h:18
virtual Int_t GetNp() const
Definition: TSpline.h:54
Double_t Eval(Double_t x) const
Definition: TSpline.h:167
virtual void BuildCoeff()=0
Double_t fY
Definition: TSpline.h:72
virtual void SavePrimitive(std::ostream &out, Option_t *option="")
Save a primitive as a C++ statement(s) on output stream "out".
Definition: TObject.cxx:664
static constexpr double g