{ "cells": [ { "cell_type": "markdown", "id": "2fcef631", "metadata": {}, "source": [ "# pdf012_tStudent\n", "Example macro describing the student t distribution\n", "\n", "```cpp\n", "root[0]: .x tStudent.C\n", "```\n", "\n", "It draws the pdf, the cdf and then 10 quantiles of the t Student distribution\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": "c86c1369", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:57.575352Z", "iopub.status.busy": "2026-05-19T20:26:57.575196Z", "iopub.status.idle": "2026-05-19T20:26:57.891995Z", "shell.execute_reply": "2026-05-19T20:26:57.891289Z" } }, "outputs": [], "source": [ "/* gSystem->Load(\"libMathMore\");*/" ] }, { "cell_type": "markdown", "id": "e713b725", "metadata": {}, "source": [ "this is the way to force load of MathMore in Cling" ] }, { "cell_type": "code", "execution_count": 2, "id": "572868fb", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:57.894059Z", "iopub.status.busy": "2026-05-19T20:26:57.893935Z", "iopub.status.idle": "2026-05-19T20:26:58.101302Z", "shell.execute_reply": "2026-05-19T20:26:58.100622Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Info in : libMathMore has been loaded.\n" ] } ], "source": [ "ROOT::Math::MathMoreLibrary::Load();\n", "\n", "int n=100;\n", "double a=-5.;\n", "double b=5.;" ] }, { "cell_type": "markdown", "id": "13fcd561", "metadata": {}, "source": [ "double r = 3;" ] }, { "cell_type": "code", "execution_count": 3, "id": "1cc0ba34", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:58.103185Z", "iopub.status.busy": "2026-05-19T20:26:58.103062Z", "iopub.status.idle": "2026-05-19T20:26:58.310114Z", "shell.execute_reply": "2026-05-19T20:26:58.309390Z" } }, "outputs": [], "source": [ "TF1* pdf = new TF1(\"pdf\", \"ROOT::Math::tdistribution_pdf(x,3.0)\", a,b);\n", "TF1* cum = new TF1(\"cum\", \"ROOT::Math::tdistribution_cdf(x,3.0)\", a,b);\n", "\n", "TH1D* quant = new TH1D(\"quant\", \"\", 9, 0, 0.9);\n", "\n", "for(int i=1; i < 10; i++)\n", " quant->Fill((i-0.5)/10.0, ROOT::Math::tdistribution_quantile((1.0*i)/10, 3.0 ) );\n", "\n", "double xx[10];\n", "xx[0] = -1.5;\n", "for(int i=1; i<9; i++)\n", " xx[i]= quant->GetBinContent(i);\n", "xx[9] = 1.5;\n", "TH1D* pdfq[10];" ] }, { "cell_type": "markdown", "id": "eb8d49a8", "metadata": {}, "source": [ "int nbin = n/10.0;" ] }, { "cell_type": "code", "execution_count": 4, "id": "299ca485", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:58.312196Z", "iopub.status.busy": "2026-05-19T20:26:58.312073Z", "iopub.status.idle": "2026-05-19T20:26:58.519255Z", "shell.execute_reply": "2026-05-19T20:26:58.518676Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning in : nbins is <=0 - set to nbins = 1\n" ] } ], "source": [ "for(int i=0; i < 9; i++) {\n", " int nbin = n * (xx[i+1]-xx[i])/3.0 + 1.0;\n", " TString name = \"pdf\";\n", " name += i;\n", " pdfq[i]= new TH1D(name, \"\", nbin,xx[i],xx[i+1] );\n", " for(int j=1; jSetBinContent(j, ROOT::Math::tdistribution_pdf(x,3));\n", " }\n", "}\n", "\n", "TCanvas *Canvas = new TCanvas(\"DistCanvas\", \"Student Distribution graphs\", 10, 10, 800, 700);\n", "pdf->SetTitle(\"Student t distribution function\");\n", "cum->SetTitle(\"Cumulative for Student t\");\n", "quant->SetTitle(\"10-quantiles for Student t\");\n", "Canvas->Divide(2, 2);\n", "Canvas->cd(1);\n", "pdf->SetLineWidth(2);\n", "pdf->DrawCopy();\n", "Canvas->cd(2);\n", "cum->SetLineWidth(2);\n", "cum->SetLineColor(kRed);\n", "cum->Draw();\n", "Canvas->cd(3);\n", "quant->Draw();\n", "quant->SetLineWidth(2);\n", "quant->SetLineColor(kBlue);\n", "quant->SetStats(false);\n", "Canvas->cd(4);\n", "pdfq[0]->SetTitle(\"Student t & its quantiles\");\n", "pdf->SetTitle(\"\");\n", "pdf->Draw();" ] }, { "cell_type": "markdown", "id": "8f9d7bf0", "metadata": {}, "source": [ "pdfq[0]->SetAxisRange(-1.5, 0, 1.5,1.0);" ] }, { "cell_type": "code", "execution_count": 5, "id": "c29278ea", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:58.520883Z", "iopub.status.busy": "2026-05-19T20:26:58.520759Z", "iopub.status.idle": "2026-05-19T20:26:58.727687Z", "shell.execute_reply": "2026-05-19T20:26:58.726927Z" } }, "outputs": [], "source": [ "pdfq[0]->SetTitle(\"Student t & its quantiles\");\n", "for(int i=0; i < 9; i++) {\n", " pdfq[i]->SetStats(false);\n", " pdfq[i]->SetFillColor(i+1);\n", " pdfq[i]->Draw(\"same\");\n", "}\n", "Canvas->Modified();\n", "Canvas->cd();" ] }, { "cell_type": "markdown", "id": "d0a85b1c", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 6, "id": "9251d4c4", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:58.729173Z", "iopub.status.busy": "2026-05-19T20:26:58.729043Z", "iopub.status.idle": "2026-05-19T20:26:59.043493Z", "shell.execute_reply": "2026-05-19T20:26:59.042886Z" } }, "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 }