{ "cells": [ { "cell_type": "markdown", "id": "21874269", "metadata": {}, "source": [ "# qa2\n", "Test generation of random numbers distributed according to a function defined by the user.\n", "\n", "\n", "\n", "\n", "**Author:** Rene Brun \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Sunday, December 21, 2025 at 02:49 PM." ] }, { "cell_type": "markdown", "id": "adb28949", "metadata": {}, "source": [ "Fill a 1-D histogram from a parametric function" ] }, { "cell_type": "code", "execution_count": 1, "id": "a0aac945", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-21T13:49:27.445485Z", "iopub.status.busy": "2025-12-21T13:49:27.445361Z", "iopub.status.idle": "2025-12-21T13:49:27.858436Z", "shell.execute_reply": "2025-12-21T13:49:27.842504Z" } }, "outputs": [], "source": [ "TCanvas *c1 = new TCanvas(\"c1\",\"The FillRandom example\",0,0,700,500);\n", "\n", "gBenchmark->Start(\"fillrandom\");" ] }, { "cell_type": "markdown", "id": "7bec3935", "metadata": {}, "source": [ "A function (any dimension) or a formula may reference\n", "an already defined formula" ] }, { "cell_type": "code", "execution_count": 2, "id": "d0dc0c18", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-21T13:49:27.879842Z", "iopub.status.busy": "2025-12-21T13:49:27.879635Z", "iopub.status.idle": "2025-12-21T13:49:28.092958Z", "shell.execute_reply": "2025-12-21T13:49:28.092399Z" } }, "outputs": [], "source": [ "TFormula *form1 = new TFormula(\"form1\",\"abs(sin(x)/x)\");\n", "TF1 *sqroot = new TF1(\"sqroot\",\"x*gaus(0) + [3]*form1\",0,10);\n", "sqroot->SetParameters(10,4,1,20);" ] }, { "cell_type": "markdown", "id": "7a820221", "metadata": {}, "source": [ "Create a one dimensional histogram (one float per bin)\n", "and fill it following the distribution in function sqroot." ] }, { "cell_type": "code", "execution_count": 3, "id": "206ea1b4", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-21T13:49:28.097773Z", "iopub.status.busy": "2025-12-21T13:49:28.097633Z", "iopub.status.idle": "2025-12-21T13:49:28.305133Z", "shell.execute_reply": "2025-12-21T13:49:28.304594Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "TH1F *h1f = new TH1F(\"h1f\",\"Test random numbers\",200,0,10);\n", "h1f->SetFillColor(45);\n", "h1f->FillRandom(\"sqroot\",100000);\n", "h1f->Draw();\n", "TPaveLabel *lfunction = new TPaveLabel(5,39,9.8,46,\"The sqroot function\");\n", "lfunction->SetFillColor(41);\n", "\n", "c1->SetGridx();\n", "c1->SetGridy();\n", "\n", "h1f->SetDirectory(nullptr);\n", "\n", "c1->Update();\n", "\n", "sqroot->SetParameters(200,4,1,20);" ] }, { "cell_type": "markdown", "id": "88a47c84", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 4, "id": "19d42b3f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2025-12-21T13:49:28.306886Z", "iopub.status.busy": "2025-12-21T13:49:28.306752Z", "iopub.status.idle": "2025-12-21T13:49:28.523649Z", "shell.execute_reply": "2025-12-21T13:49:28.523236Z" } }, "outputs": [ { "data": { "text/html": [ "\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 }