Created
April 7, 2022 09:47
-
-
Save AlexWilkinsonnn/e277870e2512fea9ea5cdb08c60aa6ff to your computer and use it in GitHub Desktop.
Make a simple TTree using PyROOT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import ROOT | |
from array import array | |
import random | |
ROOT.PyConfig.IgnoreCommandLineOptions = True | |
ROOT.gROOT.SetBatch(1) | |
f = ROOT.TFile("my_tree.root", "RECREATE") | |
tree = ROOT.TTree("valid", "An Example Tree") | |
pt = array('f', [0.]) | |
ptRef = array('f', [0.]) | |
rsp = array('f', [0.]) | |
tree.Branch("pt", pt, 'pt/F') | |
tree.Branch("ptRef", ptRef,'ptRef/F') | |
tree.Branch("rsp", rsp, 'rsp/F') | |
for i in range(1000000): | |
pt[0] = (i+1) * 1.0 | |
ptRef[0] = (i+1) * 1.0 | |
rsp[0] = 1. * pt[0] / ptRef[0] | |
tree.Fill() | |
tree.Write("", ROOT.TObject.kOverwrite); | |
f.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment