How to write a branch directory?

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

image-a68yybox6brz9juoznthkm4njw

I have tried chatgpt’s code:

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

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

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

tree->Fill();

But there’s no branch like muonData.pt 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

Cheers,
Marta

1 Like

Hi,
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…

Cheers.
Jérôme

You probably did not generate the dictionary for the class (see https://root.cern.ch/root/html534/guides/users-guide/AddingaClass.html). 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.