ROOT
master
Reference Guide
Loading...
Searching...
No Matches
hist001_TH1_fillrandom_uhi.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_hist
3
## \notebook
4
## Fill a 1D histogram with random values using predefined functions.
5
##
6
## \macro_code
7
##
8
## \date July 2025
9
## \author Giacomo Parolini, Nursena Bitirgen
10
11
import
numpy
as
np
12
import
ROOT
13
14
np.random.seed
(0)
15
16
# Create a one dimensional histogram and fill it with a gaussian distribution
17
h1d =
ROOT.TH1D
(
"h1d"
,
"Test random numbers"
, nbinsx=200, xlow=0.0, xup=10.0)
18
19
# "gaus" is a predefined ROOT function. Here we are filling the histogram with
20
# 10000 values sampled from that distribution.
21
values =
np.random.normal
(0.0, 1.0, 10000)
22
h1d.Fill
(values)
23
24
# Open a ROOT file and save the histogram
25
with
ROOT.TFile.Open
(
"fillrandom_py_uhi.root"
,
"RECREATE"
)
as
myfile:
26
myfile.WriteObject
(h1d,
h1d.GetName
())
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:360
tutorials
hist
hist001_TH1_fillrandom_uhi.py
ROOTmaster - Reference Guide Generated on Thu Jun 25 2026 04:40:07 (GVA Time) using Doxygen 1.10.0