{ "cells": [ { "cell_type": "markdown", "id": "fcb25f8e", "metadata": {}, "source": [ "# splines_test\n", "\n", "\n", "\n", "\n", "**Author:** Federico Carminati \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:37 PM." ] }, { "cell_type": "markdown", "id": "9a62a310", "metadata": {}, "source": [ " Arguments are defined. " ] }, { "cell_type": "code", "execution_count": 1, "id": "a50643eb", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:29.602277Z", "iopub.status.busy": "2026-05-19T20:37:29.602150Z", "iopub.status.idle": "2026-05-19T20:37:29.940260Z", "shell.execute_reply": "2026-05-19T20:37:29.939805Z" } }, "outputs": [], "source": [ "Int_t np = 23;\n", "Double_t a = -0.5;\n", "Double_t b = 31;" ] }, { "cell_type": "code", "execution_count": 2, "id": "919e4de1", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:29.952295Z", "iopub.status.busy": "2026-05-19T20:37:29.952157Z", "iopub.status.idle": "2026-05-19T20:37:30.170834Z", "shell.execute_reply": "2026-05-19T20:37:30.170246Z" } }, "outputs": [], "source": [ "const Double_t power = 0.75;\n", "const Double_t eps = (b - a) * 1.e-5;" ] }, { "cell_type": "markdown", "id": "d51a2d7a", "metadata": {}, "source": [ "Define the original function" ] }, { "cell_type": "code", "execution_count": 3, "id": "449128e3", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:30.177674Z", "iopub.status.busy": "2026-05-19T20:37:30.177536Z", "iopub.status.idle": "2026-05-19T20:37:30.388745Z", "shell.execute_reply": "2026-05-19T20:37:30.388118Z" } }, "outputs": [], "source": [ "TF1 *f = new TF1(\"f\", \"sin(x)*sin(x/10)\", a - 0.05 * (b - a), b + 0.05 * (b - a));" ] }, { "cell_type": "markdown", "id": "b0b06508", "metadata": {}, "source": [ "Draw function" ] }, { "cell_type": "code", "execution_count": 4, "id": "3a77bd41", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:30.390446Z", "iopub.status.busy": "2026-05-19T20:37:30.390328Z", "iopub.status.idle": "2026-05-19T20:37:41.861854Z", "shell.execute_reply": "2026-05-19T20:37:41.861374Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Info in : created default TCanvas with name c1\n" ] } ], "source": [ "f->SetLineColor(kBlue);\n", "f->Draw(\"lc\");\n", "\n", "TSpline3 *spline3 = nullptr;\n", "TSpline5 *spline5 = nullptr;\n", "TLegend *legend = nullptr;\n", "\n", "for (Int_t nnp = 2; nnp <= np; ++nnp) {\n", "\n", " std::vector xx(nnp), yy(nnp);\n", "\n", " // Calculate the knots\n", " for (Int_t i = 0; i < nnp; ++i) {\n", " xx[i] = a + (b - a) * TMath::Power(i / Double_t(nnp - 1), power);\n", " yy[i] = f->Eval(xx[i]);\n", " }\n", "\n", " // Evaluate fifth spline coefficients\n", " delete spline5;\n", " spline5 = new TSpline5(TString::Format(\"quintic spline %dknt\", nnp),\n", " xx.data(), f, nnp, \"b1e1b2e2\", f->Derivative(a), f->Derivative(b),\n", " (f->Derivative(a + eps) - f->Derivative(a)) / eps,\n", " (f->Derivative(b) - f->Derivative(b - eps)) / eps);\n", "\n", " spline5->SetLineColor(kRed);\n", " spline5->SetLineWidth(3);\n", "\n", " // Draw the quintic spline\n", " spline5->Draw(\"lcsame\");\n", "\n", " // Evaluate third spline coefficients\n", " delete spline3;\n", " spline3 = new TSpline3(TString::Format(\"third spline %dknt\", nnp),\n", " xx.data(), yy.data(), nnp, \"b1e1\", f->Derivative(a), f->Derivative(b));\n", "\n", " spline3->SetLineColor(kGreen);\n", " spline3->SetLineWidth(3);\n", " spline3->SetMarkerColor(kMagenta);\n", " spline3->SetMarkerStyle(20);\n", " spline3->SetMarkerSize(1.5);\n", "\n", " // Draw the third spline\n", " spline3->Draw(\"lcpsame\");\n", "\n", " delete legend;\n", " legend = gPad->BuildLegend(0.6, 0.7, 0.88, 0.88);\n", "\n", " gPad->Update();\n", "\n", " gSystem->Sleep(500);\n", "}" ] }, { "cell_type": "markdown", "id": "3c505c2f", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "17be51ca", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:37:41.872676Z", "iopub.status.busy": "2026-05-19T20:37:41.872532Z", "iopub.status.idle": "2026-05-19T20:37:42.091882Z", "shell.execute_reply": "2026-05-19T20:37:42.091412Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gROOT->GetListOfCanvases()->Draw()" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }