How to use TChain to combine many .root files

I have recently started using root and I cant figure out how to use TChain command. I have a bunch of “L1 Ntuple_.root" that are consisted of many trees ("” stands for the number on the file and goes like 1,2,3,4…) and I am trying to use TChain to combine the entries from these trees into one tree, I proceed as following:

TChain* chain = new TChain (“L1EventTree”)

/* where L1EventTree is one of the trees inside the file*/

TFile* f = new TFile(“output”,“create”);

but when I use TBrowser it shows an empty output file. I am not sure what I am missing here. Any help is appreciated.

Try to execute:
rootls --help
rootcp --help
hadd --help

1 Like

Inside root I did .x hadd --help and .x rootcp --help and it gives me an error. is that what you were suggesting?

These are standalone executables.

Thank you Wile_E_Coyote this is much better than TChain and merging each tree one by one, but I am still wondering why TChain didn’t work in my case.

Instead of

TFile* f = new TFile("output","create");

you should have tried


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