问题描述
我刚刚开始使用pyroot读取根文件,而无法使用jupyter notebook从文件中读取数据. TBrowser的外观如下:
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:
我是这样开始的:
import ROOT as root
import numpy as np
f = root.TFile("RealData.root")
myTree = f.Get("tree")
entries = myTree.GetEntriesFast()
到目前为止,它正在运行,如果我打印条目,我将得到文件中所包含的正确总数.但是我不知道如何从树中读取实际数据(event_number,n_channels等).如果我尝试使用类似myTree.events
或myTree.event_number
的方法,内核将停止工作.我应该怎么做才能从树中读取数据?
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?
推荐答案
通常使用pyROOT,您可以执行以下操作:
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
我对jupyter的工作方式了解不足,无法确定这是否会引起任何特定的问题.您是否尝试过使用常规的python解释器运行相同的脚本?
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?
这篇关于使用PyRoot以root身份读取TTree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!