ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
EventSelectionAlgorithms
python
EventSelectionConfigTestSupport.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
"""Shared harness for the EventSelectionConfig unit tests.
3
4
Each *_unitTest.py script builds a real ConfigSequence containing a single
5
EventSelectionConfig block, configures it through a real ConfigAccumulator,
6
and inspects the resulting algorithm sequence. No mocking: the accumulator
7
instantiates the real CP algorithms, so a Python/C++ property-name mismatch
8
is caught here rather than at runtime.
9
10
In a full job the object-config blocks register the input containers and their
11
selection working points upstream. In isolation we register them here:
12
* input containers -> config.setSourceName(container, container)
13
* object selection WPs -> config.addSelection(container, wp, decoration)
14
"""
15
16
from
AnaAlgorithm.AlgSequence
import
AlgSequence
17
from
AnaAlgorithm.DualUseConfig
import
isAthena
18
from
AnalysisAlgorithmsConfig.ConfigSequence
import
ConfigSequence
19
from
AnalysisAlgorithmsConfig.ConfigAccumulator
import
ConfigAccumulator, DataType
20
from
EventSelectionAlgorithms.EventSelectionConfig
import
(
21
EventSelectionConfig, EventSelectionMergerConfig,
22
)
23
24
_UNSET = object()
25
26
# Dummy object-selection working points referenced by the tests' extra-selection
27
# forms. Registered on every input container so getFullSelection resolves them.
28
_DUMMY_WPS = [
"baseline"
,
"mysel"
,
"goodjet"
,
"centraljet"
,
"topjet"
,
29
"elsel"
,
"musel"
,
"esel"
,
"msel"
,
"tsel"
]
30
31
32
def
_container
(spec):
33
"""Strip a trailing '.selection' to get the bare container name."""
34
return
spec.split(
"."
)[0]
35
36
37
def
_new_accumulator
(dataType, containers):
38
algSeq = AlgSequence()
39
config = ConfigAccumulator(dataType=dataType, algSeq=algSeq)
40
for
cont
in
{
_container
(c)
for
c
in
containers}:
41
config.setSourceName(cont, cont)
42
for
wp
in
_DUMMY_WPS:
43
# decoration string deliberately embeds the WP name so the
44
# extra-selection tests can assert on it via substring.
45
config.addSelection(cont, wp, f
"{wp}_%SYS%"
)
46
return
algSeq, config
47
48
49
def
run
(cuts, *, dataType=DataType.FullSim, containers=None,
50
selectionName="SR", **options):
51
"""Configure one EventSelectionConfig block and return its algorithms.
52
53
`containers` maps EventSelectionConfig option names to container specs,
54
e.g. {'electrons': 'AnaElectrons'} or {'jets': 'AnaJets.baseline'}.
55
"""
56
containers = containers
or
{}
57
algSeq, config =
_new_accumulator
(dataType, containers.values())
58
seq = ConfigSequence()
59
block = EventSelectionConfig()
60
block.setOptionValue(
"selectionName"
, selectionName)
61
block.setOptionValue(
"selectionCuts"
, cuts)
62
for
opt, cname
in
containers.items():
63
block.setOptionValue(opt, cname)
64
for
opt, val
in
options.items():
65
block.setOptionValue(opt, val)
66
seq.append(block)
67
68
if
isAthena:
69
try
:
70
seq.fullConfigure(config)
71
return
config.CA.getEventAlgos()
72
finally
:
73
config.CA.wasMerged()
74
75
seq.fullConfigure(config)
76
return
list(algSeq)
77
78
79
def
run_merger
(region_names, *, dataType=DataType.FullSim, noFilter=False):
80
"""Build real regions then the merger, and return the algorithm sequence.
81
82
Each region is a trivial EventSelectionConfig (a single RUN_NUMBER cut) so
83
that the merger's `EventSelection` dependency is satisfied and
84
`eventSelectionNames` is populated. The event filter is emitted implicitly
85
at the end of each block (no explicit SAVE needed).
86
"""
87
algSeq, config =
_new_accumulator
(dataType, [])
88
seq = ConfigSequence()
89
for
name
in
region_names:
90
block = EventSelectionConfig()
91
block.setOptionValue(
"selectionName"
, name)
92
block.setOptionValue(
"selectionCuts"
,
"RUN_NUMBER >= 0"
)
93
seq.append(block)
94
merger = EventSelectionMergerConfig()
95
merger._instance_number = 1
# defensive: ensure the guard runs
96
merger.setOptionValue(
"noFilter"
, noFilter)
97
seq.append(merger)
98
seq.fullConfigure(config)
99
if
isAthena:
100
algs = config.CA.getEventAlgos()
101
config.CA.wasMerged()
102
return
algs
103
return
list(algSeq)
104
105
106
def
selectors
(algs):
107
"""Selector algorithms only (exclude the SAVE filter)."""
108
return
[a
for
a
in
algs
if
a.getType() !=
"CP::SaveFilterAlg"
]
109
110
111
def
named
(algs, substr):
112
return
[a
for
a
in
algs
if
substr
in
a.getName()]
113
114
115
def
prop
(alg, name, default=_UNSET):
116
"""Read a property set on the algorithm; return `default` if unset."""
117
val = getattr(alg, name, _UNSET)
118
if
val
is
_UNSET:
119
if
default
is
_UNSET:
120
raise
AttributeError(f
"{alg.getName()} has no property {name!r}"
)
121
return
default
122
return
val
python.EventSelectionConfigTestSupport.run_merger
run_merger(region_names, *, dataType=DataType.FullSim, noFilter=False)
Definition
EventSelectionConfigTestSupport.py:79
python.EventSelectionConfigTestSupport._new_accumulator
_new_accumulator(dataType, containers)
Definition
EventSelectionConfigTestSupport.py:37
python.EventSelectionConfigTestSupport._container
_container(spec)
Definition
EventSelectionConfigTestSupport.py:32
python.EventSelectionConfigTestSupport.named
named(algs, substr)
Definition
EventSelectionConfigTestSupport.py:111
python.EventSelectionConfigTestSupport.selectors
selectors(algs)
Definition
EventSelectionConfigTestSupport.py:106
python.EventSelectionConfigTestSupport.run
run(cuts, *, dataType=DataType.FullSim, containers=None, selectionName="SR", **options)
Definition
EventSelectionConfigTestSupport.py:50
python.EventSelectionConfigTestSupport.prop
prop(alg, name, default=_UNSET)
Definition
EventSelectionConfigTestSupport.py:115
Generated on
for ATLAS Offline Software by
1.17.0