ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
EventSelectionAlgorithms
python
EventSelectionConfigEventVar_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 EVENTVAR keyword: cut on an EventInfo scalar decoration
4
(e.g. a DNN/BDT discriminant) with a configurable stored type.
5
6
Formalism: EVENTVAR <type> <varname> <sign> <threshold>, where <varname> is
7
bare and the '_%SYS%' suffix is appended by the configuration."""
8
9
import
unittest
10
from
EventSelectionAlgorithms.EventSelectionConfigTestSupport
import
run, named, prop
11
12
13
class
TestEventVar
(unittest.TestCase):
14
def
test_float_default
(self):
15
alg = named(
run
(
"EVENTVAR float dnn_score > 0.5"
),
"EVENTVAR"
)[0]
16
self.assertEqual(alg.getType(),
"CP::EventScalarSelectorAlg"
)
17
self.assertEqual(prop(alg,
"floatVariable"
),
"dnn_score_%SYS%"
)
18
self.assertEqual(prop(alg,
"sign"
),
"GT"
)
19
self.assertEqual(prop(alg,
"refValue"
), 0.5)
20
21
def
test_explicit_int
(self):
22
alg = named(
run
(
"EVENTVAR int n_jets >= 5"
),
"EVENTVAR"
)[0]
23
self.assertEqual(prop(alg,
"intVariable"
),
"n_jets_%SYS%"
)
24
self.assertEqual(prop(alg,
"floatVariable"
,
""
),
""
)
25
self.assertEqual(prop(alg,
"sign"
),
"GE"
)
26
27
def
test_explicit_double
(self):
28
alg = named(
run
(
"EVENTVAR double ht > 300000.0"
),
"EVENTVAR"
)[0]
29
self.assertEqual(prop(alg,
"doubleVariable"
),
"ht_%SYS%"
)
30
31
def
test_negative_threshold
(self):
32
alg = named(
run
(
"EVENTVAR float bdt_score > -0.2"
),
"EVENTVAR"
)[0]
33
self.assertEqual(prop(alg,
"floatVariable"
),
"bdt_score_%SYS%"
)
34
self.assertEqual(prop(alg,
"refValue"
), -0.2)
35
36
def
test_all_signs
(self):
37
for
sym, enum
in
[(
"<"
,
"LT"
), (
">"
,
"GT"
), (
"=="
,
"EQ"
), (
">="
,
"GE"
), (
"<="
,
"LE"
)]:
38
with
self.subTest(sign=sym):
39
alg = named(
run
(f
"EVENTVAR float score {sym} 0.5"
),
"EVENTVAR"
)[0]
40
self.assertEqual(prop(alg,
"sign"
), enum)
41
42
def
test_bad_type_raises
(self):
43
self.assertRaises(ValueError, run,
"EVENTVAR complex score > 0.5"
)
44
45
def
test_bad_argcount_raises
(self):
46
self.assertRaises(ValueError, run,
"EVENTVAR float score > 0.5 extra"
)
47
self.assertRaises(ValueError, run,
"EVENTVAR score > 0.5"
)
48
49
def
test_chains_after_other_cuts
(self):
50
algs =
run
(
"JET_N 30000 >= 2\nEVENTVAR float dnn > 0.8"
,
51
containers={
"jets"
:
"AnaJets"
})
52
ev = [a
for
a
in
algs
if
a.getType() ==
"CP::EventScalarSelectorAlg"
][0]
53
self.assertIn(
"NJET_1"
, prop(ev,
"eventPreselection"
))
54
55
56
if
__name__ ==
"__main__"
:
57
unittest.main()
python.EventSelectionConfigEventVar_unitTest.TestEventVar
Definition
EventSelectionConfigEventVar_unitTest.py:13
python.EventSelectionConfigEventVar_unitTest.TestEventVar.test_explicit_int
test_explicit_int(self)
Definition
EventSelectionConfigEventVar_unitTest.py:21
python.EventSelectionConfigEventVar_unitTest.TestEventVar.test_float_default
test_float_default(self)
Definition
EventSelectionConfigEventVar_unitTest.py:14
python.EventSelectionConfigEventVar_unitTest.TestEventVar.test_negative_threshold
test_negative_threshold(self)
Definition
EventSelectionConfigEventVar_unitTest.py:31
python.EventSelectionConfigEventVar_unitTest.TestEventVar.test_bad_argcount_raises
test_bad_argcount_raises(self)
Definition
EventSelectionConfigEventVar_unitTest.py:45
python.EventSelectionConfigEventVar_unitTest.TestEventVar.test_bad_type_raises
test_bad_type_raises(self)
Definition
EventSelectionConfigEventVar_unitTest.py:42
python.EventSelectionConfigEventVar_unitTest.TestEventVar.test_chains_after_other_cuts
test_chains_after_other_cuts(self)
Definition
EventSelectionConfigEventVar_unitTest.py:49
python.EventSelectionConfigEventVar_unitTest.TestEventVar.test_explicit_double
test_explicit_double(self)
Definition
EventSelectionConfigEventVar_unitTest.py:27
python.EventSelectionConfigEventVar_unitTest.TestEventVar.test_all_signs
test_all_signs(self)
Definition
EventSelectionConfigEventVar_unitTest.py:36
run
int run(int argc, char *argv[])
Definition
ttree2hdf5.cxx:28
Generated on
for ATLAS Offline Software by
1.17.0