{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "623e3506",
   "metadata": {},
   "source": [
    "# hist001_TH1_fillrandom_uhi\n",
    "Fill a 1D histogram with random values using predefined functions.\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "**Author:** Giacomo Parolini, Nursena Bitirgen  \n",
    "<i><small>This notebook tutorial was automatically generated with <a href= \"https://github.com/root-project/root/blob/master/documentation/doxygen/converttonotebook.py\">ROOTBOOK-izer</a> from the macro found in the ROOT repository  on Tuesday, May 19, 2026 at 08:11 PM.</small></i>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9036e767",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:11:37.648630Z",
     "iopub.status.busy": "2026-05-19T20:11:37.648478Z",
     "iopub.status.idle": "2026-05-19T20:11:38.723482Z",
     "shell.execute_reply": "2026-05-19T20:11:38.722686Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import ROOT\n",
    "\n",
    "np.random.seed(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "333f45b5",
   "metadata": {},
   "source": [
    "Create a one dimensional histogram and fill it with a gaussian distribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1a6b7a0a",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:11:38.731592Z",
     "iopub.status.busy": "2026-05-19T20:11:38.731384Z",
     "iopub.status.idle": "2026-05-19T20:11:38.869467Z",
     "shell.execute_reply": "2026-05-19T20:11:38.868767Z"
    }
   },
   "outputs": [],
   "source": [
    "h1d = ROOT.TH1D(\"h1d\", \"Test random numbers\", nbinsx=200, xlow=0.0, xup=10.0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2186c3e5",
   "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": 3,
   "id": "b6455cd3",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:11:38.871730Z",
     "iopub.status.busy": "2026-05-19T20:11:38.871582Z",
     "iopub.status.idle": "2026-05-19T20:11:38.979766Z",
     "shell.execute_reply": "2026-05-19T20:11:38.979300Z"
    }
   },
   "outputs": [],
   "source": [
    "values = np.random.normal(0.0, 1.0, 10000)\n",
    "h1d.Fill(values)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "edd05f41",
   "metadata": {},
   "source": [
    "Open a ROOT file and save the histogram"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5fcd58b5",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:11:38.997394Z",
     "iopub.status.busy": "2026-05-19T20:11:38.997249Z",
     "iopub.status.idle": "2026-05-19T20:11:39.166076Z",
     "shell.execute_reply": "2026-05-19T20:11:39.165641Z"
    }
   },
   "outputs": [],
   "source": [
    "with ROOT.TFile.Open(\"fillrandom_py_uhi.root\", \"RECREATE\") as myfile:\n",
    "    myfile.WriteObject(h1d, h1d.GetName())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8bfa7e8f",
   "metadata": {},
   "source": [
    "Draw all canvases "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "63e40d89",
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2026-05-19T20:11:39.174398Z",
     "iopub.status.busy": "2026-05-19T20:11:39.174260Z",
     "iopub.status.idle": "2026-05-19T20:11:39.281890Z",
     "shell.execute_reply": "2026-05-19T20:11:39.281334Z"
    }
   },
   "outputs": [],
   "source": [
    "from ROOT import gROOT \n",
    "gROOT.GetListOfCanvases().Draw()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
