Storing a non-fixed sized Array in a Branch

I am currently working on storing positions of primary vertexes reconstructed in pile up
events. I am looking for a way to store an array of these vertex positions for each entry (ie
bunch crossing). But from one entry to the next, the number of vertex positions needed to
be stored varies. So far i have tried to implement using TArrayF, but have failed to get it to
work. In general, is there a safe and easy way of writing an array of a variable size into the
root tree?

Cheers,
Gareth

Hi,

create a class representing your vertex position. Create a TTree, and add one branch containing a TClonesArray of that class. For each bunch crossing you create the vertex positions in the TClonesArray, and then fill the tree.

This is time and space efficient, and you can even change the layout of your vertex class when you need it. Check the Users Guide for how to set up a branch with a TClonesArray and how to fill it.

Cheers, Axel.

[quote=“Axel”]Hi,

create a class representing your vertex position. Create a TTree, and add one branch containing a TClonesArray of that class. For each bunch crossing you create the vertex positions in the TClonesArray, and then fill the tree.

This is time and space efficient, and you can even change the layout of your vertex class when you need it. Check the Users Guide for how to set up a branch with a TClonesArray and how to fill it.

Cheers, Axel.[/quote]

Thanks for the suggestion, but i was hoping to do it without having to create my own class, as i have been told i would need to use dictionaries and such. So i decided to just use a fixed size array (large enough for high luminosity pile up) and fill that. But i keep getting a segmentation violation when i run it. Can anyone give any possible explanation?

Cheers
Gareth

Did you look at the standard ROOT tutorials in $ROOTSYS/tutorials/tree ?
for instance tree3.C or other tre*.C tutorials ?

Rene

[quote=“brun”]Did you look at the standard ROOT tutorials in $ROOTSYS/tutorials/tree ?
for instance tree3.C or other tre*.C tutorials ?

Rene[/quote]

Thanks, i have finally got it semi working creating the tree as below

out_tree->Branch("NoRecVx",&nrecvx,"nrecvx/I"); out_tree->Branch("RecVxPile",rec_pile_v,"x[nrecvx]/F:y[nrecvx]/F:z[nrecvx]/F");
and then inserting the information by int t1 = a + nrecvx; int t2 = t1 + nrecvx; rec_pile_v[a]= (*i)->recVertex().position().x(); rec_pile_v[t1]= (*i)->recVertex().position().y(); rec_pile_v[t2]= (*i)->recVertex().position().z();
going over a upto NoRecVx where that is the number of reconstructed vertices.

currently it is recording the same information in all 3 leafs, which suggests that my way of inserting into the second and third leafs is wrong.

Does anyone know the correct way of filling?

Cheers

Gareth

Instead of a single array and a single branch, try 3 arrays and 3 branches.

Philippe

[quote=“pcanal”]Instead of a single array and a single branch, try 3 arrays and 3 branches.

Philippe[/quote]

I was hoping to get 1 branch with 3 leafs that were arrays, as the other way makes it a bit untidy, though of course if that is the only way then it will have to do.

Is it possible to use an array of TVector3’s and fill them into a branch?

Gareth

Yes you could use a TClonesArray of TVector3.

Philippe