Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
splines_test.C File Reference

Detailed Description

View in nbviewer Open in SWAN
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);
}
}
#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
Author
Federico Carminati

Definition in file splines_test.C.