Reading a TTree in root using PyRoot

扶醉桌前 提交于 2019-12-11 06:59:51

问题


I just started using pyroot to read root files and I can't read the data from a file using jupyter notebook. Here is how the TBrowser looks like:

I started like this:

import ROOT as root
import numpy as np

f = root.TFile("RealData.root")
myTree = f.Get("tree")

entries = myTree.GetEntriesFast()

Up to here it is working and if I print entries I get the right number of entires I have in the file. But i don't know how to read actual data from the tree (event_number, n_channels, etc.) If I try something like myTree.events or myTree.event_number the kernel stops working. What should I do to read the data from the tree?


回答1:


Normally with pyROOT, you can just do something like:

import ROOT as root
import numpy as np

f = root.TFile("RealData.root")
myTree = f.Get("tree")
for entry in myTree:         
     # Now you have acess to the leaves/branches of each entry in the tree, e.g.
     events = entry.events

I don't know enough about how jupyter works to know if that would cause any particular problems. Have you tried running the same script just using a regular python interpreter?



来源:https://stackoverflow.com/questions/38819098/reading-a-ttree-in-root-using-pyroot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!