Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist001_TH1_fillrandom_uhi.py File Reference

Detailed Description

View in nbviewer Open in SWAN
Fill a 1D histogram with random values using predefined functions.

B␘

import numpy as np
import ROOT
# Create a one dimensional histogram and fill it with a gaussian distribution
h1d = ROOT.TH1D("h1d", "Test random numbers", nbinsx=200, xlow=0.0, xup=10.0)
# "gaus" is a predefined ROOT function. Here we are filling the histogram with
# 10000 values sampled from that distribution.
values = np.random.normal(0.0, 1.0, 10000)
h1d.Fill(values)
# Open a ROOT file and save the histogram
with ROOT.TFile.Open("fillrandom_py_uhi.root", "RECREATE") as myfile:
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Date
July 2025
Author
Giacomo Parolini, Nursena Bitirgen

Definition in file hist001_TH1_fillrandom_uhi.py.