#! /usr/bin/env python """ ntpSaved.py: Example PyROOT program which stores data to a ROOT TNtuple then saves this data as a ROOT objects in a ROOT TFile. Paul Eugenio PHZ4151C Florida State University April 1, 2019 """ from __future__ import division, print_function import numpy as np import ROOT def func( aX ): """ ... """ return np.exp( -aX ) * np.sin( 3.0 * aX )**2 # Open a ROOT TFile rootFile = ROOT.TFile("ntpData.root","RECREATE") # Create an instance of a TNtuple object ntuple = ROOT.TNtuple("ntp1", "My First Ntuple", "x:y" ) # define plotting limits and step size xMin = 0.0 xMax = 5.0 deltaX = 0.01 for x in np.arange( xMin, xMax, deltaX ): # Fill the TNtuple with values for x & y ntuple.Fill( x, func(x) ) # Save the ROOT TFile containing ROOT objects rootFile.Write()