Creating a subbranch

Hello, ROOTers.
I am very new to ROOT, and I need some help to make my Tree organized better.
I’m trying to make subbranches under a parent branch using, but I can’t get it to work.

Here is how I tried:

TBranch *parentbranch = tree->Branch("parent", &parent, "parent/i");
TBranch(parentbranch, "child", &child, "child/i");

The result of this is a branch with a leaf “parent” and nothing else.

So what I want to make is a tree with a structure like

Parent Branch 1
- Child Branch 1
- Child Branch 2
- Child Branch 3
- Some Leaves
Parent Branch 2

and so on.

Can anyone help me?

have you look at the tree examples here : … index.html

[quote=“couet”]have you look at the tree examples here : … index.html

Yes, I have.
Should I be able to figure it out after reading those examples?

I guess so.

Also: … nd-courses … rimer.html … Trees.html

if you do not manage, the best is to post here the smallest possible macro reproducing the problem.

Search for “splitting”, “split-level” and “splitlevel” in:
TTree class description
"ROOT User’s Guide" -> “Trees” -> “Adding a TBranch to Hold an Object”
“ROOT User’s Guide” -> “Trees” -> “Adding a Branch to Hold a List of Variables”

I have the same problem, and could not find a solution in what was suggested: how to build a sub-branch of a branch, from a list of leaves, not from a class object.

I tried this (as a kind of minimal example):

**// define a branch**
Int_t myBuffer [3] = { -1, -1, -1 };
TBranch * myBranch = outTree->Branch ( "MainBr", &myBuffer[0], "VarA/I:VarB/I:VarC/I" );

**// define a sub-branch of the main branch**
Int_t mySubBuffer[2] = { -1, -1 };
TBranch * mySubBranch = new TBranch ( myBranch, "SubBr", &mySubBuffer[0], "VarSub1/I:VarSub2/I" );
myBranch->GetListOfBranches()->Add ( mySubBranch );

but when setting non-zero values in the buffers, and filling the TTree:

  • if reading the TTree entries, the sub-branch leaves are 0
  • with a TBrowser in ROOT, the sub-branch does not appear