How to access elements of std.vector<double> object type in PyROOT

I am fairly new to using ROOT, so please bear with me.

Currently, I am trying to comb through the data from a ROOT file and access the particular entries of a tree. The issue I am having is that I don’t know how to interface with std.vector data types in PyROOT.

Here is my code:

f = TFile.Open("/Users/user/work/GEMC_Sim/GEMC_Simulation/clas12Tags/config/Trials.root")

tree = f.Get('flux')


for idx,event in enumerate(tree):

{ 11 }
{ 11,11 }

In this output, there are either these empty braces or they are filled with individual particle index values or they are grouped together with multiple entries. What I want is to create a separate index that increases by one every time that one 11 is identified in each brace. For instance, {11,11,11} would increase the index by one. Similarly, {11} would also increase the index by one.

If this was a normal python data type I would know how to work with this, but I am a bit confused as to how to work with the std.vector data type. Any insight or suggestions is greatly appreciated.

ROOT Version: ROOT 6.24/06

Welcome to the ROOT forum.
I guess @etejedor can help you.

1 Like


You can work with an std::vector from Python in the same way you would do it from C++ – all its methods are available. You can also iterate over it in a pythonic way (for elem in vector: …) or access individual positions. Iterating should be enough to check that all elements are 11.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.