Roottree with variable length array of struct

Hello Rooters,

I am trying to fill a root tree with an array of structs that I my data consists of.
I don’t know wether what I am doing is right. If have constructed the attached example from what I have learned reading the users guide on Trees.
In the write example I am not sure wether the branch is created in the right way. Since I don’t have a feeling for what the TTree::Fill() Method is doing I have some questions to this: In attached example will the Method fill the tree with all MaxHits Entries of the array. Or will it fill it with only the first entry of the array. Or will it fill it with the first nbrOfCurrentHits entries of the array? The last is the wanted situation. If the attached example is not doing what I want, how do I have to change it?

The more general question that I have is: Can the goal, that I am trying to reach, be archived using Root Trees?

Thank you,
treetest.c (2.19 KB)

[quote] I am not sure wether the branch is created in the right way.[/quote]No. You are explicitly requesting only one element (aka you never say to the branch what is the size of the array.

Also use the syntax you used (known as the ‘leaflist’ method) you can only use a struct of array (not an array of struct).

You could either use a vector (and compile via ACLiC and use the object method of branch creation), or you need to use

struct Hit { double x[MaxHits]; double y[MaxHits]; double t[MaxHits]; int meth[MaxHits]; }; .... tt->Branch("NbrHits",&nbrOfCurrentHits,"nbrHits/I"); tt->Branch("Hit.x",&(hit.x[0]),"x/D"; tt->Branch("Hit.y",&(hit.y[0]),"y/D"; tt->Branch("Hit.x",&(hit.t[0]),"t/D"; tt->Branch("Hit.y",&(hit.meth[0]),"meth/I";