Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
splines_test.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// \notebook
4/// \preview Examples of use of the spline classes.
5///
6/// \macro_image
7/// \macro_code
8///
9/// \author Federico Carminati
10
11void splines_test(Int_t np = 23, Double_t a = -0.5, Double_t b = 31)
12{
13 const Double_t power = 0.75;
14 const Double_t eps = (b - a) * 1.e-5;
15
16 // Define the original function
17 TF1 *f = new TF1("f", "sin(x)*sin(x/10)", a - 0.05 * (b - a), b + 0.05 * (b - a));
18 // Draw function
19 f->SetLineColor(kBlue);
20 f->Draw("lc");
21
22 TSpline3 *spline3 = nullptr;
23 TSpline5 *spline5 = nullptr;
24 TLegend *legend = nullptr;
25
26 for (Int_t nnp = 2; nnp <= np; ++nnp) {
27
28 std::vector<Double_t> xx(nnp), yy(nnp);
29
30 // Calculate the knots
31 for (Int_t i = 0; i < nnp; ++i) {
32 xx[i] = a + (b - a) * TMath::Power(i / Double_t(nnp - 1), power);
33 yy[i] = f->Eval(xx[i]);
34 }
35
36 // Evaluate fifth spline coefficients
37 delete spline5;
38 spline5 = new TSpline5(TString::Format("quintic spline %dknt", nnp),
39 xx.data(), f, nnp, "b1e1b2e2", f->Derivative(a), f->Derivative(b),
40 (f->Derivative(a + eps) - f->Derivative(a)) / eps,
41 (f->Derivative(b) - f->Derivative(b - eps)) / eps);
42
43 spline5->SetLineColor(kRed);
44 spline5->SetLineWidth(3);
45
46 // Draw the quintic spline
47 spline5->Draw("lcsame");
48
49 // Evaluate third spline coefficients
50 delete spline3;
51 spline3 = new TSpline3(TString::Format("third spline %dknt", nnp),
52 xx.data(), yy.data(), nnp, "b1e1", f->Derivative(a), f->Derivative(b));
53
54 spline3->SetLineColor(kGreen);
55 spline3->SetLineWidth(3);
56 spline3->SetMarkerColor(kMagenta);
57 spline3->SetMarkerStyle(20);
58 spline3->SetMarkerSize(1.5);
59
60 // Draw the third spline
61 spline3->Draw("lcpsame");
62
63 delete legend;
64 legend = gPad->BuildLegend(0.6, 0.7, 0.88, 0.88);
65
66 gPad->Update();
67
68 gSystem->Sleep(500);
69 }
70}
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kRed
Definition Rtypes.h:66
@ kGreen
Definition Rtypes.h:66
@ kMagenta
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
R__EXTERN TSystem * gSystem
Definition TSystem.h:572
#define gPad
1-Dim function class
Definition TF1.h:234
This class displays a legend box (TPaveText) containing several legend entries.
Definition TLegend.h:23
Class to create third splines to interpolate knots Arbitrary conditions can be introduced for first a...
Definition TSpline.h:182
Class to create quintic natural splines to interpolate knots Arbitrary conditions can be introduced f...
Definition TSpline.h:238
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:2378
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:437
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition TMath.h:725