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.

Author: Wim Lavrijsen
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Thursday, January 21, 2021 at 10:23 AM.

In [1]:
import sys, os
from ROOT import TFile, TNtuple, TROOT

ifn = os.path.join(str(TROOT.GetTutorialDir()), 'pyroot', 'aptuple.txt')
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 )


Welcome to JupyROOT 6.23/01
opening file /home/sftnight/build/workspace/root-makedoc-master/rootspi/rdoc/src/ ...
writing file aptuple.root ...