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 http://root.cern.ch/root/html/TBranch.html#TBranch:TBranch@3, 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

Tree
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 :
root.cern.ch/root/html534/tutori … index.html
?

[quote=“couet”]have you look at the tree examples here :
root.cern.ch/root/html534/tutori … index.html
?[/quote]

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

I guess so.

Also:

root.cern.ch/drupal/content/tuto … nd-courses

root.cern.ch/root/htmldoc/guides … rimer.html

root.cern.ch/root/htmldoc/guides … 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”

Hello,
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