{ "cells": [ { "cell_type": "markdown", "id": "7a6b7679", "metadata": {}, "source": [ "# GammaFun\n", "Example showing the usage of the major special math functions (gamma, beta, erf) in ROOT.\n", "\n", "To execute the macro type in:\n", "\n", "```cpp\n", "root[0]: .x GammaFun.C\n", "```\n", "\n", "It will create one canvas with the representation\n", "of the tgamma, lgamma, beta, erf and erfc functions.\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:25 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "5129d524", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:28.595177Z", "iopub.status.busy": "2026-05-19T20:25:28.595043Z", "iopub.status.idle": "2026-05-19T20:25:29.043259Z", "shell.execute_reply": "2026-05-19T20:25:29.042576Z" } }, "outputs": [], "source": [ "gStyle->SetOptStat(0);\n", "\n", "TF1 *f1a = new TF1(\"Gamma(x)\",\"ROOT::Math::tgamma(x)\",-2,5);\n", "TF1 *f2a = new TF1(\"f2a\",\"ROOT::Math::lgamma(x)\",0,10);\n", "TF2 *f3a = new TF2(\"Beta(x)\",\"ROOT::Math::beta(x, y)\",0,0.1, 0, 0.1);\n", "TF1 *f4a = new TF1(\"erf(x)\",\"ROOT::Math::erf(x)\",0,5);\n", "TF1 *f4b = new TF1(\"erfc(x)\",\"ROOT::Math::erfc(x)\",0,5);\n", "\n", "TCanvas *c1 = new TCanvas(\"c1\", \"Gamma and related functions\",800,700);\n", "\n", "c1->Divide(2,2);\n", "\n", "c1->cd(1);\n", "gPad->SetGrid();" ] }, { "cell_type": "markdown", "id": "520687bb", "metadata": {}, "source": [ "setting the title in a label style" ] }, { "cell_type": "code", "execution_count": 2, "id": "bd4d83db", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:29.056566Z", "iopub.status.busy": "2026-05-19T20:25:29.056427Z", "iopub.status.idle": "2026-05-19T20:25:29.263404Z", "shell.execute_reply": "2026-05-19T20:25:29.262973Z" } }, "outputs": [], "source": [ "TPaveLabel *p1 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,\"ROOT::Math::tgamma(x)\", \"NDC\");\n", "p1->SetFillColor(0);\n", "p1->SetTextFont(22);\n", "p1->SetTextColor(kBlack);" ] }, { "cell_type": "markdown", "id": "6bcc3425", "metadata": {}, "source": [ "setting graph\n", "draw axis first (use TH1 to draw the frame)" ] }, { "cell_type": "code", "execution_count": 3, "id": "1526f7ce", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:29.270244Z", "iopub.status.busy": "2026-05-19T20:25:29.270053Z", "iopub.status.idle": "2026-05-19T20:25:29.476690Z", "shell.execute_reply": "2026-05-19T20:25:29.476217Z" } }, "outputs": [], "source": [ "TH1F * h = new TH1F(\"hTemp\",\"\",500,-2,5);\n", "h->SetMinimum(-20);\n", "h->SetMaximum(20);\n", "h->GetXaxis()->SetTitleSize(0.06);\n", "h->GetXaxis()->SetTitleOffset(.7);\n", "h->GetXaxis()->SetTitle(\"x\");\n", "\n", "h->Draw();" ] }, { "cell_type": "markdown", "id": "2be05c26", "metadata": {}, "source": [ "draw the functions 3 times in the separate ranges to avoid singularities" ] }, { "cell_type": "code", "execution_count": 4, "id": "41e5d434", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:29.499392Z", "iopub.status.busy": "2026-05-19T20:25:29.499251Z", "iopub.status.idle": "2026-05-19T20:25:29.706092Z", "shell.execute_reply": "2026-05-19T20:25:29.705442Z" } }, "outputs": [], "source": [ "f1a->SetLineWidth(2);\n", "f1a->SetLineColor(kBlue);\n", "\n", "f1a->SetRange(-2,-1);\n", "f1a->DrawCopy(\"same\");\n", "\n", "f1a->SetRange(-1,0);\n", "f1a->DrawCopy(\"same\");\n", "\n", "f1a->SetRange(0,5);\n", "f1a->DrawCopy(\"same\");\n", "\n", "p1->Draw();\n", "\n", "c1->cd(2);\n", "gPad->SetGrid();\n", "TPaveLabel *p2 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,\"ROOT::Math::lgamma(x)\", \"NDC\");\n", "p2->SetFillColor(0);\n", "p2->SetTextFont(22);\n", "p2->SetTextColor(kBlack);\n", "f2a->SetLineColor(kBlue);\n", "f2a->SetLineWidth(2);\n", "f2a->GetXaxis()->SetTitle(\"x\");\n", "f2a->GetXaxis()->SetTitleSize(0.06);\n", "f2a->GetXaxis()->SetTitleOffset(.7);\n", "f2a->SetTitle(\"\");\n", "f2a->Draw();\n", "p2->Draw();\n", "\n", "c1->cd(3);\n", "gPad->SetGrid();\n", "\n", "TPaveLabel *p3 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,\"ROOT::Math::beta(x, y)\", \"NDC\");\n", "p3->SetFillColor(0);\n", "p3->SetTextFont(22);\n", "p3->SetTextColor(kBlack);\n", "f3a->SetLineWidth(2);\n", "f3a->GetXaxis()->SetTitle(\"x\");\n", "f3a->GetXaxis()->SetTitleOffset(1.2);\n", "f3a->GetXaxis()->SetTitleSize(0.06);\n", "f3a->GetYaxis()->SetTitle(\"y\");\n", "f3a->GetYaxis()->SetTitleSize(0.06);\n", "f3a->GetYaxis()->SetTitleOffset(1.5);\n", "f3a->SetTitle(\"\");\n", "f3a->Draw(\"surf1\");//option for a 3-dim plot\n", "p3->Draw();\n", "\n", "c1->cd(4);\n", "gPad->SetGrid();\n", "TPaveLabel *p4 = new TPaveLabel(.1,.90 , (.1+.50),(.90+.10) ,\"erf(x) and erfc(x)\", \"NDC\");\n", "p4->SetFillColor(0);\n", "p4->SetTextFont(22);\n", "p4->SetTextColor(kBlack);\n", "f4a->SetTitle(\"erf(x) and erfc(x)\");\n", "f4a->SetLineWidth(2);\n", "f4b->SetLineWidth(2);\n", "f4a->SetLineColor(kBlue);\n", "f4b->SetLineColor(kRed);\n", "f4a->GetXaxis()->SetTitleSize(.06);\n", "f4a->GetXaxis()->SetTitleOffset(.7);\n", "f4a->GetXaxis()->SetTitle(\"x\");\n", "f4a->Draw();\n", "f4b->Draw(\"same\");//option for a multiple graph plot\n", "f4a->SetTitle(\"\");\n", "p4->Draw();" ] }, { "cell_type": "markdown", "id": "aea6aa90", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "ec146410", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:25:29.707940Z", "iopub.status.busy": "2026-05-19T20:25:29.707823Z", "iopub.status.idle": "2026-05-19T20:25:30.023264Z", "shell.execute_reply": "2026-05-19T20:25:30.022751Z" } }, "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 }