util#

General producers that might be utilized in various places.

Classes:

attach_coffea_behavior(*args, **kwargs)

Functions:

ak_extract_fields(arr, fields, **kwargs)

Build an array containing only certain fields of an input array arr, preserving behaviors.

lv_xyzt(arr, *[, fields])

Construct a LorentzVectorArray from an input array.

lv_mass(arr, *[, fields])

Construct a PtEtaPhiMLorentzVectorArray from an input array.

lv_energy(arr, *[, fields])

Construct a PtEtaPhiELorentzVectorArray from an input array.

lv_sum(lv_arrays)

Return the sum of identically-structured arrays containing Lorentz vectors.

delta_r_match(src_lv, dst_lvs[, max_dr, ...])

Match entries in the source array src_lv to the closest entry in the destination array dst_lvs using delta-R as a metric.

delta_r_match_multiple(src_lvs, dst_lvs[, ...])

Like delta_r_match, except source array src_lvs can contain more than one entry per event.

class attach_coffea_behavior(*args, **kwargs)[source]#

Bases: Producer

Attributes:

Methods:

call_func(events[, collections])

Add coffea's NanoEvents behavior to collections.

skip_func(**kwargs)

update_cls_dict(cls_name, cls_dict, get_attr)

cache_instances = True#
call_force = True#
call_func(events, collections=None, **kwargs)#

Add coffea’s NanoEvents behavior to collections.

This might become relevant in case some of the collections have been invalidated in a potential previous step. All information on source collection names, coffea - Columnar Object Framework For Effective Analysis type names, attributes to check whether the correct behavior is already attached, and fields to potentially skip is taken from columnar_util.default_coffea_collections.

However, this information is updated by collections when it is a dict. In case it is a list, its items are interpreted as names of collections defined as keys in the default collections for which the behavior should be attached.

Parameters:
  • events (Array) – Array containing the events

  • collections (Union[dict, Sequence, None], default: None) – Attach behavior for these collections. Defaults to columnar_util.default_coffea_collections.

Return type:

Array

Returns:

Array with correct behavior attached for collections

data_only = False#
mc_only = False#
skip_func(**kwargs) bool#
Return type:

bool

static update_cls_dict(cls_name, cls_dict, get_attr)#
ak_extract_fields(arr, fields, **kwargs)[source]#

Build an array containing only certain fields of an input array arr, preserving behaviors.

lv_xyzt(arr: ak.Array, *, fields: list[str] = ['x', 'y', 'z', 't'], **kwargs)#

Construct a LorentzVectorArray from an input array.

lv_mass(arr: ak.Array, *, fields: list[str] = ['pt', 'eta', 'phi', 'mass'], **kwargs)#

Construct a PtEtaPhiMLorentzVectorArray from an input array.

lv_energy(arr: ak.Array, *, fields: list[str] = ['pt', 'eta', 'phi', 'energy'], **kwargs)#

Construct a PtEtaPhiELorentzVectorArray from an input array.

lv_sum(lv_arrays)[source]#

Return the sum of identically-structured arrays containing Lorentz vectors.

delta_r_match(src_lv, dst_lvs, max_dr=None, as_index=False)[source]#

Match entries in the source array src_lv to the closest entry in the destination array dst_lvs using delta-R as a metric.

The array src_lv should contain a single entry per event and dst_lvs should be a list of possible matches.

The parameter max_dr optionally indicates the maximum possible delta-R value for a match (if the best possible match has a higher value, it is not considered a valid match).

Returns a tuple (best_match, dst_lvs_filtered), where best_match is an array containing either the best match in dst_lvs per event (if as_index is false), or the index to be applied to dst_lvs in order to obtain the best match (if as_index is true). The second tuple entry, dst_lvs_filtered, is a view of dst_lvs with the best matches removed, and can be used for subsequent matching.

delta_r_match_multiple(src_lvs, dst_lvs, max_dr=None, as_index=False)[source]#

Like delta_r_match, except source array src_lvs can contain more than one entry per event. The matching is done sequentially for each entry in src_lvs, with previous matches being filtered from the destination array each time to prevent double counting.