{ "cells": [ { "cell_type": "markdown", "id": "969b5240", "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 Tuesday, May 19, 2026 at 08:27 PM." ] }, { "cell_type": "markdown", "id": "2c8f8913", "metadata": {}, "source": [ "Fill a 1-D histogram from a parametric function" ] }, { "cell_type": "code", "execution_count": 1, "id": "dafa0e15", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:14.807555Z", "iopub.status.busy": "2026-05-19T20:27:14.807444Z", "iopub.status.idle": "2026-05-19T20:27:15.157334Z", "shell.execute_reply": "2026-05-19T20:27:15.156750Z" } }, "outputs": [], "source": [ "TCanvas *c1 = new TCanvas(\"c1\",\"The FillRandom example\",0,0,700,500);\n", "\n", "gBenchmark->Start(\"fillrandom\");" ] }, { "cell_type": "markdown", "id": "1f3b578e", "metadata": {}, "source": [ "A function (any dimension) or a formula may reference\n", "an already defined formula" ] }, { "cell_type": "code", "execution_count": 2, "id": "53d8ee78", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:15.159325Z", "iopub.status.busy": "2026-05-19T20:27:15.159202Z", "iopub.status.idle": "2026-05-19T20:27:15.366206Z", "shell.execute_reply": "2026-05-19T20:27:15.365666Z" } }, "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": "baec7f4d", "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": "68466a00", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:15.368080Z", "iopub.status.busy": "2026-05-19T20:27:15.367965Z", "iopub.status.idle": "2026-05-19T20:27:15.574810Z", "shell.execute_reply": "2026-05-19T20:27:15.574275Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\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": "d1a49287", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 4, "id": "979d1449", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:15.576294Z", "iopub.status.busy": "2026-05-19T20:27:15.576177Z", "iopub.status.idle": "2026-05-19T20:27:15.787792Z", "shell.execute_reply": "2026-05-19T20:27:15.787221Z" } }, "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 }