-
Notifications
You must be signed in to change notification settings - Fork 9
Trigger Object Matching
The script imports various modules and functions for array manipulation and data processing:
from typing import Optional
from columnflow.selection import Selector, SelectionResult, selector
from columnflow.util import maybe_import
from columnflow.columnar_util import set_ak_column
from httcp.util import trigger_object_matching
np = maybe_import("numpy")
ak = maybe_import("awkward")
The hlt_path_fired
function processes a dictionary of High-Level Trigger (HLT) conditions to determine which path has fired by storing the related trigger ID.
It pads and fills missing values to make arrays broadcastable.
-
dictionary
(dict): A dictionary where keys are trigger names and values are lists of trigger IDs.
Returns an Awkward Array with the highest trigger IDs that fired for each event.
The function performs the following steps:
- Calculates the maximum length of the entries in the dictionary to pad shorter entries.
- Pads and fills the entries in the dictionary to ensure they are all the same length.
- Combines the padded entries to determine which triggers have fired.
def hlt_path_fired(dictionary):
if len(dictionary) > 0:
max_length = 0
for key in dictionary.keys():
if max_length < max(len(entry) for entry in dictionary[key]):
max_length = max(len(entry) for entry in dictionary[key])
hlt_condition = {}
for key in dictionary.keys():
print(key, dictionary[key])
hlt_condition[key] = ak.pad_none(dictionary[key], target=max_length)
hlt_condition[key] = ak.fill_none(hlt_condition[key], -1)
print(key, hlt_condition[key])
hlt_trig = list(hlt_condition.values())[0]
i = 0
while i < len(dictionary) - 1:
hlt_trig = ak.where(list(hlt_condition.values())[i + 1] > list(hlt_condition.values())[i],
list(hlt_condition.values())[i + 1],
list(hlt_condition.values())[i])
print(hlt_trig)
i += 1
HLT_path_fired = hlt_trig
else:
print("No trigger matched for this path or no such trigger required")
HLT_path_fired = ak.Array([])
return HLT_path_fired
Here's an example of how to use the hlt_path_fired
function:
trigger_dict = {
"hlt_path_1": [[201, 201], [201], []],
"hlt_path_2": [[202], [], [202]]
}
hlt_fired = hlt_path_fired(trigger_dict)
hlt_fired = ak.Array([202,201],[201],[202])
The HLT paths follow an hierarchy in which the higher is the triggerID the better is the more relevant is the HLT path reletated to it.
The hierarchy is the following: first Single Object HLT triggers, and then Cross Object HLT triggers.
The match_trigobj
function is a decorated selector function that matches trigger objects with events and determines which triggers are fired based on given criteria.
The function is decorated with @selector
, specifying the data it uses and produces:
@selector(
uses={
"Electron.pt", "Electron.eta", "Electron.phi", "Electron.mass",
"Muon.pt", "Muon.eta", "Muon.phi", "Muon.mass",
"Tau.pt", "Tau.eta", "Tau.phi", "Tau.mass",
"TrigObj.pt", "TrigObj.eta", "TrigObj.phi",
},
produces={
"single_electron_triggered", "cross_electron_triggered",
"single_muon_triggered", "cross_muon_triggered",
"cross_tau_triggered",
},
exposed=False
)
-
self
(Selector): The selector instance. -
events
(ak.Array): An array of event data. -
trigger_results
(SelectionResult): Results from trigger selection. -
electron_indices
(ak.Array): Indices of selected electrons. -
muon_indices
(ak.Array): Indices of selected muons. -
tau_indices
(ak.Array): Indices of selected taus. -
domatch
: A boolean flag indicating whether to perform matching. -
**kwargs
: Additional arguments.
Returns an updated events array and selected indices for electrons, muons, and taus.
The function performs the following steps:
- Initializes output vectors with false masks.
- Initializes dummy arrays for electron, muon, and tau indices.
- If
domatch
is True, it processes each trigger separately, matching objects and updating trigger conditions. - Uses the
hlt_path_fired
function to determine which triggers are fired for electrons, muons, and taus. - Sets matched indices and trigger IDs for the selected objects.
- Updates event arrays with the selected indices and trigger conditions.