Build ROOT Ntuple from other source.
This program reads the ‘aptuple.txt’ file row by row, then creates the Ntuple by adding row by row.
opening file /home/sftnight/build/workspace/root-makedoc-v630/rootspi/rdoc/src/v6-30-00-patches.build/tutorials/pyroot/aptuple.txt ...
writing file aptuple.root ...
done
import sys, os
from ROOT import TFile, TNtuple, TROOT
ofn = 'aptuple.root'
print('opening file %s ...' % ifn)
infile = open( ifn, 'r' )
lines = infile.readlines()
title = lines[0]
labels = lines[1].split()
print('writing file %s ...' % ofn)
outfile =
TFile( ofn,
'RECREATE',
'ROOT file with an NTuple' )
ntuple =
TNtuple(
'ntuple', title,
':'.join( labels ) )
for line in lines[2:]:
words = line.split()
row = map( float, words )
ntuple.Fill(*row)
outfile.Write()
print('done')
A ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
A simple TTree restricted to a list of float variables only.
static const TString & GetTutorialDir()
Get the tutorials directory in the installation. Static utility function.
- Author
- Wim Lavrijsen
Definition in file mrt.py.