ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
Algorithms
EventSelectionAlgorithms
python
EventSelectionConfigExpr_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 generic EXPR object-kinematic cuts.
4
5
The config-time validation (compatibility matrix + the two error classes) runs
6
before any algorithm is created, so the error tests pass without the C++
7
component. The happy-path tests require CP::ObjectKinematicSelectorAlg to be
8
built (they instantiate it through the real accumulator)."""
9
10
import
unittest
11
from
EventSelectionAlgorithms.EventSelectionConfigTestSupport
import
run, named, prop
12
from
EventSelectionAlgorithms.EventSelectionConfig
import
(
13
UnavailableFeatureError, InconsistentSettingsError,
14
)
15
16
ALL = dict(electrons=
"AnaElectrons"
, muons=
"AnaMuons"
, taus=
"AnaTaus"
, jets=
"AnaJets"
,
17
largeRjets=
"AnaLRJets"
, photons=
"AnaPhotons"
, met=
"AnaMET"
, btagDecoration=
"btag"
)
18
19
20
class
TestExprHappyPath
(unittest.TestCase):
21
def
test_dR
(self):
22
alg = named(
run
(
"EXPR dR(jet[0], jet[1]) < 1.0"
, containers=ALL),
"EXPR"
)[0]
23
self.assertEqual(alg.getType(),
"CP::ObjectKinematicSelectorAlg"
)
24
self.assertEqual(prop(alg,
"variable"
),
"dR"
)
25
self.assertEqual(prop(alg,
"sign"
),
"LT"
)
26
self.assertEqual(prop(alg,
"refValue"
), 1.0)
27
self.assertEqual(list(prop(alg,
"operandKinds"
)), [
"PARTICLE"
,
"PARTICLE"
])
28
self.assertEqual(list(prop(alg,
"indices"
)), [0, 1])
29
30
def
test_bjet_btag_applied
(self):
31
alg = named(
run
(
"EXPR pt(bjet[0]) > 30000"
, containers=ALL),
"EXPR"
)[0]
32
self.assertIn(
"btag"
, list(prop(alg,
"selections"
))[0])
33
34
def
test_mass_of_sum
(self):
35
alg = named(
run
(
"EXPR m(el[0]+mu[0]) > 80000"
, containers=ALL),
"EXPR"
)[0]
36
self.assertEqual(prop(alg,
"variable"
),
"m"
)
37
bare = [c.replace(
"_%SYS%"
,
""
)
for
c
in
prop(alg,
"collections"
)]
38
self.assertEqual(bare, [
"AnaElectrons"
,
"AnaMuons"
])
39
40
def
test_dphi_met
(self):
41
alg = named(
run
(
"EXPR dPhi(met, jet[0]) > 2.0"
, containers=ALL),
"EXPR"
)[0]
42
self.assertEqual(list(prop(alg,
"operandKinds"
)), [
"MET"
,
"PARTICLE"
])
43
self.assertEqual(prop(alg,
"metTerm"
),
"Final"
)
44
bare = [c.replace(
"_%SYS%"
,
""
)
for
c
in
prop(alg,
"collections"
)]
45
self.assertEqual(bare, [
"AnaJets"
])
46
47
def
test_whitespace_insensitive
(self):
48
a = named(
run
(
"EXPR dR(jet[0], jet[1]) < 1.0"
, containers=ALL),
"EXPR"
)[0]
49
b = named(
run
(
"EXPR dR(jet[0],jet[1])<1.0"
, containers=ALL),
"EXPR"
)[0]
50
self.assertEqual(prop(a,
"variable"
), prop(b,
"variable"
))
51
self.assertEqual(list(prop(a,
"indices"
)), list(prop(b,
"indices"
)))
52
53
54
class
TestExprInconsistent
(unittest.TestCase):
55
CASES = [
56
"EXPR dR(jet[0]) < 1.0"
,
57
"EXPR dR(jet[0], jet[1], jet[2]) < 1.0"
,
58
"EXPR eta(met) < 1.0"
,
59
"EXPR dR(met, jet[0]) < 1.0"
,
60
"EXPR pt(met[0]) > 30000"
,
61
"EXPR pt(met+jet[0]) > 30000"
,
62
"EXPR dR(jet[0]+jet[1]) < 1.0"
,
63
"EXPR pt(jet) > 30000"
,
64
]
65
def
test_inconsistent
(self):
66
for
line
in
self.
CASES
:
67
with
self.subTest(line=line):
68
self.assertRaises(InconsistentSettingsError, run, line, containers=ALL)
69
70
71
class
TestExprUnavailable
(unittest.TestCase):
72
def
test_unknown_variable
(self):
73
self.assertRaises(UnavailableFeatureError, run,
74
"EXPR mT2(jet[0], jet[1]) < 100000"
, containers=ALL)
75
76
def
test_unknown_collection
(self):
77
self.assertRaises(UnavailableFeatureError, run,
78
"EXPR pt(fjet[0]) > 30000"
, containers=ALL)
79
80
def
test_charge_is_deferred
(self):
81
# charge() is recognised but not yet implemented -> UnavailableFeatureError
82
self.assertRaises(UnavailableFeatureError, run,
83
"EXPR charge(el[0]) == 1"
, containers=ALL)
84
self.assertRaises(UnavailableFeatureError, run,
85
"EXPR charge(jet[0]) == 1"
, containers=ALL)
86
87
88
class
TestExprMissingInput
(unittest.TestCase):
89
def
test_missing_container
(self):
90
self.assertRaises(ValueError, run,
"EXPR pt(jet[0]) > 30000"
)
91
92
def
test_bjet_missing_btag
(self):
93
self.assertRaises(ValueError, run,
"EXPR pt(bjet[0]) > 30000"
,
94
containers={
"jets"
:
"AnaJets"
})
95
96
97
if
__name__ ==
"__main__"
:
98
unittest.main()
python.EventSelectionConfigExpr_unitTest.TestExprHappyPath
Definition
EventSelectionConfigExpr_unitTest.py:20
python.EventSelectionConfigExpr_unitTest.TestExprHappyPath.test_dphi_met
test_dphi_met(self)
Definition
EventSelectionConfigExpr_unitTest.py:40
python.EventSelectionConfigExpr_unitTest.TestExprHappyPath.test_mass_of_sum
test_mass_of_sum(self)
Definition
EventSelectionConfigExpr_unitTest.py:34
python.EventSelectionConfigExpr_unitTest.TestExprHappyPath.test_dR
test_dR(self)
Definition
EventSelectionConfigExpr_unitTest.py:21
python.EventSelectionConfigExpr_unitTest.TestExprHappyPath.test_bjet_btag_applied
test_bjet_btag_applied(self)
Definition
EventSelectionConfigExpr_unitTest.py:30
python.EventSelectionConfigExpr_unitTest.TestExprHappyPath.test_whitespace_insensitive
test_whitespace_insensitive(self)
Definition
EventSelectionConfigExpr_unitTest.py:47
python.EventSelectionConfigExpr_unitTest.TestExprInconsistent
Definition
EventSelectionConfigExpr_unitTest.py:54
python.EventSelectionConfigExpr_unitTest.TestExprInconsistent.test_inconsistent
test_inconsistent(self)
Definition
EventSelectionConfigExpr_unitTest.py:65
python.EventSelectionConfigExpr_unitTest.TestExprInconsistent.CASES
list CASES
Definition
EventSelectionConfigExpr_unitTest.py:55
python.EventSelectionConfigExpr_unitTest.TestExprMissingInput
Definition
EventSelectionConfigExpr_unitTest.py:88
python.EventSelectionConfigExpr_unitTest.TestExprMissingInput.test_bjet_missing_btag
test_bjet_missing_btag(self)
Definition
EventSelectionConfigExpr_unitTest.py:92
python.EventSelectionConfigExpr_unitTest.TestExprMissingInput.test_missing_container
test_missing_container(self)
Definition
EventSelectionConfigExpr_unitTest.py:89
python.EventSelectionConfigExpr_unitTest.TestExprUnavailable
Definition
EventSelectionConfigExpr_unitTest.py:71
python.EventSelectionConfigExpr_unitTest.TestExprUnavailable.test_unknown_variable
test_unknown_variable(self)
Definition
EventSelectionConfigExpr_unitTest.py:72
python.EventSelectionConfigExpr_unitTest.TestExprUnavailable.test_unknown_collection
test_unknown_collection(self)
Definition
EventSelectionConfigExpr_unitTest.py:76
python.EventSelectionConfigExpr_unitTest.TestExprUnavailable.test_charge_is_deferred
test_charge_is_deferred(self)
Definition
EventSelectionConfigExpr_unitTest.py:80
run
int run(int argc, char *argv[])
Definition
ttree2hdf5.cxx:28
Generated on
for ATLAS Offline Software by
1.17.0