ROOT
master
Reference Guide
Loading...
Searching...
No Matches
splines_test.C File Reference
Tutorials
»
Visualisation tutorials
»
Graphics tutorials
Detailed Description
Examples of use of the spline classes.
void
splines_test(
Int_t
np
= 23,
Double_t
a
= -0.5,
Double_t
b
= 31)
{
const
Double_t
power = 0.75;
const
Double_t
eps = (
b
-
a
) * 1.e-5;
// Define the original function
TF1
*
f
=
new
TF1
(
"f"
,
"sin(x)*sin(x/10)"
,
a
- 0.05 * (
b
-
a
),
b
+ 0.05 * (
b
-
a
));
// Draw function
f
->SetLineColor(
kBlue
);
f
->Draw(
"lc"
);
TSpline3
*spline3 =
nullptr
;
TSpline5
*spline5 =
nullptr
;
TLegend
*legend =
nullptr
;
for
(
Int_t
nnp = 2; nnp <=
np
; ++nnp) {
std::vector<Double_t> xx(nnp), yy(nnp);
// Calculate the knots
for
(
Int_t
i = 0; i < nnp; ++i) {
xx[i] =
a
+ (
b
-
a
) *
TMath::Power
(i /
Double_t
(nnp - 1), power);
yy[i] =
f
->Eval(xx[i]);
}
// Evaluate fifth spline coefficients
delete
spline5;
spline5 =
new
TSpline5
(
TString::Format
(
"quintic spline %dknt"
, nnp),
xx.data(),
f
, nnp,
"b1e1b2e2"
,
f
->Derivative(
a
),
f
->Derivative(
b
),
(
f
->Derivative(
a
+ eps) -
f
->Derivative(
a
)) / eps,
(
f
->Derivative(
b
) -
f
->Derivative(
b
- eps)) / eps);
spline5->
SetLineColor
(
kRed
);
spline5->
SetLineWidth
(3);
// Draw the quintic spline
spline5->
Draw
(
"lcsame"
);
// Evaluate third spline coefficients
delete
spline3;
spline3 =
new
TSpline3
(
TString::Format
(
"third spline %dknt"
, nnp),
xx.data(), yy.data(), nnp,
"b1e1"
,
f
->Derivative(
a
),
f
->Derivative(
b
));
spline3->
SetLineColor
(
kGreen
);
spline3->
SetLineWidth
(3);
spline3->
SetMarkerColor
(
kMagenta
);
spline3->
SetMarkerStyle
(20);
spline3->
SetMarkerSize
(1.5);
// Draw the third spline
spline3->
Draw
(
"lcpsame"
);
delete
legend;
legend =
gPad
->BuildLegend(0.6, 0.7, 0.88, 0.88);
gPad
->Update();
gSystem
->Sleep(500);
}
}
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
Signed integer 4 bytes (int)
Definition
RtypesCore.h:59
Double_t
double Double_t
Double 8 bytes.
Definition
RtypesCore.h:73
kRed
@ kRed
Definition
Rtypes.h:67
kGreen
@ kGreen
Definition
Rtypes.h:67
kMagenta
@ kMagenta
Definition
Rtypes.h:67
kBlue
@ kBlue
Definition
Rtypes.h:67
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
gSystem
R__EXTERN TSystem * gSystem
Definition
TSystem.h:582
gPad
#define gPad
Definition
TVirtualPad.h:322
TAttLine::SetLineWidth
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition
TAttLine.h:47
TAttLine::SetLineColor
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition
TAttLine.h:44
TAttMarker::SetMarkerColor
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition
TAttMarker.h:41
TAttMarker::SetMarkerStyle
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition
TAttMarker.h:43
TAttMarker::SetMarkerSize
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition
TAttMarker.h:48
TF1
1-Dim function class
Definition
TF1.h:182
TLegend
This class displays a legend box (TPaveText) containing several legend entries.
Definition
TLegend.h:23
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
TSpline::Draw
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition
TSpline.cxx:95
TString::Format
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition
TString.cxx:2385
TMath::Power
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition
TMath.h:732
Author
Federico Carminati
Definition in file
splines_test.C
.
tutorials
visualisation
graphics
splines_test.C
ROOTmaster - Reference Guide Generated on Tue May 19 2026 19:40:28 (GVA Time) using Doxygen 1.13.2