1

I need to read a root tree that contains a 2D array stored within a struct and would like to use uproot for this.

For example: the following code-snippet creates a tree with both a 2D array and a 2D array within a struct. Uproot has no problem reading the 2D array by itself, but does not know how to parse it within the struct.

Is there a way to tell uproot how to parse this struct?

Float_t x2[15][2]={{0}};
struct POINT{
  Float_t x[15][2]={{0}};
  Float_t y[15][2]={{0}};
};
POINT point;
TTree tree("T","ROOT tree with 2D array and 2D array in struct");
tree.Branch("point",&point,"x[15][2]:y[15][2]");
tree.Branch("x2",x2,"x2[15][2]/F");
LMVogel
  • 779
  • 7
  • 28

1 Answers1

0

Although I can't test this without the file, the following should allow you to read that data structure:

import numpy as np
import uproot

dtype = np.dtype([("x", ">f4", (15, 2)), ("y", ">f4", (15, 2))])
interpretation = uproot.asdtype(dtype)
points_array = tree["point"].array(interpretation)

It is a problem that Uproot is not recognizing this structure, though I can imagine why not: it's a special case (fixed-size dimensions) of a special case (leaf-list). If you could post a small (< 1 MB) example file as an Uproot GitHub issue, I'll look into the problem of automatically identifying this interpretation.

Jim Pivarski
  • 5,568
  • 2
  • 35
  • 47