Python を使用して、ROOT ファイル内の TTree の 1 つに新しいブランチを追加する方法を知りたいです。
with root_open('MC_output.root', mode='a') as myfile:
new_column = numpy.array(gb_weights , dtype=[('weight', 'f8')])
root_numpy.array2tree(new_column , tree=myfile.TrainTree)
new_column_test = numpy.array(gb_weights_test , dtype=[('weight', 'f8')])
root_numpy.array2tree(new_column_test, tree=myfile.TestTree)
myfile.write()
myfile.close()
この例では、TrainTree と TestTree は ROOT ファイルに既に存在します。それらに新しいブランチ「重み」を追加したいだけです。ここでの問題は、ツリーが複製されることです。そのため、私のファイルには 2 つの TrainTree と 2 つの TestTree があります。
この問題を解決するには、一時ファイルを使用する必要がありますか? それとも、それを行うためのより良い、より簡単な方法はありますか?
ご協力いただきありがとうございます!