How to write a branch directory?

Hi, all! Anyone know how to write a branch directory like this?


I have tried chatgpt’s code:

Muon muonData; = 25.0;
muonData.eta = 0.8;
muonData.phi = 1.0;

TTree* tree = new TTree(“ParticleData”, “Particle Data”);

tree->Branch(“MuonBranch”, “Muon”, &muonData);


But there’s no branch like in output tree.

1 Like

Hi @Wenjie,

thank you for reaching out on the ROOT forum as chatgtp is not always an answer… especially in a bit more specialised cases as ROOT framework is.

You could indeed start by reviewing the details of the TTrees as was suggested above. What you want here is a sub-branch (or a leaf) and you are now only creating a Branch in your Tree, you can also follow this forum post for more details: TTree: creating a sub-branch of a branch from scratch


1 Like

As far as I understood, I think the problem is more simple than the case you mention (TTree: creating a sub-branch of a branch from scratch)

Indeed, my point was to created nested branches, while here it simply question of a standard branch.
The answer is most likely in the TBranch or TTree::Branch documentation.

In the code (from chatgpt ???) it is not clear how the leaves are defined and how their address is set (to the members of the muon object (struct / class ?).

I guess the class needs to be known by ROOT (included in the dictionnary).
But I did not try that, I usually split data in basic type leaves…


You probably did not generate the dictionary for the class (see Or maybe even simpler load your code via ACLiC

1 Like

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