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

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

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

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

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 and posting code

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


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, 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

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

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

$ 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 :sweat_smile:

If you are looking for a high-level C++ interface for ROOT data processing, you might also be interested in RDataFrame (see here for the advertising forum post), which is based on TTreeReader but offers a nicer interface.

Cheers,
Enrico