Interactively merge two root files containing TTrees

ROOT Version: 6.18
Platform: Ubuntu 18.04

I have two root files “tree_1000.root” and “tree_1001.root”, both containing the same type of TTree (“DataTree”).
I can open an interactive session with “root -l tree_1000.root
and then plot variables from that tree (e.g. “DataTree->Draw("Energy")), but what if I want to use the contents of both files to get a plot with more statistics? I tried opening the files with TChain interactively (TChain* chain = new TChain("tree_1000.root")), but that didn’t work (”chain->GetTTree()" returns a zero pointer). So how can I do this?

Hi @machiel,

TChain constructor requires tree name, not file name as an argument. This should work:

// Construct the chain
// TChain* chain = new TChain("DataTree");
TChain chain("DataTree") // short version of above
chain.AddFile("tree_100[01].root"); // Add files using wildcard
chain.Draw("Energy");

You also can merge similar root files with this command in terminal:

$ hadd final.root tree_1000.root tree_1001.root

and then work with 1 file

cheers,
Bohdan

Thank you very much, both methods you suggested work perfectly now.

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