ROOT Trees - (beginner question)

Hi All,

I have a class called Neuron that I want to store and retrieve using TTree.

The class has three int members and one TCloneArray. When I make the tree using the following code;

TTree* tree = new TTree(“NT”,“Tree with Neurons”);

for (Int_t=0;t<50;t++){
Neuron* n = new Neuron();
// set the three int data members

This results in having (50) NeuronObj branches at the top level under tree “NT”. There is no probelm in using the Scan, Draw methods for printing values contained in different Neuron objects.

When I use the Tree Viewer; on the top level I see data members of ALL 50 Neurons.


Similarly when I use MakeClass() ; the resultant NT.h file has Neuron data members (and branch decalrations) for ALL 50 Neurons. This results in a LONG header file. May be I am doing something wrong in the process.

Can some one suggest to me a better method to store these Neuron objects in tree. Or guide me to an example. I looked at ROOT tutorail tree4.C but it stores a SINGLE Event object in tree; where as I need to store multiple top level objects.

I tried using a “NeuronContainer” class with TClonesArray of Neurons. And stored “NeuronContainer” object in tree. But this did not result in sort of organisation that I want.

Thanks in advance

Hi Asif,
trees are two dimensional: for each entry in the tree (that’s one dimension) there are several branches and leaves (that’s the other dim). One creates branches by calling TTree::Branch; one adds entries by calling Fill. You seem to have a tree with only one entry, though with several branches (actually you’re mixing this improperly - you create 50 branches with the same name, filling the first branch 50 times, the second one 49 times etc) - so in principle one dimension is sufficient for you. What might be more appropriate than a tree is a single TClonesArray of Neurons:

[code]TClonesArray* ca = new TClonesArray(“Neuron”);

for (Int_t t=0;t<50;t++){
Neuron* n = new ((ca)[t]) Neuron();
// set the three int data members
Note that the Write call only needs to be issued once, not once per entry. If this answer does not give the results you wanted please let us know more details of what file structure you’re looking for.

Thanks a lot for reply. I now better understand the tree structure. However; I do need a tree for storing my objects and I used TClonesArray (as suggested by you) and tree. This time it works perfectly fine for me.