ROOT
v6-32
Reference Guide
Loading...
Searching...
No Matches
splines_test.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_graphs
3
/// \notebook
4
/// Examples of use of the spline classes.
5
///
6
/// \macro_image
7
/// \macro_code
8
///
9
/// \author Federico Carminati
10
11
void
splines_test
(
Int_t
np
=23,
Double_t
a
=-0.5,
Double_t
b
=31)
12
{
13
// array of points
14
Double_t
*
xx
=0, *
yy
=0;
15
TSpline3
*
spline3
=0;
16
TSpline5
*
spline5
=0;
17
TLine
*
line5
, *
line3
;
18
TText
*
text5
, *
text3
, *
textn
;
19
char
text
[20];
20
const
Double_t
power
=0.75;
21
22
// Define the original function
23
TF1
*
f
=
new
TF1
(
"f"
,
"sin(x)*sin(x/10)"
,
24
a
-0.05*(
b
-
a
),
b
+0.05*(
b
-
a
));
25
// Draw function
26
f
->Draw(
"lc"
);
27
28
// Create text and legend
29
Double_t
xx1
,
yy1
,
xx2
,
yy2
,
dx
,
dy
;
30
gPad
->Update();
31
gPad
->GetRangeAxis(
xx1
,
yy1
,
xx2
,
yy2
);
32
dx
=
xx2
-
xx1
;
33
dy
=
yy2
-
yy1
;
34
line5
=
new
TLine
(
xx1
+
dx
*0.3,
yy1
+
dy
*1.02,
35
xx1
+
dx
*0.38,
yy1
+
dy
*1.02);
36
line5
->SetLineColor(
kRed
);
37
line5
->SetLineWidth(2);
38
text5
=
new
TText
(
xx1
+
dx
*0.4,
39
yy1
+
dy
*1.03,
"quintic spline"
);
40
text5
->SetTextAlign(12);
41
text5
->SetTextSize(0.04);
42
line3
=
new
TLine
(
xx1
+
dx
*0.67,
yy1
+
dy
*1.02,
43
xx1
+
dx
*0.75,
yy1
+
dy
*1.02);
44
line3
->SetLineColor(
kGreen
);
45
line3
->SetLineWidth(2);
46
text3
=
new
TText
(
xx1
+
dx
*0.77,
47
yy1
+
dy
*1.03,
"third spline"
);
48
text3
->SetTextAlign(12);
49
text3
->SetTextSize(0.04);
50
textn
=
new
TText
(
xx1
+
dx
*0.8,
yy1
+
dy
*0.91,
" "
);
51
textn
->SetTextAlign(12);
52
textn
->SetTextSize(0.04);
53
textn
->Draw();
54
55
// Draw legenda
56
line5
->Draw();
57
text5
->Draw();
58
line3
->Draw();
59
text3
->Draw();
60
61
for
(
Int_t
nnp
=2;
nnp
<=
np
; ++
nnp
) {
62
63
// Calculate the knots
64
if
(
xx
)
delete
[]
xx
;
65
xx
=
new
Double_t
[
nnp
];
66
if
(
yy
)
delete
[]
yy
;
67
yy
=
new
Double_t
[
nnp
];
68
for
(
Int_t
i=0; i<
nnp
; ++i) {
69
xx
[i]=
a
+(
b
-
a
)*
TMath::Power
(i/
Double_t
(
nnp
-1),
power
);
70
yy
[i]=
f
->Eval(
xx
[i]);
71
}
72
73
// Evaluate fifth spline coefficients
74
Double_t
eps=(
b
-
a
)*1.e-5;
75
if
(
spline5
)
delete
spline5
;
76
spline5
=
new
TSpline5
(
"Test"
,
xx
,
f
,
nnp
,
"b1e1b2e2"
,
77
f
->Derivative(
a
),
f
->Derivative(
b
),
78
(
f
->Derivative(
a
+eps)-
f
->Derivative(
a
))/eps,
79
(
f
->Derivative(
b
)-
f
->Derivative(
b
-eps))/eps);
80
81
spline5
->SetLineColor(
kRed
);
82
spline5
->SetLineWidth(3);
83
84
// Draw the quintic spline
85
spline5
->Draw(
"lcsame"
);
86
87
// Evaluate third spline coefficients
88
if
(
spline3
)
delete
spline3
;
89
spline3
=
new
TSpline3
(
"Test"
,
xx
,
yy
,
nnp
,
"b1e1"
,
90
f
->Derivative(
a
),
f
->Derivative(
b
));
91
92
spline3
->SetLineColor(
kGreen
);
93
spline3
->SetLineWidth(3);
94
spline3
->SetMarkerColor(
kBlue
);
95
spline3
->SetMarkerStyle(20);
96
spline3
->SetMarkerSize(1.5);
97
98
// Draw the third spline
99
spline3
->Draw(
"lcpsame"
);
100
101
sprintf
(
text
,
"%3d knots"
,
nnp
);
102
textn
->SetTitle(
text
);
103
gPad
->Update();
104
105
//
106
gSystem
->
Sleep
(500);
107
}
108
}
b
#define b(i)
Definition
RSha256.hxx:100
f
#define f(i)
Definition
RSha256.hxx:104
a
#define a(i)
Definition
RSha256.hxx:99
Int_t
int Int_t
Definition
RtypesCore.h:45
Double_t
double Double_t
Definition
RtypesCore.h:59
kRed
@ kRed
Definition
Rtypes.h:66
kGreen
@ kGreen
Definition
Rtypes.h:66
kBlue
@ kBlue
Definition
Rtypes.h:66
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Definition
TGWin32VirtualXProxy.cxx:222
text
Option_t Option_t TPoint TPoint const char text
Definition
TGWin32VirtualXProxy.cxx:68
gSystem
R__EXTERN TSystem * gSystem
Definition
TSystem.h:566
gPad
#define gPad
Definition
TVirtualPad.h:305
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TF1
1-Dim function class
Definition
TF1.h:233
TLine
Use the TLine constructor to create a simple line.
Definition
TLine.h:22
TSpline3
Class to create third splines to interpolate knots Arbitrary conditions can be introduced for first a...
Definition
TSpline.h:182
TSpline5
Class to create quintic natural splines to interpolate knots Arbitrary conditions can be introduced f...
Definition
TSpline.h:238
TSystem::Sleep
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition
TSystem.cxx:437
TText
Base class for several text objects.
Definition
TText.h:22
TMath::Power
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition
TMath.h:721
tutorials
graphs
splines_test.C
ROOT v6-32 - Reference Guide Generated on Mon Feb 24 2025 14:13:19 (GVA Time) using Doxygen 1.10.0