{ "cells": [ { "cell_type": "markdown", "id": "865aa3ba", "metadata": {}, "source": [ "# rf710_roopoly\n", "Taylor expansion of RooFit functions using the taylorExpand function with RooPolyFunc\n", "\n", "\n", "\n", "\n", "**Author:** Rahul Balasubramanian \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:34 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "9e6a5e07", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:02.144839Z", "iopub.status.busy": "2026-05-19T20:35:02.144733Z", "iopub.status.idle": "2026-05-19T20:35:02.160446Z", "shell.execute_reply": "2026-05-19T20:35:02.159870Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "#include \"RooRealVar.h\"\n", "#include \"RooPolyFunc.h\"\n", "#include \"RooAbsCollection.h\"\n", "#include \"RooPlot.h\"\n", "#include \"TCanvas.h\"\n", "\n", "using namespace RooFit;" ] }, { "cell_type": "markdown", "id": "29b5bfc5", "metadata": {}, "source": [ "Create polynomial\n", "function of fourth order\n", "---------------------------------------------\n", "x^4 - 5x^3 + 5x^2 + 5x -6\n", "---------------------------------------------" ] }, { "cell_type": "code", "execution_count": 2, "id": "eea14192", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:02.162129Z", "iopub.status.busy": "2026-05-19T20:35:02.162004Z", "iopub.status.idle": "2026-05-19T20:35:02.560559Z", "shell.execute_reply": "2026-05-19T20:35:02.559643Z" } }, "outputs": [], "source": [ "RooRealVar x(\"x\", \"x\", 0, -3, 10);\n", "RooPolyFunc f(\"f\", \"f\", RooArgSet(x));\n", "f.addTerm(+1, x, 4);\n", "f.addTerm(-5, x, 3);\n", "f.addTerm(+5, x, 2);\n", "f.addTerm(+5, x, 1);\n", "f.addTerm(-6, x, 0);" ] }, { "cell_type": "markdown", "id": "bff1788c", "metadata": {}, "source": [ "Create taylor expansion\n", "---------------------------------------------" ] }, { "cell_type": "code", "execution_count": 3, "id": "2940a513", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:02.562264Z", "iopub.status.busy": "2026-05-19T20:35:02.562142Z", "iopub.status.idle": "2026-05-19T20:35:02.772584Z", "shell.execute_reply": "2026-05-19T20:35:02.771792Z" } }, "outputs": [], "source": [ "double x0 = 2.0;\n", "auto taylor_o1 = RooPolyFunc::taylorExpand(\"taylor_o1\", \"taylor expansion order 1\", f, {x}, 1, {x0});\n", "auto taylor_o2 = RooPolyFunc::taylorExpand(\"taylor_o2\", \"taylor expansion order 2\", f, {x}, 2, {x0});" ] }, { "cell_type": "markdown", "id": "6ad8e2c4", "metadata": {}, "source": [ "Plot polynomial with first and second order taylor expansion overlaid" ] }, { "cell_type": "code", "execution_count": 4, "id": "e32301bc", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:02.774217Z", "iopub.status.busy": "2026-05-19T20:35:02.774097Z", "iopub.status.idle": "2026-05-19T20:35:02.980327Z", "shell.execute_reply": "2026-05-19T20:35:02.979627Z" } }, "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 : png file rf710_roopoly.png has been created\n" ] } ], "source": [ "auto frame = x.frame(Title(\"x^{4} - 5x^{3} + 5x^{2} + 5x - 6\"));\n", "auto c = new TCanvas(\"rf710_roopoly\", \"rf710_roopoly\", 400, 400);\n", "c->cd();\n", "\n", "f.plotOn(frame, Name(\"f\"));\n", "taylor_o1->plotOn(frame, LineColor(kRed), LineStyle(kDashed), Name(\"taylor_o1\"));\n", "taylor_o2->plotOn(frame, LineColor(kRed - 9), LineStyle(kDotted), Name(\"taylor_o2\"));\n", "\n", "frame->SetMinimum(-8.0);\n", "frame->SetMaximum(+8.0);\n", "frame->SetYTitle(\"function value\");\n", "frame->Draw();\n", "\n", "auto legend = new TLegend(0.53, 0.7, 0.86, 0.87);\n", "legend->SetFillColor(kWhite);\n", "legend->SetLineColor(kWhite);\n", "legend->SetTextSize(0.02);\n", "legend->AddEntry(\"taylor_o1\", \"Taylor expansion upto first order\", \"L\");\n", "legend->AddEntry(\"taylor_o2\", \"Taylor expansion upto second order\", \"L\");\n", "legend->AddEntry(\"f\", \"Polynomial of fourth order\", \"L\");\n", "legend->Draw();\n", "c->Draw();\n", "c->SaveAs(\"rf710_roopoly.png\");" ] }, { "cell_type": "markdown", "id": "3902599a", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "b580e6b7", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:35:02.981942Z", "iopub.status.busy": "2026-05-19T20:35:02.981823Z", "iopub.status.idle": "2026-05-19T20:35:03.197302Z", "shell.execute_reply": "2026-05-19T20:35:03.196533Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%jsroot on\n", "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 }