Create a Branch as a child of another Branch

Hi,

I’m very new to Root. I’ve successfully created a file with lots of TTree below, all of which have branches and leaves below them.

But - what i want to do is to create a deeper structure, using branches that are children of other branches. The TBranch::TBranch documentation seems to suggest this is possible: root.cern.ch/root/html/TBranch.h … :TBranch@3

But i cant get anything to work. I’ve checked the examples, and searched the root site for more detail, but not found any.

Can anybody help with some example code?

Cheers
Gerard

Hi Gerard,

what you might do is topbranch->GetListOfBranches()->Add(subbranch), but I would not really recommend this. What are you trying to achieve? Wouldn’t be your issue be solved by the way in which you design your data model? Btw, what do you intend to write?

Cheers,
Danilo

Hi Danilo,

thanks for the reply.

I’ll have a go at describing what i’m trying to do data-wise - i’m sure its basic, i’m just struggling to understand how to do it!

I want to store many sets of results, i was planning to store each of these result sets in their own branch.
Each set if results contains three data objects, table a, b and c.
Each result set is of variable length, table a is the same length as b, but different from c.
I have failed to understand how to store data of different lengths within the same branch. If i could do that, I’d probably be ok.

I’d imagined that if i could store each table in a child branch, off the original result branch, then i’d avoid my failure to understand how table a, b and c can be variable and differently sized!

Hope this helps to clarify what I’m up to.

Cheers
Gerard

Hi Gerard,

thinking at a problem from the data point of view is usually rather rewarding :slight_smile:

So if I understand correctly, you have many instances of 3 “tables”, which you call a,b and c. It is not clear to me what you mean by table here (is it an associative container? A list?), but what you might go for is an ROOT/stl/array like incarnation of the container (TList, …) and you could indeed have 3 branches, a,b,c. You could then refresh their content once per entry/event in your system.
Additional information could be found here:
root.cern.ch/root/html/tutorials/tree/index.html

Cheers,
Danilo

Hi Danilo,

I would like to store some fit results in a tree with branches for each detector and subranches for each individual fit for the detectors:

Tree
[ul]
[li] Detector 1
[list]
[] Fit 1
[/li][li]Fit 2
[/li][/ul]
[/
:m][li] Detector 2
[ul]
[] Fit 1
[/li][/ul]
[/
:m][li] Detector 3
[ul]
[] Fit 1
[/li][li] Fit 2
[/li][li] Fit 3
[/li][/ul][/
:m][/list:u]

So my problem is that the number of fits for each detector is not fixed. So I can not produce a class which holds the fit results as member variables.

You said early you would not recommend to create subbranches using
topBranch->GetListOfBranches()->Add(subbranch).

So here is my question: Why don’t you recommend this, and what would be an alternative to produce such a structure?

Cheers,

Achim

Hi Achim,

I think I understand you need a container (“Detector”) for your fits and you need one container per detector.
In principle, you can have a branch per container ( aka per detector) since this number will not change. On the other hand, you can increase the number of fits per detector simply resizing the container. In first approximation you could store your fits in a stl vector…

Cheers,
Danilo

Hi Danilo,

Thanks for the reply. Maybe I should have been more specific (sorry about that). I would like to see a structure with branches and subbranches in the tree-viewer and I would like to do something like this:

tree->Draw(“Detector1.Fit1.fReconstructedEnergy”)

Using containers was also my first idea, but then I would have to do this:

tree->Draw(“Detector1.Fit[2].fReconstructedEnergy”)

And with this method there is the problem that I (or some other users) would have to know in which order the different fits were performed. And that could lead to some confusion since the fits should have names like “CarrierEvents” or “TestPulses”

I hope that I made my problem a little bit clearer…

Cheers,

Achim