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.
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?
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!
thinking at a problem from the data point of view is usually rather rewarding
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
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…
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:
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…