3D Arrays or Vectors in TTree

Hello,

Sorry if this is a repeated question, but I have been unable to find an answer in the forums. I am attempting to write a 3D vector or array into a TTree using c++, then read it back using python. A vector would be preferable, but I can also live with arrays if it is necessary.

I’ve tried several things so far. Writing a 3D vector using c++ seems to be supported for int/doubles after adding the appropriate dictionaries, though not for unsigned integers. But for each TTree->Fill() called, the new 3D vector entry does not have the updated values, but only repeats the initial values from the very first call. I find that this is not the case with 2D or 1D vectors, but only with 3D vectors. If I can properly write a 3D vector to a TTree, I will be able to succesfully read it in python by looping over events in Tree (vectors don’t appear to suffer from the recent “TypeError: attempt to bind ROOT object w/o class”)

If I need to use 3D arrays, I am having trouble reading them in pyroot. When doing a for loop over events in the tree,the object suffer from the recent TypeError problem. Can I set up a three dimensional array.array or numpy.array which will allow me to read in 3D arrays from a ttree?

Thanks for your help,
Jeff

Jeff,

is this 3D array a builtin array, or an object of some type?

Historically, multi-dimensional builtin arrays have not been supported well in Python, and now that they are (since python2.6 really, after a push from the numpy folks), I have yet to find the time to integrate them well. An object of an 3D array type should work fine, though.

So, if it’s not a builtin array, do you have some code showing the problem?

Cheers,
Wim

Hi Wim,

Ok, we have switched to arrays, rather than std vectors, and it seems to be working ok. Thanks for your reply!

Jeff