PackedSelection
- class coffea.analysis_tools.PackedSelection(dtype='uint32')[source]
Bases:
objectStore several boolean arrays in a compact manner
This class can store several boolean arrays in a memory-efficient mannner and evaluate arbitrary combinations of boolean requirements in an CPU-efficient way. Supported inputs are 1D numpy or awkward arrays.
- Parameters:
dtype (numpy.dtype or str) – internal bitwidth of the packed array, which governs the maximum number of selections storable in this object. The default value is
uint32, which allows up to 32 booleans to be stored, but if a smaller or larger number of selections needs to be stored, one can chooseuint16oruint64instead.
Attributes Summary
Current list of mask names available
Methods Summary
add(name, selection[, fill_value])Add a new boolean array
all(*names)Shorthand for
require, where all the values are Trueany(*names)Return a mask vector corresponding to an inclusive OR of requirements
require(**names)Return a mask vector corresponding to specific requirements
Attributes Documentation
- maxitems
- names
Current list of mask names available
Methods Documentation
- add(name, selection, fill_value=False)[source]
Add a new boolean array
- Parameters:
name (str) – name of the selection
selection (numpy.ndarray or awkward.Array) – a flat array of type
boolor?bool. If this is not the first selection added, it must also have the same shape as previously added selections. If the array is option-type, null entries will be filled withfill_value.fill_value (bool, optional) – All masked entries will be filled as specified (default:
False)
- any(*names)[source]
Return a mask vector corresponding to an inclusive OR of requirements
- Parameters:
*names (args) – The named selections to allow
Examples
If
>>> selection.names ['cut1', 'cut2', 'cut3']
then
>>> selection.any("cut1", "cut2") array([True, False, True, ...])
returns a boolean array where an entry is True if the corresponding entries
cut1 == Trueorcut2 == False, andcut3arbitrary.
- require(**names)[source]
Return a mask vector corresponding to specific requirements
Specify an exact requirement on an arbitrary subset of the masks
- Parameters:
**names (kwargs) – Each argument to require specific value for, in form
arg=Trueorarg=False.
Examples
If
>>> selection.names ['cut1', 'cut2', 'cut3']
then
>>> selection.require(cut1=True, cut2=False) array([True, False, True, ...])
returns a boolean array where an entry is True if the corresponding entries
cut1 == True,cut2 == False, andcut3arbitrary.