# Leaf with array!

**URL:** <https://root-forum.cern.ch/t/leaf-with-array/59285>\
**Category:** Newbie\
**Created:** [May 10, 2024, 3:58am UTC](https://root-forum.cern.ch/t/leaf-with-array/59285 "2024-05-10T03:58:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saurav](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@Saurav](https://root-forum.cern.ch/u/Saurav)\
**Post date:** [May 10, 2024, 3:58am UTC](https://root-forum.cern.ch/t/leaf-with-array/59285/1 "2024-05-10T03:58:08Z")

</div>

Dear Experts,

1. 

If I have a leaf named Interaction that looks like Interaction[hit][4] in the header file with [hit] of dimension 100 ,and [4] refers 0 as x, 1 as y, 2 as z and 3 as t coordinates. In my c++ macro I am trying to loop over time (Interaction[hit][3]) but I don’t understand how to write the for loop condition with the the index variable `[3]` from `Interaction[hit][3]`, Please help me write this condition.

1. Also how do I look at all the numbers in Interaction[hit][3] leaf using a terminal command.

Thank you,  
Saurav

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [May 10, 2024, 4:14am UTC](https://root-forum.cern.ch/t/leaf-with-array/59285/2 "2024-05-10T04:14:30Z")

</div>

Hi,

1. Do you mean looping over a 2D array in C++?

```auto
for (int hit_i = 0;hit_i <100;hit_i++) {
   for (int coord_i = 0;coord_i <3;coord_i++) {
      std::cout << Interaction[hit_i][coord_i] << std::endl;
   }
}

```

1. Have you had a look to TTree::Scan ? [ROOT: TTree Class Reference](https://root.cern.ch/doc/master/classTTree.html#af8a886acab51b16d8ddbf65667c035e4)

In any case, I would advise to consider [RDataFrame](https://root.cern/doc/master/classROOT_1_1RDataFrame.html) for all your analysis and manipulation of columnar data.

Best,  
Danilo

---

<div class="post-metadata">

**Author:** ![Saurav](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@Saurav](https://root-forum.cern.ch/u/Saurav)\
**Post date:** [May 10, 2024, 5:15am UTC](https://root-forum.cern.ch/t/leaf-with-array/59285/3 "2024-05-10T05:15:36Z")

</div>

HI Danilo,  
Thanks for your response.  
Yes, I am trying to loop over a 2D array. I already looped over the [hit], now I am trying to loop over only the time coordinate, I don’t want to loop the spatial coordinates. So while doing the second for loop, how do I assign the time coordinate inside the array and only loop over all the values assigned to t.  
Also if you could explain this:  
for (int coord\_i = 0;coord\_i \<3;coord\_i++) {}  
it will be really helpful. As, what I understand from this is that you are also looping through x,y,z.

I did look at the scan feature ,I am not sure what to put inside the bracket to only view the time coordinate.

And, sure I will look into RDataFrame, thanks for pointing this out.

Regards,  
Saurav

```auto

```
