# Accessing sub entries in entries

**URL:** <https://root-forum.cern.ch/t/accessing-sub-entries-in-entries/56097>\
**Category:** Newbie\
**Tags:** tree, root\
**Created:** [August 22, 2023, 3:42am UTC](https://root-forum.cern.ch/t/accessing-sub-entries-in-entries/56097 "2023-08-22T03:42:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![d\_ana](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/d_ana/32/33918_2.png) [@d\_ana](https://root-forum.cern.ch/u/d_ana)\
**Post date:** [August 22, 2023, 3:42am UTC](https://root-forum.cern.ch/t/accessing-sub-entries-in-entries/56097/1 "2023-08-22T03:42:04Z")

</div>

Hello, I am a beginner.

My branches are:

\*Br 0 :event\_number : Int\_t \*  
\*Entries : 10 : Total Size= 745 bytes One basket in memory \*  
\*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 \*  
_…_  
\*Br 1 :momentum\_unit : Int\_t \*  
\*Entries : 10 : Total Size= 739 bytes One basket in memory \*  
\*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 \*  
_…_  
\*Br 2 :particles : Int\_t particles\_ \*  
\*Entries : 10 : Total Size= 92400 bytes One basket in memory \*  
\*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 \*  
_…_  
\*Br 3 :particles.pid : Int\_t pid[particles\_] \*  
\*Entries : 10 : Total Size= 7711 bytes One basket in memory \*  
\*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00  
_…_  
`where Br 3 has 10 entries and each of those 10 entries have varying sub-entries when I used TBrowser to check individual`event\_number`plots for example,`tree-\>Draw(“particles.pid”, “event\_number==1”)`, but i am not able to access the sub-entries and when I print`particles.pid` it only returns 24 subentries repeatedly for all 10 entries.

Any suggestions? Thank you!!!

My current C code is:

```auto
TFile f("TTreefile.root");
TTree* tree;
f.GetObject("tree", tree);
Int_t totalEntries = tree->GetEntries();
Int_t event_number, momentum_unit, pid[particles_];

tree->SetBranchAddress("event_number",&event_number);
tree->SetBranchAddress("particles", &particles_);
tree->SetBranchAddress("particles.pid", pid);

for (int i = 0; i < totalEntries; ++i) {
     tree->GetEntry(i);
      for (Int_t j=0; j< particles_; ++j){
         printf("Sub-entry %d: %d\n", i++, pid[i]);
      }

}

```

_ROOT Version:_ 6.26/06  
_Platform:_ mac  
_Compiler:_ Not Provided

* * *

---

<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:** [August 22, 2023, 6:47am UTC](https://root-forum.cern.ch/t/accessing-sub-entries-in-entries/56097/2 "2023-08-22T06:47:30Z")

</div>

Welcome to the ROOT forum

Maybe you can provide your file `TTreefile.root` in order to inspect it ?

---

<div class="post-metadata">

**Author:** ![d\_ana](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/d_ana/32/33918_2.png) [@d\_ana](https://root-forum.cern.ch/u/d_ana)\
**Post date:** [August 25, 2023, 5:52pm UTC](https://root-forum.cern.ch/t/accessing-sub-entries-in-entries/56097/3 "2023-08-25T17:52:23Z")

</div>

I am not able to attach or link the root file as I am a new user, is there is a way to share the root file?

Thank you!!

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [August 26, 2023, 1:05pm UTC](https://root-forum.cern.ch/t/accessing-sub-entries-in-entries/56097/4 "2023-08-26T13:05:14Z")

</div>

Dear @d_ana ,

Is this a good starting point for you?

```c++
ROOT::RDataFrame df{"tree", "TTreefile.root"};

df.Display()->Print();

```

Or equivalently in Python

```python
df = ROOT.RDataFrame("tree", "TTreefile.root")
df.Display().Print()

```

For other operations you can define on your dataset, see the docs at [ROOT: ROOT::RDataFrame Class Reference](https://root.cern/doc/master/classROOT_1_1RDataFrame.html)

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![d\_ana](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/d_ana/32/33918_2.png) [@d\_ana](https://root-forum.cern.ch/u/d_ana)\
**Post date:** [August 26, 2023, 10:06pm UTC](https://root-forum.cern.ch/t/accessing-sub-entries-in-entries/56097/5 "2023-08-26T22:06:44Z")

</div>

Thank you for the quick response. I am trying what you suggested, but is `df.Display().Print()` not supposed to print out anything?

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [August 27, 2023, 10:42am UTC](https://root-forum.cern.ch/t/accessing-sub-entries-in-entries/56097/6 "2023-08-27T10:42:40Z")

</div>

Dear @d_ana ,

Not sure what you mean, `Display` does what the [documentation](https://root.cern/doc/master/classROOT_1_1RDF_1_1RInterface.html#a39c3e60011400378da41d325bc442d20) suggests

```auto
$: rootls -l Run2012BC_DoubleMuParked_Muons.root
TTree May 20 06:17 2019 Events;75 "Events" [current cycle]
TTree May 20 06:17 2019 Events;74 "Events" [backup cycle]
$: python -c "import ROOT; df = ROOT.RDataFrame('Events','Run2012BC_DoubleMuParked_Muons.root'); df.Display().Print()"
+-----+-------------+------------+-----------+-------------+----------+-------+
| Row | Muon_charge | Muon_eta | Muon_mass | Muon_phi | Muon_pt | nMuon | 
+-----+-------------+------------+-----------+-------------+----------+-------+
| 0 | -1 | 1.06683f | 0.105658f | -0.0342727f | 10.7637f | 2 | 
| | -1 | -0.563787f | 0.105658f | 2.54262f | 15.7365f | | 
+-----+-------------+------------+-----------+-------------+----------+-------+
| 1 | 1 | -0.427780f | 0.105658f | -0.274792f | 10.5385f | 2 | 
| | -1 | 0.349225f | 0.105658f | 2.53978f | 16.3271f | | 
+-----+-------------+------------+-----------+-------------+----------+-------+
| 2 | 1 | 2.21086f | 0.105658f | -1.22341f | 3.27533f | 1 | 
+-----+-------------+------------+-----------+-------------+----------+-------+
| 3 | 1 | -1.58824f | 0.105658f | -2.07730f | 11.4292f | 4 | 
| | 1 | -1.75118f | 0.105658f | 0.251358f | 17.6340f | | 
| | 1 | -1.59100f | 0.105658f | -2.01305f | 9.62473f | | 
| | 1 | -1.65596f | 0.105658f | -1.84997f | 3.50223f | | 
+-----+-------------+------------+-----------+-------------+----------+-------+
| 4 | -1 | -2.17248f | 0.105658f | -2.37001f | 3.28344f | 4 | 
| | -1 | -2.18253f | 0.105658f | -2.30514f | 3.64401f | | 
| | 1 | -1.12336f | 0.105658f | -0.975242f | 32.9112f | | 
| | 1 | -1.16290f | 0.105658f | -0.773005f | 23.7218f | | 
+-----+-------------+------------+-----------+-------------+----------+-------+

```

---

<div class="post-metadata">

**Author:** ![d\_ana](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/d_ana/32/33918_2.png) [@d\_ana](https://root-forum.cern.ch/u/d_ana)\
**Post date:** [August 27, 2023, 10:48pm UTC](https://root-forum.cern.ch/t/accessing-sub-entries-in-entries/56097/7 "2023-08-27T22:48:39Z")

</div>

Thank you @vpadulan, I think using `RDataFrame` is the right direction to explore.

One follow-up question: Is there a docs reference to save `df.Display().Print()`? Or something that would expand the entries `...` e.g.:

```auto
+-----+----------------+
| Row | particles.mass | 
+-----+----------------+
| 5 | 0.93827000 | 
| | 0.93827000 | 
| | 0.0000000 | 
| | 0.0000000 | 
| | 1.5000000 | 
| | 1.5000000 | 
| | 0.0000000 | 
| | 0.0000000 | 
| | 0.0000000 | 
| | 0.0000000 | 
| | ... | 
+-----+----------------+
``
```

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [August 28, 2023, 7:26am UTC](https://root-forum.cern.ch/t/accessing-sub-entries-in-entries/56097/8 "2023-08-28T07:26:29Z")

</div>

HI @d_ana ,

Sure, it’s all in the docs [ROOT: ROOT::RDF::RInterface\< Proxied, DataSource \> Class Template Reference](https://root.cern/doc/master/classROOT_1_1RDF_1_1RInterface.html#a39c3e60011400378da41d325bc442d20) .

> nMaxCollectionElements Maximum number of collection elements to display per row.

---

<div class="post-metadata">

**Author:** ![d\_ana](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/d_ana/32/33918_2.png) [@d\_ana](https://root-forum.cern.ch/u/d_ana)\
**Post date:** [August 28, 2023, 5:15pm UTC](https://root-forum.cern.ch/t/accessing-sub-entries-in-entries/56097/9 "2023-08-28T17:15:39Z")

</div>

Thank you @vpadulan for all your help!
