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?
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: