{ "cells": [ { "cell_type": "markdown", "id": "4dadac84", "metadata": {}, "source": [ "# pdf009_Bessel\n", "Show the different kinds of Bessel functions available in ROOT\n", "To execute the macro type in:\n", "\n", "```cpp\n", "root[0] .x Bessel.C\n", "```\n", "\n", "It will create one canvas with the representation\n", "of the cylindrical and spherical Bessel functions\n", "regular and modified\n", "\n", "\n", "\n", "\n", "**Author:** Magdalena Slawinska \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:26 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "df62b832", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:49.508364Z", "iopub.status.busy": "2026-05-19T20:26:49.508237Z", "iopub.status.idle": "2026-05-19T20:26:49.848361Z", "shell.execute_reply": "2026-05-19T20:26:49.847565Z" } }, "outputs": [], "source": [ "TCanvas *DistCanvas = new TCanvas(\"DistCanvas\", \"Bessel functions example\", 10, 10, 800, 600);\n", "DistCanvas->SetFillColor(17);\n", "DistCanvas->Divide(2, 2);\n", "DistCanvas->cd(1);\n", "gPad->SetGrid();\n", "gPad->SetFrameFillColor(19);\n", "TLegend *leg = new TLegend(0.75, 0.7, 0.89, 0.89);\n", "\n", "int n = 5; //number of functions in each pad" ] }, { "cell_type": "markdown", "id": "c8bc12e7", "metadata": {}, "source": [ "drawing the set of Bessel J functions" ] }, { "cell_type": "code", "execution_count": 2, "id": "3d752791", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:49.850216Z", "iopub.status.busy": "2026-05-19T20:26:49.850093Z", "iopub.status.idle": "2026-05-19T20:26:50.057300Z", "shell.execute_reply": "2026-05-19T20:26:50.056511Z" } }, "outputs": [], "source": [ "TF1* JBessel[5];\n", "for(int nu = 0; nu < n; nu++)\n", "{\n", " JBessel[nu]= new TF1(\"J_0\", \"ROOT::Math::cyl_bessel_j([0],x)\", 0, 10);\n", " JBessel[nu]->SetParameters(nu, 0.0);\n", " JBessel[nu]->SetTitle(\"\"); //Bessel J functions\");\n", " JBessel[nu]->SetLineStyle(kSolid);\n", " JBessel[nu]->SetLineWidth(3);\n", " JBessel[nu]->SetLineColor(nu+1);\n", "}\n", "JBessel[0]->TF1::GetXaxis()->SetTitle(\"x\");\n", "JBessel[0]->GetXaxis()->SetTitleSize(0.06);\n", "JBessel[0]->GetXaxis()->SetTitleOffset(.7);\n", "\n", "//setting the title in a label style\n", "TPaveLabel *p1 = new TPaveLabel(.0,.90 , (.0+.50),(.90+.10) , \"Bessel J functions\", \"NDC\");\n", "p1->SetFillColor(0);\n", "p1->SetTextFont(22);\n", "p1->SetTextColor(kBlack);\n", "\n", "//setting the legend\n", "leg->AddEntry(JBessel[0]->DrawCopy(), \" J_0(x)\", \"l\");\n", "leg->AddEntry(JBessel[1]->DrawCopy(\"same\"), \" J_1(x)\", \"l\");\n", "leg->AddEntry(JBessel[2]->DrawCopy(\"same\"), \" J_2(x)\", \"l\");\n", "leg->AddEntry(JBessel[3]->DrawCopy(\"same\"), \" J_3(x)\", \"l\");\n", "leg->AddEntry(JBessel[4]->DrawCopy(\"same\"), \" J_4(x)\", \"l\");\n", "\n", "leg->Draw();\n", "p1->Draw();\n", "\n", "//------------------------------------------------\n", "DistCanvas->cd(2);\n", "gPad->SetGrid();\n", "gPad->SetFrameFillColor(19);\n", "\n", "TLegend *leg2 = new TLegend(0.75, 0.7, 0.89, 0.89);\n", "//------------------------------------------------\n", "//Drawing Bessel k\n", "TF1* KBessel[5];\n", "for(int nu = 0; nu < n; nu++){\n", " KBessel[nu]= new TF1(\"J_0\", \"ROOT::Math::cyl_bessel_k([0],x)\", 0, 10);\n", " KBessel[nu]->SetParameters(nu, 0.0);\n", " KBessel[nu]->SetTitle(\"Bessel K functions\");\n", " KBessel[nu]->SetLineStyle(kSolid);\n", " KBessel[nu]->SetLineWidth(3);\n", " KBessel[nu]->SetLineColor(nu+1);\n", "}\n", "KBessel[0]->GetXaxis()->SetTitle(\"x\");\n", "KBessel[0]->GetXaxis()->SetTitleSize(0.06);\n", "KBessel[0]->GetXaxis()->SetTitleOffset(.7);\n", "\n", "//setting title\n", "TPaveLabel *p2 = new TPaveLabel(.0,.90 , (.0+.50),(.90+.10) , \"Bessel K functions\", \"NDC\");\n", "p2->SetFillColor(0);\n", "p2->SetTextFont(22);\n", "p2->SetTextColor(kBlack);\n", "\n", "//setting legend\n", "leg2->AddEntry(KBessel[0]->DrawCopy(), \" K_0(x)\", \"l\");\n", "leg2->AddEntry(KBessel[1]->DrawCopy(\"same\"), \" K_1(x)\", \"l\");\n", "leg2->AddEntry(KBessel[2]->DrawCopy(\"same\"), \" K_2(x)\", \"l\");\n", "leg2->AddEntry(KBessel[3]->DrawCopy(\"same\"), \" K_3(x)\", \"l\");\n", "leg2->AddEntry(KBessel[4]->DrawCopy(\"same\"), \" K_4(x)\", \"l\");\n", "leg2->Draw();\n", "p2->Draw();\n", "//------------------------------------------------\n", "DistCanvas->cd(3);\n", "gPad->SetGrid();\n", "gPad->SetFrameFillColor(19);\n", "TLegend *leg3 = new TLegend(0.75, 0.7, 0.89, 0.89);\n", "//------------------------------------------------\n", "//Drawing Bessel i\n", "TF1* iBessel[5];\n", "for(int nu = 0; nu <= 4; nu++){\n", " iBessel[nu]= new TF1(\"J_0\", \"ROOT::Math::cyl_bessel_i([0],x)\", 0, 10);\n", " iBessel[nu]->SetParameters(nu, 0.0);\n", " iBessel[nu]->SetTitle(\"Bessel I functions\");\n", " iBessel[nu]->SetLineStyle(kSolid);\n", " iBessel[nu]->SetLineWidth(3);\n", " iBessel[nu]->SetLineColor(nu+1);\n", "}\n", "\n", "iBessel[0]->GetXaxis()->SetTitle(\"x\");\n", "iBessel[0]->GetXaxis()->SetTitleSize(0.06);\n", "iBessel[0]->GetXaxis()->SetTitleOffset(.7);\n", "\n", "//setting title\n", "TPaveLabel *p3 = new TPaveLabel(.0,.90 , (.0+.50),(.90+.10) ,\"Bessel I functions\", \"NDC\");\n", "p3->SetFillColor(0);\n", "p3->SetTextFont(22);\n", "p3->SetTextColor(kBlack);\n", "\n", "//setting legend\n", "leg3->AddEntry(iBessel[0]->DrawCopy(), \" I_0\", \"l\");\n", "leg3->AddEntry(iBessel[1]->DrawCopy(\"same\"), \" I_1(x)\", \"l\");\n", "leg3->AddEntry(iBessel[2]->DrawCopy(\"same\"), \" I_2(x)\", \"l\");\n", "leg3->AddEntry(iBessel[3]->DrawCopy(\"same\"), \" I_3(x)\", \"l\");\n", "leg3->AddEntry(iBessel[4]->DrawCopy(\"same\"), \" I_4(x)\", \"l\");\n", "leg3->Draw();\n", "p3->Draw();\n", "//------------------------------------------------\n", "DistCanvas->cd(4);\n", "gPad->SetGrid();\n", "gPad->SetFrameFillColor(19);\n", "TLegend *leg4 = new TLegend(0.75, 0.7, 0.89, 0.89);\n", "//------------------------------------------------\n", "//Drawing sph_bessel\n", "TF1* jBessel[5];\n", "for(int nu = 0; nu <= 4; nu++){\n", " jBessel[nu]= new TF1(\"J_0\", \"ROOT::Math::sph_bessel([0],x)\", 0, 10);\n", " jBessel[nu]->SetParameters(nu, 0.0);\n", " jBessel[nu]->SetTitle(\"Bessel j functions\");\n", " jBessel[nu]->SetLineStyle(kSolid);\n", " jBessel[nu]->SetLineWidth(3);\n", " jBessel[nu]->SetLineColor(nu+1);\n", "}\n", "jBessel[0]->GetXaxis()->SetTitle(\"x\");\n", "jBessel[0]->GetXaxis()->SetTitleSize(0.06);\n", "jBessel[0]->GetXaxis()->SetTitleOffset(.7);\n", "\n", "//setting title\n", "TPaveLabel *p4 = new TPaveLabel(.0,.90 , (.0+.50),(.90+.10) ,\"Bessel j functions\", \"NDC\");\n", "p4->SetFillColor(0);\n", "p4->SetTextFont(22);\n", "p4->SetTextColor(kBlack);\n", "\n", "//setting legend\n", "\n", "leg4->AddEntry(jBessel[0]->DrawCopy(), \" j_0(x)\", \"l\");\n", "leg4->AddEntry(jBessel[1]->DrawCopy(\"same\"), \" j_1(x)\", \"l\");\n", "leg4->AddEntry(jBessel[2]->DrawCopy(\"same\"), \" j_2(x)\", \"l\");\n", "leg4->AddEntry(jBessel[3]->DrawCopy(\"same\"), \" j_3(x)\", \"l\");\n", "leg4->AddEntry(jBessel[4]->DrawCopy(\"same\"), \" j_4(x)\", \"l\");\n", "\n", "leg4->Draw();\n", "p4->Draw();\n", "\n", "DistCanvas->cd();" ] }, { "cell_type": "markdown", "id": "fecb1666", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 3, "id": "35835a9d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:50.059437Z", "iopub.status.busy": "2026-05-19T20:26:50.059308Z", "iopub.status.idle": "2026-05-19T20:26:50.375747Z", "shell.execute_reply": "2026-05-19T20:26:50.374749Z" } }, "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 }