# TTreeReader does not find branch, TTree::Draw finds it

**URL:** <https://root-forum.cern.ch/t/ttreereader-does-not-find-branch-ttree-draw-finds-it/39642>\
**Category:** Newbie\
**Created:** [May 28, 2020, 11:33am UTC](https://root-forum.cern.ch/t/ttreereader-does-not-find-branch-ttree-draw-finds-it/39642 "2020-05-28T11:33:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfglinux\_gmail](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mfglinux_gmail/32/21046_2.png) [@mfglinux\_gmail](https://root-forum.cern.ch/u/mfglinux_gmail)\
**Post date:** [May 28, 2020, 11:33am UTC](https://root-forum.cern.ch/t/ttreereader-does-not-find-branch-ttree-draw-finds-it/39642/1 "2020-05-28T11:33:07Z")

</div>

Hello

I am learning how to use TTreeReader but I have miserably failed.

I have a file with 2 TTrees (I uploaded it to cernbox)

[https://cernbox.cern.ch/index.php/s/hqEk6R3Yc0vhWtI](https://cernbox.cern.ch/index.php/s/hqEk6R3Yc0vhWtI)

If I open it and Draw a leaf, I can do it without any problem:

```auto
root -l 2019-08-27_15-49-55_run.txt.root
ch0->Draw("raw.event")

```

When I try with TTreeReader, it tells me that raw.event does not exist

```auto
root -l 2019-08-27_15-49-55_run.txt.root 
root [0] 
Warning in <TClass::Init>: no dictionary for class TMeas is available
Warning in <TClass::Init>: no dictionary for class TTiming is available
Warning in <TClass::Init>: no dictionary for class TWaveform is available
(TFile *) 0x18b8290
root [1] TTreeReader reader(ch0)
Error in <TClass::Load>: dictionary of class TMeasHeader not found
(TTreeReader &) Name: TTreeReader Title: A simple interface to read trees
root [2] TTreeReaderValue<UInt_t> event(reader,"raw.event")
(TTreeReaderValue<UInt_t> &) @0x7fcb74e9c178
root [3] reader.Next()
Error in <TTreeReaderValueBase::CreateProxy()>: The tree does not have a branch, nor a sub-branch called raw.event. You could check with TTree::Print() for available branches.
(bool) false

```

Can you indicate what I am doing wrong? Thank you!

Marcos

* * *

_Please read [tips for efficient and successful posting](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292) and [posting code](https://root-forum.cern.ch/t/posting-code-read-this-first/28293)_

\_ROOT Version: 6.16/00  
\_Platform: ubuntu 16.04  
\_Compiler: g++ (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609

* * *

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [May 28, 2020, 12:18pm UTC](https://root-forum.cern.ch/t/ttreereader-does-not-find-branch-ttree-draw-finds-it/39642/2 "2020-05-28T12:18:47Z")

</div>

Hi Marcos,  
this is a bug in TTreeReader that is still present in ROOT v6.20 and will be fixed in the upcoming ROOT v6.22 (by [this PR](https://github.com/root-project/root/pull/5603), that you can apply to your ROOT installation if you compiled ROOT yourself).

I am not sure whether we have a workaround in the meanwhile, maybe @Axel or @pcanal have an idea.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![mfglinux\_gmail](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mfglinux_gmail/32/21046_2.png) [@mfglinux\_gmail](https://root-forum.cern.ch/u/mfglinux_gmail)\
**Post date:** [May 28, 2020, 1:12pm UTC](https://root-forum.cern.ch/t/ttreereader-does-not-find-branch-ttree-draw-finds-it/39642/3 "2020-05-28T13:12:51Z")

</div>

Hello Enrico

thank you very much for your answer, it is really appreciated. I got the impression that TTreeReader was advised to use more than the “older” SetBranchAddress.

Yes, I compiled ROOT myself, but I never applied a PR (is this a patch?) myself.  
Could you maybe instruct me where how to do that? Or maybe it is better first to wait for @Axel and @pcanal …

Marcos

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [May 28, 2020, 1:28pm UTC](https://root-forum.cern.ch/t/ttreereader-does-not-find-branch-ttree-draw-finds-it/39642/4 "2020-05-28T13:28:00Z")

</div>

Applying the patch is fairly simple, you can create a new git branch in which you pull the changes from that patch:

```auto
$ cd path/to/root_sources
$ git checkout -b eguiraud-fix_10702
$ git pull https://github.com/eguiraud/root.git fix_10702

```

At this point you just have to recompile.

Indeed `TTreeReader` has several advantages with respect to raw TTree usage, but sometimes it also has bugs 😅

If you are looking for a high-level C++ interface for ROOT data processing, you might also be interested in [RDataFrame](https://root.cern.ch/doc/master/classROOT_1_1RDataFrame.html) (see [here](https://root-forum.cern.ch/t/rdataframe-a-modern-tool-to-manipulate-and-analyze-root-datasets/29384) for the advertising forum post), which is based on TTreeReader but offers a nicer interface.

Cheers,  
Enrico
