How to read specific range of events from each TChained .root

Hello

I have made a MakeClass for three .root files which have the same TTrees. The problem is that these .root do not have the same number of events in general. So, is it possible somehow to force while looping over the events to read exaclty X events from the first chained .root, then skip events until I reach the second chained .root, read again X events etc ?

Thanks

Hi,

why not opening these files separately, e.g. in a loop and build a second, nested loop on N events on each of the trees?

Cheers,
Danilo

The function TChain::GetTreeOffet() gets you the offset for each file in the TChain. So I think something like this should work:

TChain c("ntuple");
c.Add("hsimple1.root",0);
c.Add("hsimple2.root",0);
c.Add("hsimple2.root",0);

Long64_t* offset = c.GetTreeOffset();
for (int i = 0; i < c.GetNTrees();i++) {
  for (int j = 0; j < X; j++) {
    c.GetEntry(offset[i]+j);
    ...
   }
 }