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

**URL:** <https://root-forum.cern.ch/t/how-to-access-elements-of-std-vector-double-object-type-in-pyroot/50998>\
**Category:** Newbie\
**Tags:** tree, python, root\
**Created:** [July 28, 2022, 5:17pm UTC](https://root-forum.cern.ch/t/how-to-access-elements-of-std-vector-double-object-type-in-pyroot/50998 "2022-07-28T17:17:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Austin\_Shipley](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/austin_shipley/32/30429_2.png) [@Austin\_Shipley](https://root-forum.cern.ch/u/Austin_Shipley)\
**Post date:** [July 28, 2022, 5:17pm UTC](https://root-forum.cern.ch/t/how-to-access-elements-of-std-vector-double-object-type-in-pyroot/50998/1 "2022-07-28T17:17:29Z")

</div>

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:

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

#f.ls()

tree = f.Get('flux')

tree.Print()

for idx,event in enumerate(tree):
    
    print(idx,event.pid)
            

```

> {}  
> { 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

* * *

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [July 29, 2022, 7:09am UTC](https://root-forum.cern.ch/t/how-to-access-elements-of-std-vector-double-object-type-in-pyroot/50998/2 "2022-07-29T07:09:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [July 29, 2022, 8:14am UTC](https://root-forum.cern.ch/t/how-to-access-elements-of-std-vector-double-object-type-in-pyroot/50998/3 "2022-07-29T08:14:41Z")

</div>

Hello,

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.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [August 12, 2022, 8:15am UTC](https://root-forum.cern.ch/t/how-to-access-elements-of-std-vector-double-object-type-in-pyroot/50998/4 "2022-08-12T08:15:08Z")

</div>

Closed on August 12, 2022, 8:15am UTC

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