{ "cells": [ { "cell_type": "markdown", "id": "8dfcddbf", "metadata": {}, "source": [ "# hist001_TH1_fillrandom\n", "Fill a 1D histogram with random values using predefined functions.\n", "\n", "\n", "\n", "\n", "**Author:** Giacomo Parolini \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:06 PM." ] }, { "cell_type": "markdown", "id": "fcf90937", "metadata": {}, "source": [ "Create a one dimensional histogram and fill it with a gaussian distribution" ] }, { "cell_type": "code", "execution_count": 1, "id": "81e604df", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:16.329840Z", "iopub.status.busy": "2026-05-19T20:06:16.329701Z", "iopub.status.idle": "2026-05-19T20:06:16.682692Z", "shell.execute_reply": "2026-05-19T20:06:16.674112Z" } }, "outputs": [], "source": [ "int nBins = 200;\n", "double rangeMin = 0.0;\n", "double rangeMax = 10.0;\n", "TH1D h1d(\"h1d\", \"Test random numbers\", nBins, rangeMin, rangeMax);" ] }, { "cell_type": "markdown", "id": "808cf00f", "metadata": {}, "source": [ "\"gaus\" is a predefined ROOT function. Here we are filling the histogram with\n", "10000 values sampled from that distribution." ] }, { "cell_type": "code", "execution_count": 2, "id": "cfb35bb5", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:16.709551Z", "iopub.status.busy": "2026-05-19T20:06:16.709398Z", "iopub.status.idle": "2026-05-19T20:06:17.073949Z", "shell.execute_reply": "2026-05-19T20:06:17.062621Z" } }, "outputs": [], "source": [ "h1d.FillRandom(\"gaus\", 10000);" ] }, { "cell_type": "markdown", "id": "5f9c34f2", "metadata": {}, "source": [ "Open a ROOT file and save the histogram" ] }, { "cell_type": "code", "execution_count": 3, "id": "6bfa8c83", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:17.095938Z", "iopub.status.busy": "2026-05-19T20:06:17.095767Z", "iopub.status.idle": "2026-05-19T20:06:17.318886Z", "shell.execute_reply": "2026-05-19T20:06:17.318104Z" } }, "outputs": [], "source": [ "auto myfile = std::unique_ptr(TFile::Open(\"fillrandom.root\", \"RECREATE\"));\n", "myfile->WriteObject(&h1d, h1d.GetName());" ] }, { "cell_type": "markdown", "id": "da9e707d", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 4, "id": "5ff26a99", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:06:17.335437Z", "iopub.status.busy": "2026-05-19T20:06:17.335284Z", "iopub.status.idle": "2026-05-19T20:06:17.559186Z", "shell.execute_reply": "2026-05-19T20:06:17.553564Z" } }, "outputs": [], "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 }