Reading two Trees in parallel

I would like to read two trees from one ntuple (see below) inside my analysis program and
need to use variable from each tree simultaneously.
I have tried to make a « super » MakeClass file including both trees, but have not succeded.
I have not found information how to do this.

Is there a simple way to do this ?
Many thanks in advance,

Hi Isabelle,

You can create two TTreeReader instances. For example:

TFile *f = TFile::Open("freshConstants.root"); TTreeReader ofc_reader("OFC", f); TTreeReader shape_reader("SHAPE", f); TTreeReaderValue<Float_t> ofc_barrel_ec(ofc_reader, "barrel_ec"); TTreeReaderValue<Float_t> shape_barrel_ec(shape_reader, "barrel_ec"); while ( ofc_reader.Next()) { cout << *ofc_barrel_ec << endl; } while ( shape_reader.Next()) { cout << *shape_barrel_ec << endl; }
Cheers, Bertrand.

Dear Bertrand,

many thanks; this works like a charm!


What if I want read only one concrete entry and do not want to loop over all entries? TTreeReader will not help me?

May be this exemple can be of some help.
Note also that this thread was marked as solved. It is better to create a new one in that case.

You can use TTreeReader::SetEntry instead of TTreeReader::Next to read a specific entry.