Skip to content

best_track fails for tracks slices

Let's open a fresh issue 😆

It works for "single events" but fails when additional slicing/masking is present:

[ins] In [15]: import km3io; from km3net_testdata import data_path                                                    

[ins] In [16]: r = km3io.OfflineReader(data_path("offline/mcv5.11r2.gsg_muonCChigherE-CC_50-5000GeV.km3_AAv1.jterbr000
          ...: 04695.jchain.aanet.498.root"))                                                                         

[ins] In [17]: tracks = r.events.tracks[0]                                                                            

[ins] In [18]: km3io.tools.best_track(tracks, rec_type="JPP_RECONSTRUCTION_TYPE")                                     
Out[18]: <OfflineBranch[tracks]: 1 element>

[ins] In [19]: tracks = tracks[tracks.rec_type == 4000]                                                               

[ins] In [20]: km3io.tools.best_track(tracks, rec_type="JPP_RECONSTRUCTION_TYPE")                                     
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-20-fee7ec2d561a> in <module>
----> 1 km3io.tools.best_track(tracks, rec_type="JPP_RECONSTRUCTION_TYPE")

~/Dev/km3pipe/venv/lib/python3.8/site-packages/km3io/tools.py in best_track(tracks, strategy, rec_type)
    305     n_events = 1 if tracks.is_single else len(tracks)
    306 
--> 307     if n_events > 1 and any(count_nested(tracks.lik, axis=1) == 0):
    308         raise ValueError(
    309             "'events' should not contain empty tracks. Consider applying the mask: events.n_tracks>0"

~/Dev/km3pipe/venv/lib/python3.8/site-packages/km3io/tools.py in count_nested(Array, axis)
    212         return ak1.num(Array, axis=0)
    213     if axis == 1:
--> 214         return ak1.num(Array, axis=1)
    215     if axis == 2:
    216         return ak1.count(Array, axis=2)

~/Dev/km3pipe/venv/lib/python3.8/site-packages/awkward1/operations/structure.py in num(array, axis, highlevel)
    201         array, allow_record=False, allow_other=False
    202     )
--> 203     out = layout.num(axis=axis)
    204     if highlevel:
    205         return awkward1._util.wrap(out, behavior=awkward1._util.behaviorof(array))

ValueError: 'axis' out of range for 'num'

(https://github.com/scikit-hep/awkward-1.0/blob/0.3.1/src/libawkward/array/NumpyArray.cpp#L1338)