util#

Helpful utilities often used in selections.

Functions:

sorted_indices_from_mask(mask, metric[, ...])

Takes a boolean mask and converts it to an array of indices, sorted using a metric of equal size along a sort_axis and, by default, in ascending order.

create_collections_from_masks(events, ...)

Adds new collections to an ak_array based on object_masks and returns a new view.

sorted_indices_from_mask(mask, metric, sort_axis=-1, ascending=True)[source]#

Takes a boolean mask and converts it to an array of indices, sorted using a metric of equal size along a sort_axis and, by default, in ascending order. Example:

mask = [[True, False, False, True], ...]
metric = [[5.0, 1.0, 0.9, 4.1], ...]

sorted_indices_from_mask(mask, metric)
# -> [[3, 0], ...]
Return type:

Array

create_collections_from_masks(events, object_masks)[source]#

Adds new collections to an ak_array based on object_masks and returns a new view. object_masks should be a nested dictionary such as, for instance,

{
    "Jet": {
        "BJet": ak.Array([[1, 0, 3], ...]),
        "LJet": ak.Array([2], ...),
    },
    ...
}

where outer keys refer to names of source collections and inner keys to names of collections to create by applying the corresponding mask or indices to the source collection. The example above would create two collections “BJet” and “LJet” based on the source collection “Jet”.

Return type:

ak.Array