Merging TTrees from different TDirectorys


ROOT Version: 6.08/06
Platform, Compiler: x86_64-slc6-gcc62


Hi,
I’m trying to take two TTrees with the same name, each in a different TDirectory in a file, and merge them. I am having trouble figuring out how to do this, either with TChain or hadd. TChain doesn’t like wildcards like

TChain ch("*/TreeName")
ch.Add("file1.root")
ch.Add("file2.root")
ch.Draw("x")

and using hadd doesn’t work given the different directory names.
How would I achieve this? Apologies if this is duplicated somewhere.

Edit: to clarify, the structure is

  1. file.root
    1.1 directory1
    1.1.1 TreeName
    1.2 directory2
    1.2.1 TreeName

Many thanks,
George

You can add the trees to a TList then use TTree::Merge.

I have since found that the easiest way is to use (here for separate files, I’m sure it works within a single file too):

TChain ch("TreeName")
ch.AddFile("file1.root",TChain::kBigNumber,"directory1/TreeName")
ch.AddFile("file2.root",TChain::kBigNumber,"directory2/TreeName")
ch.Draw("x")

Added this in case anyone else searches this in the future

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