PyROOT changed handling of multidimensional branches between ROOT 6.32 and 6.34


ROOT Version: 6.32.08 and 6.34.04
Platform: Linux
Compiler: Not Provided


Hi experts,

I noticed a difference in how PyROOT exposes multidimensional arrays in TTrees between ROOT 6.32.x and ROOT 6.34.x.

In old version (ROOT 6.32.08), multidimensional branches are flattened automatically, while in ROOT 6.34.04 the same branches are exposed as true multidimensional.

For example, consider the branch Kappa[4][64][2][2]/F. Accessing the first value differs between ROOT versions, requiring two different approaches:

import ROOT

root_file_path = "tileCalibLAS_310666_Las.0.root"

f = ROOT.TFile.Open(root_file_path)

t = f.Get("h3000")

t.GetEntry(0) 

try:

    first_val = t.Kappa[0][0][0][0]

    print("First element (multidim):", first_val)

except TypeError:

    first_val = t.Kappa[0]

    print("First element (flattened):", first_val)

Was this change intentional in PyROOT 6.34.x?

Hello @adurica,

this looks to be a fix of this issue:

@ajomy, does this make sense?

Hi @StephanH, sorry but I can not see how this fix the issue.

I am not working with numpy array, but with c++ arrays.

The problem is that in old version PyRoot flattened array automatically so Kappa[4][64][2][2]/f behaves like Kappa[1024]. So after print(type(t.Kappa[0])) I am getting <class 'float'>

Using new version (also ROOT 6.36.+), I am getting <class ‘cppyy.LowLevelView’>

I am just curious whether this change is expected. In newer ROOT versions, are multidimensional branches intentionally exposed as multidimensional arrays in PyROOT instead of flattened arrays?