How to read trees that are inside TList within TDirectory using TChain?

Dear all

I have to read TTrees from many root files together. The trees are located inside TLists within TDirectories. How does one read these trees using TChain? Whenever I use TChain to add the trees, root cannot find the tree.

The command I am trying to use is

TChain* ch = new TChain(“ResultsData/AnalysisMain_tree_FB768/fTreeEvent”)
ch->Add(“AnalysisResults1.root”)
ch->Add(“AnalysisResults2.root”)

I get the following error:

Error in TChain::LoadTree: Cannot find tree with name ResultsData/fTreeEvent in file datafile/AnalysisResults2.root

ROOT Version: 6.24/06
Platform: Ubuntu 20.04
Compiler: gcc

Thank you
Swati

Welcome to the ROOT Forum!
As the message is telling, there is apparently no ResultsData/fTreeEvent tree in the datafile/AnalysisResults2.root file… Can you check with rootls -l datafile/AnalysisResults2.root?

Hi Bellenot,

Thanks for the quick reply. I posted the error wrongly.
The error is

Error in TChain::LoadTree: Cannot find tree with name ResultsData/AnalysisMain_tree_FB768/fTreeEvent in file datafile/AnalysisResults1.root
Error in TChain::LoadTree: Cannot find tree with name ResultsData/AnalysisMain_tree_FB768/fTreeEvent in file datafile/AnalysisResults2.root

After running the makeclass command over a single root file, I run some codes and see the error.

Unfortunately, I cannot attach any files or pictures here as the website is not allowing to post them currently.

Thanks
Swati

You should be able to attach files now

Hi Bellenot,

After running the makeclass command over a single root file (test.C and test.h are generated), I run the following codes and see the error.

test.h (11.3 KB)
test.C (1.4 KB)
runChain.C (407 Bytes)

Here is the structure of the root file

Screenshot from 2023-06-13 17-12-54

Thanks
Swati

OK, thanks for the example. Maybe @pcanal can tell if and how it’s supposed to work…

Out of curiosity why was this choice made (usually TTree are very large and thus there is only a few per files and TDirectory is already a list) …

? Whenever I use TChain to add the trees, root cannot find the tree.

This setup was not envisioned and is not supported in TChain.

1 Like

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