ATLAS Offline Software
Loading...
Searching...
No Matches
EventSelectionConfigChaining_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"""Cross-cut behaviour: preselection chaining, EVENTFLAG, GLOBALTRIGMATCH,
4IMPORT, RUN_NUMBER dataType dependence, SAVE, and a debugMode smoke test."""
5
6import unittest
7from EventSelectionAlgorithms.EventSelectionConfigTestSupport import run, selectors, named, prop, DataType
8
9
10class TestPreselectionChaining(unittest.TestCase):
12 algs = selectors(run("EL_N 25000 >= 1\nJET_N 30000 >= 2\nMET > 30000",
13 containers={"electrons": "AnaElectrons", "jets": "AnaJets", "met": "AnaMET"}))
14 el = named(algs, "NEL")[0]
15 jet = named(algs, "NJET")[0]
16 met = named(algs, "MET")[0]
17 self.assertEqual(prop(el, "eventPreselection", ""), "")
18 self.assertIn("NEL_1", prop(jet, "eventPreselection"))
19 self.assertIn("NJET_2", prop(met, "eventPreselection"))
20
22 algs = named(run("JET_N 30000 >= 2", containers={"jets": "AnaJets"},
23 preselection="pass_common_%SYS%"), "NJET")
24 self.assertIn("pass_common", prop(algs[0], "eventPreselection"))
25
26
27class TestFlags(unittest.TestCase):
29 algs = named(run("EVENTFLAG mytrigger_%SYS%\nJET_N 30000 >= 2",
30 containers={"jets": "AnaJets"}), "NJET")
31 self.assertIn("mytrigger", prop(algs[0], "eventPreselection"))
32
34 algs = named(run("GLOBALTRIGMATCH\nJET_N 30000 >= 2",
35 containers={"jets": "AnaJets"}), "NJET")
36 self.assertIn("globalTriggerMatch", prop(algs[0], "eventPreselection"))
37
39 algs = named(run("GLOBALTRIGMATCH _LooseID\nJET_N 30000 >= 2",
40 containers={"jets": "AnaJets"}), "NJET")
41 self.assertIn("globalTriggerMatch_LooseID", prop(algs[0], "eventPreselection"))
42
44 algs = named(run("IMPORT presel\nJET_N 30000 >= 2",
45 containers={"jets": "AnaJets"}), "NJET")
46 self.assertIn("pass_presel", prop(algs[0], "eventPreselection"))
47
48
49class TestRunNumber(unittest.TestCase):
51 for dt, expected in [(DataType.Data, False), (DataType.FullSim, True)]:
52 with self.subTest(dataType=dt):
53 algs = named(run("RUN_NUMBER >= 300000", dataType=dt), "RUN_NUMBER")
54 self.assertEqual(prop(algs[0], "useRandomRunNumber"), expected)
55
56 def test_properties(self):
57 algs = named(run("RUN_NUMBER >= 300000"), "RUN_NUMBER")
58 self.assertEqual(prop(algs[0], "sign"), "GE")
59 self.assertEqual(prop(algs[0], "runNumber"), 300000)
60
61
62class TestSave(unittest.TestCase):
64 # the event filter is now created automatically at the end of a block
65 algs = run("EL_N 25000 >= 1", containers={"electrons": "AnaElectrons"})
66 save = [a for a in algs if a.getType() == "CP::SaveFilterAlg"]
67 self.assertEqual(len(save), 1)
68 self.assertEqual(prop(save[0], "selectionName"), "pass_SR_%SYS%,as_char")
69 self.assertEqual(prop(save[0], "decorationName"), "ntuplepass_SR_%SYS%")
70 self.assertTrue(prop(save[0], "noFilter"))
71
73 with self.assertWarns(FutureWarning):
74 algs = run("EL_N 25000 >= 1\nSAVE", containers={"electrons": "AnaElectrons"})
75 save = [a for a in algs if a.getType() == "CP::SaveFilterAlg"]
76 self.assertEqual(len(save), 1) # not doubled by the implicit one
77
79 self.assertRaises(ValueError, run, "EL_N 25000 >= 1\nSAVE now",
80 containers={"electrons": "AnaElectrons"})
81
82
83class TestDebugMode(unittest.TestCase):
85 # debugMode registers a per-cut output branch; here we assert it does not
86 # perturb the selector algorithms or raise during configuration.
87 algs = selectors(run("JET_N 30000 >= 2", containers={"jets": "AnaJets"}, debugMode=True))
88 self.assertEqual(len(named(algs, "NJET")), 1)
89
90
91if __name__ == "__main__":
92 unittest.main()
int run(int argc, char *argv[])