2016-07-07 86 views
1

我不確定這個問題實際上是關於指針,因爲我不是很確定它們是什麼,但我必須使用python讀取一些.root文件。以下是該文件的截圖。從根python讀取指針

enter image description here

我設法讀取數字,但我無法讀取向量(或指針 - 我不知道它們是什麼)。我是新來的根。這是代碼的讀取部分,其中t1是文件內的TTree。

a.append(root.TChain("t1")) 

for chain in a: 
    chain.Add(input) 
entries = a[0].GetEntries() 

這是一些數字變量(不是那些在圖片)的讀數:

import pandas as pd 
entries = chain[0].GetEntries() 

xp_pri = [] 
yp_pri = [] 
X_shower = [] 
Y_shower = [] 

for k in range(entries): 
    for a in chain: 
     a.LoadTree(k) 
     a.GetEntry(k) 

     xp_pri = xp_pri + [chain[0].xp_pri] 
     yp_pri = yp_pri + [chain[0].yp_pri] 
     X_shower = X_shower + [chain[0].X_shower/10**10] 
     Y_shower = Y_shower + [chain[0].Y_shower/10**10] 

所以我的問題是我怎麼讀向量,因爲如果我使用同樣的方法:鏈[0] .xp_pri,程序停止工作?

+0

您應該包括一個完整的例子(包括任何進口),否則就很難得到解決你的問題的上下文。 – Ajean

回答

0

創建

myvec = ROOT.std.vector('float')() 

myvec = ROOT.std.vector('int')() 

然後:

chain.SetBranchAddress("the_branch_name",myvec) 

後:

chain.GetEntry(some_entry_number) 

myvec會將包含事件編號some_entry_number值。

你的其他選擇是使用root_numpy它也能夠檢索矢量。