ROOT
v6-36
Reference Guide
Loading...
Searching...
No Matches
hist000_TH1_first.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_hist
3
## Hello World example for TH1
4
##
5
## Shows how to create, fill and write a histogram to a ROOT file.
6
##
7
## \macro_code
8
##
9
## \date November 2024
10
## \author Giacomo Parolini (CERN)
11
12
import
ROOT
13
14
# Open the file to write the histogram to
15
with
ROOT.TFile.Open
(
"outfile.root"
,
"RECREATE"
)
as
outFile:
16
# Create the histogram object
17
# There are several constructors you can use (see TH1). In this example we use the
18
# simplest one, accepting a number of bins and a range.
19
histogram =
ROOT.TH1D
(
"histogram"
,
"My first ROOT histogram"
, nbinsx = 30, xlow = 0.0, xup = 10.0)
20
21
# Fill the histogram. In this simple example we use a fake set of data.
22
# The 'D' in TH1D stands for 'double', so we fill the histogram with doubles.
23
# In general you should prefer TH1D over TH1F unless you have a very specific reason
24
# to do otherwise.
25
values = [1, 2, 3, 3, 3, 4, 3, 2, 1, 0]
26
for
val
in
values:
27
histogram.Fill
(val)
28
29
# Write the histogram to `outFile`.
30
outFile.WriteObject
(histogram,
histogram.GetName
())
31
32
# When `with` block exits, `outFile` will close itself and write its contents to disk.
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
tutorials
hist
hist000_TH1_first.py
ROOT v6-36 - Reference Guide Generated on Thu Aug 21 2025 04:30:47 (GVA Time) using Doxygen 1.10.0