Efficient way to save a big array of floats in a TTree?

Hello :smiley:,

I am looking for an efficient way to save a big array of floats in a TTree.
The number of entries in each array can be VERY big!!! And the maximum
number of entries in each array is not known in advance so I can not use
the usual method:

Int_t filterNumber, numberOfEntries;
Float_t invMass[MAX_NUMBER_OF_ELEMENTS];
TTree* invMass = new TTree(outputTreeName, title);
invMass->Branch(ā€œfilterNumberā€, &filterNumber, ā€œfilterNumber/Iā€);
invMass->Branch(ā€œnumberOfEntriesā€, &numberOfEntries, ā€œnumberOfEntries/Iā€);
invMass->Branch(ā€œinvMassā€, invMass, ā€œinvMass[numberOfEntries]/Fā€);

because I do not know MAX_NUMBER_OF_ELEMENTS.

How to do that efficient? I am looking for a rare process and will have to
process hundreds of millions of events several times to adjust breaking of the
event set into correct subsets for the event mixing method.

In particular I was said that TArrayF is going to reallocate memory each time
one adds a new element into it and it is not possible to use TClonesArray
with fundamental types. Is it true? :unamused:

Is it possible to save (STL) vector in a TTree? (ROOT v3.05/07)

Or I have to save TTrees(TNtuples) in my TTree instead of arrays?

Thanks a lot!!! :slight_smile:
Sergei.

Hi Sergei,

you could think about writing a small class for the invariant masses and storing the instances in a TClonesArray. I think this is the most efficient and fastest way when analysing trees.

Cheers,
Oliver