ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
EventSelectionAlgorithms
python
EventSelectionConfigNObject_unitTest.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
"""Unit tests for the N-object pT selectors: EL_N, MU_N, JET_N, PH_N, TAU_N,
4
LJET_N, OBJ_N. All build CP::NObjectPtSelectorAlg, differing only in source."""
5
6
import
unittest
7
from
EventSelectionAlgorithms.EventSelectionConfigTestSupport
import
run, named, prop
8
9
# keyword -> (option name, container name)
10
FAMILY = {
11
"EL_N"
: (
"electrons"
,
"AnaElectrons"
),
12
"MU_N"
: (
"muons"
,
"AnaMuons"
),
13
"JET_N"
: (
"jets"
,
"AnaJets"
),
14
"PH_N"
: (
"photons"
,
"AnaPhotons"
),
15
"TAU_N"
: (
"taus"
,
"AnaTaus"
),
16
"LJET_N"
: (
"largeRjets"
,
"AnaLRJets"
),
17
}
18
TAG = {
"EL_N"
:
"NEL"
,
"MU_N"
:
"NMU"
,
"JET_N"
:
"NJET"
,
"PH_N"
:
"NPH"
,
19
"TAU_N"
:
"NTAU"
,
"LJET_N"
:
"NLJET"
}
20
21
22
class
TestNObjectMinimal
(unittest.TestCase):
23
def
test_minimal_form
(self):
24
for
kw, (opt, val)
in
FAMILY.items():
25
with
self.subTest(kw=kw):
26
algs = named(
run
(f
"{kw} 25000 >= 2"
, containers={opt: val}), TAG[kw])
27
self.assertEqual(len(algs), 1)
28
alg = algs[0]
29
self.assertEqual(alg.getType(),
"CP::NObjectPtSelectorAlg"
)
30
self.assertEqual(prop(alg,
"minPt"
), 25000.0)
31
self.assertEqual(prop(alg,
"sign"
),
"GE"
)
32
self.assertEqual(prop(alg,
"count"
), 2)
33
34
def
test_extra_selection_form
(self):
35
for
kw, (opt, val)
in
FAMILY.items():
36
with
self.subTest(kw=kw):
37
algs = named(
run
(f
"{kw} mysel 25000 >= 2"
, containers={opt: val}), TAG[kw])
38
self.assertIn(
"mysel"
, prop(algs[0],
"objectSelection"
))
39
40
def
test_extra_selection_composes_with_base
(self):
41
for
kw, (opt, val)
in
FAMILY.items():
42
with
self.subTest(kw=kw):
43
algs = named(
run
(f
"{kw} mysel 25000 >= 2"
,
44
containers={opt: f
"{val}.baseline"
}), TAG[kw])
45
sel = prop(algs[0],
"objectSelection"
)
46
self.assertIn(
"baseline"
, sel)
47
self.assertIn(
"mysel"
, sel)
48
49
def
test_all_signs
(self):
50
for
sym, enum
in
[(
"<"
,
"LT"
), (
">"
,
"GT"
), (
"=="
,
"EQ"
),
51
(
">="
,
"GE"
), (
"<="
,
"LE"
)]:
52
with
self.subTest(sign=sym):
53
algs = named(
run
(f
"JET_N 30000 {sym} 2"
, containers={
"jets"
:
"AnaJets"
}),
"NJET"
)
54
self.assertEqual(prop(algs[0],
"sign"
), enum)
55
56
57
class
TestNObjectErrors
(unittest.TestCase):
58
def
test_missing_input_raises
(self):
59
for
kw, (opt, _)
in
FAMILY.items():
60
if
kw ==
"LJET_N"
:
# no missing-input guard in the source
61
continue
62
with
self.subTest(kw=kw):
63
self.assertRaises(ValueError, run, f
"{kw} 25000 >= 2"
)
64
65
def
test_wrong_argcount_raises
(self):
66
for
kw, (opt, val)
in
FAMILY.items():
67
with
self.subTest(kw=kw):
68
self.assertRaises(ValueError, run,
69
f
"{kw} 25000 >= 2 extra junk"
, containers={opt: val})
70
71
72
class
TestObjN
(unittest.TestCase):
73
def
test_picks_container_from_argument
(self):
74
algs = named(
run
(
"OBJ_N MyContainer 30000 >= 2"
,
75
containers={
"jets"
:
"MyContainer"
}),
"NOBJ"
)
76
self.assertEqual(len(algs), 1)
77
self.assertEqual(prop(algs[0],
"minPt"
), 30000.0)
78
self.assertEqual(prop(algs[0],
"count"
), 2)
79
80
def
test_requires_five_args
(self):
81
self.assertRaises(ValueError, run,
"OBJ_N MyContainer 30000 >= 2 extra"
,
82
containers={
"jets"
:
"MyContainer"
})
83
self.assertRaises(ValueError, run,
"OBJ_N 30000 >= 2"
,
84
containers={
"jets"
:
"MyContainer"
})
85
86
87
if
__name__ ==
"__main__"
:
88
unittest.main()
python.EventSelectionConfigNObject_unitTest.TestNObjectErrors
Definition
EventSelectionConfigNObject_unitTest.py:57
python.EventSelectionConfigNObject_unitTest.TestNObjectErrors.test_wrong_argcount_raises
test_wrong_argcount_raises(self)
Definition
EventSelectionConfigNObject_unitTest.py:65
python.EventSelectionConfigNObject_unitTest.TestNObjectErrors.test_missing_input_raises
test_missing_input_raises(self)
Definition
EventSelectionConfigNObject_unitTest.py:58
python.EventSelectionConfigNObject_unitTest.TestNObjectMinimal
Definition
EventSelectionConfigNObject_unitTest.py:22
python.EventSelectionConfigNObject_unitTest.TestNObjectMinimal.test_extra_selection_composes_with_base
test_extra_selection_composes_with_base(self)
Definition
EventSelectionConfigNObject_unitTest.py:40
python.EventSelectionConfigNObject_unitTest.TestNObjectMinimal.test_minimal_form
test_minimal_form(self)
Definition
EventSelectionConfigNObject_unitTest.py:23
python.EventSelectionConfigNObject_unitTest.TestNObjectMinimal.test_extra_selection_form
test_extra_selection_form(self)
Definition
EventSelectionConfigNObject_unitTest.py:34
python.EventSelectionConfigNObject_unitTest.TestNObjectMinimal.test_all_signs
test_all_signs(self)
Definition
EventSelectionConfigNObject_unitTest.py:49
python.EventSelectionConfigNObject_unitTest.TestObjN
Definition
EventSelectionConfigNObject_unitTest.py:72
python.EventSelectionConfigNObject_unitTest.TestObjN.test_requires_five_args
test_requires_five_args(self)
Definition
EventSelectionConfigNObject_unitTest.py:80
python.EventSelectionConfigNObject_unitTest.TestObjN.test_picks_container_from_argument
test_picks_container_from_argument(self)
Definition
EventSelectionConfigNObject_unitTest.py:73
run
int run(int argc, char *argv[])
Definition
ttree2hdf5.cxx:28
Generated on
for ATLAS Offline Software by
1.17.0