Reading ROOT file with Branches

For the sake of completeness, there was a bug in UnROOT.jl which is now fixed (in v0.10.26) and the other issue was that the full path to the branch is a little bit different (that probably needs a better documentation, it’s not the first time that people are confused).

Long story short, here is the happy end, with some fancy regex to read multiple sub-branches and return a lazy table-like instance:

julia> using UnROOT

julia> f = ROOTFile("test/samples/issue323.root")
ROOTFile with 2 entries and 27 streamers.
test/samples/issue323.root
├─ sim (TTree)
│  ├─ "info"
│  ├─ "init"
│  ├─ "track"
│  ├─ "decay"
│  ├─ "ghost"
│  ├─ "ghostface"
│  └─ "upstream"
└─ PIMCRunHeader (PIMCRunHeader)


julia> t = LazyTree(f, "sim", [r"ghost/ghost\.(.*)" => s"\1"])
 Row │ ypos             ghostID          time             stepID           fUniqueID        xmom             pd ⋯
     │ SubArray{Float3  SubArray{Int32,  SubArray{Float3  SubArray{Int32,  SubArray{UInt32  SubArray{Float3  Su ⋯
─────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────
 1   │ [982.0, 6.83]    [110000, 11000   [3230.0, 36.4]   [0, 0]           [0, 0]           [-25.6, -29.5]   [- ⋯
 2   │ [2590.0]         [110000]         [29.7]           [0]              [0]              [21.9]           [1 ⋯
 3   │ [258.0, -2230.   [110000, 11000   [774.0, 48.0]    [0, 0]           [0, 0]           [-44.3, 22.1]    [- ⋯
 4   │ [-1850.0]        [110000]         [60.6]           [0]              [0]              [14.1]           [1 ⋯
 5   │ []               []               []               []               []               []               [] ⋯
 6   │ [512.0]          [110000]         [587.0]          [0]              [0]              [-11.5]          [- ⋯
 7   │ [-11.0]          [110000]         [40.8]           [0]              [0]              [-2.61]          [2 ⋯
 8   │ [2890.0]         [110000]         [28.7]           [0]              [0]              [-8.56]          [1 ⋯
 9   │ []               []               []               []               []               []               [] ⋯
 10  │ [28.1]           [110000]         [41.0]           [0]              [0]              [-0.453]         [2 ⋯
 11  │ [2660.0]         [110000]         [799.0]          [0]              [0]              [-4.84]          [- ⋯
 12  │ [12.0]           [110000]         [41.0]           [0]              [0]              [2.28]           [2 ⋯
 13  │ [33.0]           [110000]         [41.8]           [0]              [0]              [-4.04]          [2 ⋯
 14  │ [-0.84]          [110000]         [40.5]           [0]              [0]              [-5.09]          [2 ⋯
 15  │ [664.0]          [110000]         [311.0]          [0]              [0]              [-3.08]          [1 ⋯
 16  │ []               []               []               []               []               []               [] ⋯
 17  │ [-1220.0]        [110000]         [640.0]          [0]              [0]              [7.4]            [1 ⋯
 18  │ [-2290.0, -269   [110000, 11000   [1410.0, 1410.   [0, 0, 0]        [0, 0, 0]        [0.0214, 0.01,   [2 ⋯
 19  │ [906.0]          [110000]         [8140.0]         [0]              [0]              [41.8]           [- ⋯
 20  │ [3430.0]         [110000]         [4960.0]         [0]              [0]              [-13.3]          [- ⋯
 21  │ []               []               []               []               []               []               [] ⋯
 22  │ [5.71]           [110000]         [41.0]           [0]              [0]              [6.6]            [2 ⋯
 23  │ []               []               []               []               []               []               [] ⋯
 24  │ [1330.0]         [110000]         [1250.0]         [0]              [0]              [-24.4]          [1 ⋯
 25  │ [-1050.0]        [110000]         [23.5]           [0]              [0]              [10.1]           [1 ⋯
 26  │ [-280.0, -2400   [110000, 11000   [1150.0, 39.1]   [0, 0]           [0, 0]           [0.412, -13.6]   [2 ⋯
 27  │ []               []               []               []               []               []               [] ⋯
 28  │ [-12.8]          [110000]         [1150.0]         [0]              [0]              [10.7]           [- ⋯
 29  │ [2770.0, 2080.   [110000, 11000   [1610.0, 20.5]   [0, 0]           [0, 0]           [20.8, -15.4]    [- ⋯
 30  │ [262.0, -866.0   [110000, 11000   [36.3, 35.7]     [0, 0]           [0, 0]           [-17.5, 5.21]    [1 ⋯
 31  │ []               []               []               []               []               []               [] ⋯
  ⋮  │        ⋮                ⋮                ⋮                ⋮                ⋮                ⋮            ⋱
                                                                                  7 columns and 1169 rows omitted


julia> t.time[23:42]
20-element Vector{Vector{Float32}}:
 []
 [1248.5364]
 [23.53635]
 [1154.8237, 39.09293]
 []
 [1154.2357]
 [1608.5714, 20.453718]
 [36.331398, 35.730732]
 []
 [2756.7627]
 [4619.069, 41.54856]
 [618.69916, 51.805447]
 []
 [2412.702]
 [2667.897, 2671.2146]
 [41.457493, 86.87225]
 [2779.9707]
 [2550.0178]
 [3598.2415, 30.367851]
 [2836.5977, 38.199326]

julia>
1 Like