ROOT
git-r3/HEAD
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_image
7
## \macro_code
8
##
9
## \date July 2025
10
## \author Giacomo Parolini, Nursena Bitirgen
11
12
import
numpy
as
np
13
import
ROOT
14
15
np.random.seed(0)
16
17
# Create a one dimensional histogram and fill it with a gaussian distribution
18
h1d = ROOT.TH1D(
"h1d"
,
"Test random numbers"
, nbinsx=200, xlow=0.0, xup=10.0)
19
20
# "gaus" is a predefined ROOT function. Here we are filling the histogram with
21
# 10000 values sampled from that distribution.
22
values = np.random.normal(0.0, 1.0, 10000)
23
h1d.Fill(values)
24
25
# Open a ROOT file and save the histogram
26
with
ROOT.TFile.Open(
"fillrandom_py_uhi.root"
,
"RECREATE"
)
as
myfile:
27
myfile.WriteObject(h1d, h1d.GetName())
tutorials
hist
hist001_TH1_fillrandom_uhi.py
ROOTgit-r3/HEAD - Reference Guide Generated on
(GVA Time) using Doxygen 1.16.1