# Unable to get value of TLeaf in TTree without first \`Scan()\`-ing it

**URL:** <https://root-forum.cern.ch/t/unable-to-get-value-of-tleaf-in-ttree-without-first-scan-ing-it/50293>\
**Category:** Newbie\
**Created:** [June 6, 2022, 8:02pm UTC](https://root-forum.cern.ch/t/unable-to-get-value-of-tleaf-in-ttree-without-first-scan-ing-it/50293 "2022-06-06T20:02:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ammitra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ammitra/32/29935_2.png) [@ammitra](https://root-forum.cern.ch/u/ammitra)\
**Post date:** [June 6, 2022, 8:02pm UTC](https://root-forum.cern.ch/t/unable-to-get-value-of-tleaf-in-ttree-without-first-scan-ing-it/50293/1 "2022-06-06T20:02:51Z")

</div>

_ROOT Version:_ 6.20/07  
_Platform:_ linuxx8664gcc  
_Compiler:_ Not Provided

* * *

Hello,

I have a bunch of ROOT files with TTree named `Events`, under which I’ve saved a few TLeaves containing information about the number of events remaining after various cuts. I notice that, regardless of whether I’m using C++ or pyROOT, I’m unable to get the value of _any_ TLeaf without first calling `TTree::Scan()`, either on the entire tree or specifying that individual leaf. Here is an example of what I mean:

**Expected Behavior:**  
Let’s just say the value of `NPROC` is `57077.000`, then I’d expect:

```auto
root [1] Events->GetLeaf("NPROC")->GetValue()
(double) 57077.000

```

**Actual Behavior:**  
Instead, I have to call `Scan()` first to obtain the actual value.

```auto
root [1] Events->GetLeaf("NPROC")->GetValue()
(double) 0.0000000
root [2] Events->Scan("")
**********************************************************************************
* Row * Instance * NPROC * NFLAGS * Dijet_par <continued...>
**********************************************************************************
* 0 * 0 * 57077 * 56781 * 0.0002844 * ....
<continued...>
root [3] Events->GetLeaf("NPROC")->GetValue()
(double) 57077.000

```

I’ve just shown an example via the command line, but the same happens for me when using a C++ or pyROOT script. What is the explanation for this behavior, and is there a better way of getting the value of the leaf? Thank you in advance!

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [June 7, 2022, 8:49am UTC](https://root-forum.cern.ch/t/unable-to-get-value-of-tleaf-in-ttree-without-first-scan-ing-it/50293/2 "2022-06-07T08:49:33Z")

</div>

Welcome to the ROOT forum, @ammitra !

A `TTree` is a storage-backed vector, and before you retrieve an entry’s value you need to tell the `TTree` which entry you want to access using `Events->GetEntry(0)` or whatever.

But I’d recommend not going there. Instead please use the much more robust and simple [`RDataFrame`](https://root.cern/doc/master/classROOT_1_1RDataFrame.html).

Cheers, Axel

---

<div class="post-metadata">

**Author:** ![ammitra](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ammitra/32/29935_2.png) [@ammitra](https://root-forum.cern.ch/u/ammitra)\
**Post date:** [June 7, 2022, 12:58pm UTC](https://root-forum.cern.ch/t/unable-to-get-value-of-tleaf-in-ttree-without-first-scan-ing-it/50293/3 "2022-06-07T12:58:40Z")

</div>

Thank you, @Axel !  
I’ll use an `RDataFrame` for this task, thank you very much. In fact, the files I am reading were generated using `RDataFrame::Snapshot()`, so I’ll just stick with using the dataframe to read from them. Thanks again!
