Merging two root files without merging the trees/histo

Hi ROOT community,

I am trying to merge two root files, each one of them containing a tree, with hadd. However, when doing the usual “hadd target.root source1.root source.2.root”, it combines the two trees into one and the histograms contained in these two trees. However, this is not really what I want.

What I am trying to achieve is to combine these two root files into one without merging the trees so when opening the resulting merged file, I see the two trees of the two source files. I have tried using hadd with the -T option but it only results in an empty merged root file. Any idea on how to do what I want?

Thanks everyone :slight_smile:

If hadd was able to merge these two trees into one it is because they are the same in both files (same name, same structure etc …) . So if you put these to identical trees into the same file how will you be able to differentiate them ?

Thanks for your answer.

Well, I don’t really have any other choices. I can always rename the trees and variables once the files are merged since I know the shapes of the distributions for each variables in the trees. They’re nothing but simple histograms I can easily identify by eyes.

The thing is that I’m trying to obtain the same format as the one used in the example of the TMVA package, which shows two trees with the same variables in each, all in one root file.

Yes but imagine you have two trees with the same name in the same file, how ROOT will be able to identify which one you want to access ? It is like having two files with the same name inside a folder: that’s not possible
May be you can rename one of the tree before doing hadd using the command line tools described here:

Thank you very much for your answer. You made me realize that I had indeed named my trees with the exact same name, which of course created a conflict when merging the two root files. I recreated these two files and gave the trees different names and now, the hadd command is doing what I expected it to do :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.