Logo ROOT  
Reference Guide
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->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
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
@ kRed
Definition Rtypes.h:67
@ kGreen
Definition Rtypes.h:67
@ kMagenta
Definition Rtypes.h:67
@ kBlue
Definition Rtypes.h:67
externTSystem * gSystem
Definition TSystem.h:582
#define gPad
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:41
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:43
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Definition TAttMarker.h:48
Definition TF1.h:182
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
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition TSpline.cxx:95
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
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.