ATLAS Offline Software
Loading...
Searching...
No Matches
python.tool.Tool Class Reference
Collaboration diagram for python.tool.Tool:

Public Member Functions

 __init__ (self, type_and_name, properties=None, rename_containers=None)
 properties (self)
 columns (self)
 input_columns (self)
 output_columns (self)
 recommended_systematics (self)
 apply_systematic_variation (self, sys_name)
 __call__ (self, events, systematic=None)

Protected Attributes

 _handle = PythonToolHandle()
 _properties = dict(properties) if properties else {}
 _classified = classify_columns(self._handle.columns)

Detailed Description

High-level wrapper around PythonToolHandle.

Handles the boilerplate of classifying columns, extracting awkward-array
buffers, allocating outputs, setting columns on the handle, calling the
tool, and reconstructing the output awkward array.

Parameters
----------
type_and_name:
    Tool type and instance name, e.g. "CP::MuonEfficiencyScaleFactors/myTool".
properties:
    Optional dict of tool properties to set before initialization.
rename_containers:
    Optional mapping from canonical container names (e.g. "Muons") to the
    branch-name prefix used in the input arrays (e.g. "AnalysisMuonsAuxDyn").
    This is passed to PythonToolHandle.rename_containers *after* initialize
    so that ColumnInfo.name values match input array fields.

Definition at line 22 of file tool.py.

Constructor & Destructor Documentation

◆ __init__()

python.tool.Tool.__init__ ( self,
type_and_name,
properties = None,
rename_containers = None )

Definition at line 42 of file tool.py.

42 def __init__(self, type_and_name, properties=None, rename_containers=None):
43 self._handle = PythonToolHandle()
44 self._handle.set_type_and_name(type_and_name)
45 self._properties = dict(properties) if properties else {}
46
47 for key, value in self._properties.items():
48 self._handle.set_property(key, value)
49
50 self._handle.initialize()
51
52 if rename_containers:
53 self._handle.rename_containers(rename_containers)
54
55 # Cache classified column topology once after initialization
56 self._classified = classify_columns(self._handle.columns)
57
void initialize()

Member Function Documentation

◆ __call__()

python.tool.Tool.__call__ ( self,
events,
systematic = None )
Run the tool on events and return output columns as an ak.Array.

Parameters
----------
events:
    An ak.Array with fields matching the tool's input column names
    (after any rename_containers mapping).
systematic:
    Optional systematic variation name (e.g. "MUON_EFF_RECO_SYS__1up").
    If provided, applied before running the tool and reset to nominal
    after execution.

Returns
-------
ak.Array
    Record array with one field per output column, each a
    variable-length list over the per-particle values.

Definition at line 100 of file tool.py.

100 def __call__(self, events, systematic=None):
101 """Run the tool on events and return output columns as an ak.Array.
102
103 Parameters
104 ----------
105 events:
106 An ak.Array with fields matching the tool's input column names
107 (after any rename_containers mapping).
108 systematic:
109 Optional systematic variation name (e.g. "MUON_EFF_RECO_SYS__1up").
110 If provided, applied before running the tool and reset to nominal
111 after execution.
112
113 Returns
114 -------
115 ak.Array
116 Record array with one field per output column, each a
117 variable-length list over the per-particle values.
118 """
119 if systematic is not None:
120 self.apply_systematic_variation(systematic)
121
122 try:
123 num_events = int(ak.num(events, axis=0))
124
125 # Resolve optional columns against the actual fields present
126 effective = resolve_optional_columns(self._classified, events)
127
128 # Extract flat buffers from the awkward array
129 buffer_dict = extract_buffers(events, effective)
130
131 # Allocate zero-filled output arrays (added into buffer_dict in-place)
132 allocate_outputs(effective, buffer_dict)
133
134 # Set all columns on the handle
135 for container_name, info in effective.items():
136 # Container offset (always immutable)
137 self._handle[container_name] = np.asarray(buffer_dict[container_name])
138
139 # Nested-vector offsets (immutable)
140 for nested_name in info["nested_offsets"]:
141 if nested_name in buffer_dict:
142 self._handle[nested_name] = np.asarray(buffer_dict[nested_name])
143
144 # Input data columns (immutable)
145 for col in info["inputs"]:
146 self._handle[col.name] = np.asarray(buffer_dict[col.name])
147
148 # Output data columns (mutable)
149 for col in info["outputs"]:
150 self._handle.set_column_void(col.name, buffer_dict[col.name], False)
151
152 self._handle.call()
153
154 return reconstruct_output(effective, buffer_dict, num_events)
155 finally:
156 # Reset to nominal if systematic was applied
157 if systematic is not None:
158 self.apply_systematic_variation("")

◆ apply_systematic_variation()

python.tool.Tool.apply_systematic_variation ( self,
sys_name )
Apply a systematic variation by name.

Parameters
----------
sys_name:
    Systematic variation name, e.g. ``"MUON_EFF_RECO_SYS__1up"``.
    Pass ``""`` to reset to the nominal.

Definition at line 89 of file tool.py.

89 def apply_systematic_variation(self, sys_name):
90 """Apply a systematic variation by name.
91
92 Parameters
93 ----------
94 sys_name:
95 Systematic variation name, e.g. ``"MUON_EFF_RECO_SYS__1up"``.
96 Pass ``""`` to reset to the nominal.
97 """
98 self._handle.apply_systematic_variation(sys_name)
99

◆ columns()

python.tool.Tool.columns ( self)
All ColumnInfo objects reported by the tool.

Definition at line 64 of file tool.py.

64 def columns(self):
65 """All ColumnInfo objects reported by the tool."""
66 return self._handle.columns
67

◆ input_columns()

python.tool.Tool.input_columns ( self)
Input (non-offset) ColumnInfo objects.

Definition at line 69 of file tool.py.

69 def input_columns(self):
70 """Input (non-offset) ColumnInfo objects."""
71 cols = []
72 for info in self._classified.values():
73 cols.extend(info["inputs"])
74 return cols
75

◆ output_columns()

python.tool.Tool.output_columns ( self)
Output ColumnInfo objects.

Definition at line 77 of file tool.py.

77 def output_columns(self):
78 """Output ColumnInfo objects."""
79 cols = []
80 for info in self._classified.values():
81 cols.extend(info["outputs"])
82 return cols
83

◆ properties()

python.tool.Tool.properties ( self)
Dict of properties set on this tool at construction time.

Definition at line 59 of file tool.py.

59 def properties(self):
60 """Dict of properties set on this tool at construction time."""
61 return self._properties
62

◆ recommended_systematics()

python.tool.Tool.recommended_systematics ( self)
List of recommended systematic variation names.

Definition at line 85 of file tool.py.

85 def recommended_systematics(self):
86 """List of recommended systematic variation names."""
87 return self._handle.get_recommended_systematics()
88

Member Data Documentation

◆ _classified

python.tool.Tool._classified = classify_columns(self._handle.columns)
protected

Definition at line 56 of file tool.py.

◆ _handle

python.tool.Tool._handle = PythonToolHandle()
protected

Definition at line 43 of file tool.py.

◆ _properties

python.tool.Tool._properties = dict(properties) if properties else {}
protected

Definition at line 45 of file tool.py.


The documentation for this class was generated from the following file: