ATLAS Offline Software
Loading...
Searching...
No Matches
EventSelectionConfigDilepton_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 dilepton/charge selectors: MLL, MLLWINDOW, MLL_OSSF, OS, SS,
4including reco-vs-truth container routing."""
5
6import unittest
7from EventSelectionAlgorithms.EventSelectionConfigTestSupport import run, named, prop
8
9ELMU = {"electrons": "AnaElectrons", "muons": "AnaMuons"}
10
11
12class TestMLL(unittest.TestCase):
13 def test_mll(self):
14 algs = named(run("MLL > 80000", containers=ELMU), "MLL_")
15 self.assertEqual(len(algs), 1)
16 self.assertEqual(algs[0].getType(), "CP::DileptonInvariantMassSelectorAlg")
17 self.assertEqual(prop(algs[0], "sign"), "GT")
18 self.assertEqual(prop(algs[0], "refMLL"), 80000.0)
19
21 self.assertRaises(ValueError, run, "MLL > 80000")
22
23
24class TestMLLWindow(unittest.TestCase):
25 def test_window(self):
26 algs = named(run("MLLWINDOW 80000 100000", containers=ELMU), "MLLWINDOW")
27 self.assertEqual(algs[0].getType(), "CP::DileptonInvariantMassWindowSelectorAlg")
28 self.assertEqual(prop(algs[0], "lowMLL"), 80000.0)
29 self.assertEqual(prop(algs[0], "highMLL"), 100000.0)
30 self.assertFalse(prop(algs[0], "vetoMode", False))
31
32 def test_veto(self):
33 algs = named(run("MLLWINDOW 80000 100000 veto", containers=ELMU), "MLLWINDOW")
34 self.assertTrue(prop(algs[0], "vetoMode"))
35
36
37class TestMLLOSSF(unittest.TestCase):
38 def test_ossf(self):
39 algs = named(run("MLL_OSSF 80000 100000", containers=ELMU), "MLL_OSSF")
40 self.assertEqual(algs[0].getType(), "CP::DileptonOSSFInvariantMassWindowSelectorAlg")
41 self.assertEqual(prop(algs[0], "lowMll"), 80000.0)
42 self.assertEqual(prop(algs[0], "highMll"), 100000.0)
43 self.assertFalse(prop(algs[0], "vetoMode", False))
44
45 def test_veto(self):
46 algs = named(run("MLL_OSSF 80000 100000 veto", containers=ELMU), "MLL_OSSF")
47 self.assertTrue(prop(algs[0], "vetoMode"))
48
50 algs = named(run("MLL_OSSF 80000 100000",
51 containers={"electrons": "AnaTruthElectrons", "muons": "AnaTruthMuons"}), "MLL_OSSF")
52 # truth containers must populate the truth* handles, not the reco ones
53 self.assertNotEqual(prop(algs[0], "truthElectrons", ""), "")
54 self.assertNotEqual(prop(algs[0], "truthMuons", ""), "")
55
56
57class TestCharge(unittest.TestCase):
58 def test_os_ss(self):
59 for kw, osmode in [("OS", True), ("SS", False)]:
60 with self.subTest(kw=kw):
61 algs = named(run(kw, containers=ELMU), f"_{kw}_")
62 self.assertEqual(algs[0].getType(), "CP::ChargeSelectorAlg")
63 self.assertEqual(prop(algs[0], "OS"), osmode)
64
66 algs = named(run("OS", containers={"electrons": "AnaTruthElectrons"}), "_OS_")
67 self.assertNotEqual(prop(algs[0], "truthElectrons", ""), "")
68
70 self.assertRaises(ValueError, run, "OS")
71
73 # "OS el" restricts the charge computation to electrons only
74 algs = named(run("OS el", containers=ELMU), "_OS_")
75 self.assertNotEqual(prop(algs[0], "electrons", ""), "")
76 self.assertEqual(prop(algs[0], "muons", ""), "")
77
78
79if __name__ == "__main__":
80 unittest.main()
int run(int argc, char *argv[])