hadd/TChain with files with multiple copies of the same tree


I am currently experiencing a weird problem:
my input files have two entries for my TTree: tree:

tree n has the right number of events, tree (n-1) has LESS events.

When I merge the files the first entry (n-1) is taken and the merged file contains less events than it should.

Is there a way of telling hadd to take only the most recent instance (tree;n)?
Is there also a way to do the same when reading it via a TChain?

In both cases the number n is unknown.

I have two example files located here:

Thanks in advance!



TChain does the right thing. It always takes the tree;n instance.

How can I force ‘hadd’ to do the same or can I use TChain to perform the task ‘hadd’ does?


Which version of ROOT are you using?


I am using version 5.27/06b (comes with the framework) for the creation of the data and 5.28/00b for the analysis.

Another thing I saw: it happens only to bigger files. Files as small as 1MB seem not to be affected whilst files >-50MB have usually more than one tree.

Hi Luke,

This is quite odd as literally, those version of hadd using a TChain to do the merging. Could you provide a running example showing the problem?


It seems I can’t reproduce the error, neither with the previous version of ROOT I was using (5.22/00d) nor with the ones mentioned above.

I am confused but also happy that it doesn’t occur any more.
However, to be fair I tested only merging two files and no 12 or more as usual.