22class TestFeiConfiguration(unittest.TestCase):
24 def test_Defaults(self):
25 config = fei.config.FeiConfiguration()
26 self.assertEqual(config.prefix,
'FEI_TEST')
27 self.assertEqual(config.cache,
None)
28 self.assertEqual(config.monitor,
True)
29 self.assertEqual(config.legacy,
None)
30 self.assertEqual(config.externTeacher,
'basf2_mva_teacher')
31 self.assertEqual(config.training,
False)
34class TestMVAConfiguration(unittest.TestCase):
36 def test_Defaults(self):
37 config = fei.config.MVAConfiguration()
38 self.assertEqual(config.method,
'FastBDT')
39 self.assertEqual(config.config,
'--nTrees 400 --nCutLevels 10 --nLevels 3 --shrinkage 0.1 --randRatio 0.5')
41 self.assertEqual(config.variables,
None)
42 self.assertEqual(config.target,
'isSignal')
43 self.assertEqual(config.sPlotVariable,
None)
46class TestPreCutConfiguration(unittest.TestCase):
48 def test_Defaults(self):
49 config = fei.config.PreCutConfiguration()
50 self.assertEqual(config.userCut,
'')
51 self.assertEqual(config.vertexCut, -2)
52 self.assertEqual(config.bestCandidateVariable,
None)
53 self.assertEqual(config.bestCandidateCut, 0)
54 self.assertEqual(config.bestCandidateMode,
'lowest')
57class TestPostCutConfiguration(unittest.TestCase):
59 def test_Defaults(self):
60 config = fei.config.PostCutConfiguration()
61 self.assertEqual(config.value, 0.0)
62 self.assertEqual(config.bestCandidateCut, 0)
65class TestDecayChannel(unittest.TestCase):
67 def test_Defaults(self):
68 channel = fei.config.DecayChannel(name=
'D0:23', label=
'D0 ==> K- pi+',
69 decayString=
'D0:23 -> K- pi+', daughters=[
'K-',
'pi+'],
70 mvaConfig=fei.config.MVAConfiguration(variables=[
'E']),
71 preCutConfig=fei.config.PreCutConfiguration(userCut=
'test'),
73 self.assertEqual(channel.name,
'D0:23')
74 self.assertEqual(channel.label,
'D0 ==> K- pi+')
75 self.assertEqual(channel.decayString,
'D0:23 -> K- pi+')
76 self.assertEqual(channel.daughters, [
'K-',
'pi+'])
77 self.assertEqual(channel.mvaConfig, fei.config.MVAConfiguration(variables=[
'E']))
78 self.assertEqual(channel.preCutConfig, fei.config.PreCutConfiguration(userCut=
'test'))
79 self.assertEqual(channel.decayModeID, 23)
82class TestParticle(unittest.TestCase):
84 def test_Defaults(self):
85 mvaConfig = fei.config.MVAConfiguration(variables=[
'E'])
86 preCutConfig = fei.config.PreCutConfiguration()
87 postCutConfig = fei.config.PostCutConfiguration()
88 particle = fei.config.Particle(
'D0', mvaConfig)
90 self.assertEqual(particle.identifier,
'D0:generic')
91 self.assertEqual(particle.name,
'D0')
92 self.assertEqual(particle.label,
'generic')
93 self.assertEqual(particle.mvaConfig, mvaConfig)
94 self.assertEqual(particle.preCutConfig, preCutConfig)
95 self.assertEqual(particle.postCutConfig, postCutConfig)
96 self.assertListEqual(particle.channels, [])
97 self.assertListEqual(particle.daughters, [])
99 def test_NonDefaults(self):
100 mvaConfig = fei.config.MVAConfiguration(variables=[
'E'])
101 preCutConfig = fei.config.PreCutConfiguration(userCut=
'test')
102 postCutConfig = fei.config.PostCutConfiguration(value=0.1)
103 particle = fei.config.Particle(
'D0', mvaConfig, preCutConfig, postCutConfig)
105 self.assertEqual(particle.identifier,
'D0:generic')
106 self.assertEqual(particle.name,
'D0')
107 self.assertEqual(particle.label,
'generic')
108 self.assertEqual(particle.mvaConfig, mvaConfig)
109 self.assertEqual(particle.preCutConfig, preCutConfig)
110 self.assertEqual(particle.postCutConfig, postCutConfig)
111 self.assertListEqual(particle.channels, [])
112 self.assertListEqual(particle.daughters, [])
114 def test_Label(self):
115 mvaConfig = fei.config.MVAConfiguration(variables=[
'E'])
116 particle = fei.config.Particle(
'D0:specific', mvaConfig)
117 self.assertEqual(particle.identifier,
'D0:specific')
118 self.assertEqual(particle.name,
'D0')
119 self.assertEqual(particle.label,
'specific')
121 def test_Equality(self):
122 a = fei.config.Particle(
'D0', fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)',
'daughterAngle({}, {})']),
123 fei.config.PreCutConfiguration(userCut=
'test'), fei.config.PostCutConfiguration())
124 a.addChannel([
'pi-',
'pi+'], mvaConfig=fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)']))
125 a.addChannel([
'K-',
'pi+'], preCutConfig=fei.config.PreCutConfiguration(userCut=
'alternative'))
127 b = fei.config.Particle(
'D0', fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)',
'daughterAngle({}, {})']),
128 fei.config.PreCutConfiguration(userCut=
'test'), fei.config.PostCutConfiguration())
129 b.addChannel([
'pi-',
'pi+'], mvaConfig=fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)']))
130 b.addChannel([
'K-',
'pi+'], preCutConfig=fei.config.PreCutConfiguration(userCut=
'alternative'))
131 self.assertEqual(a, b)
133 b = fei.config.Particle(
'D+', fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)',
'daughterAngle({}, {})']),
134 fei.config.PreCutConfiguration(userCut=
'test'), fei.config.PostCutConfiguration())
135 b.addChannel([
'pi-',
'pi+'], mvaConfig=fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)']))
136 b.addChannel([
'K-',
'pi+'], preCutConfig=fei.config.PreCutConfiguration(userCut=
'alternative'))
137 self.assertNotEqual(a, b)
139 b = fei.config.Particle(
'D0', fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)',
'daughterAngle({}, {})']),
140 fei.config.PreCutConfiguration(userCut=
'test'), fei.config.PostCutConfiguration())
141 b.addChannel([
'K-',
'pi+'], preCutConfig=fei.config.PreCutConfiguration(userCut=
'alternative'))
142 self.assertNotEqual(a, b)
144 b = fei.config.Particle(
'D0', fei.config.MVAConfiguration(variables=[
'daughter({}, p)',
'daughterAngle({}, {})']),
145 fei.config.PreCutConfiguration(userCut=
'test'), fei.config.PostCutConfiguration())
146 b.addChannel([
'pi-',
'pi+'], mvaConfig=fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)']))
147 b.addChannel([
'K-',
'pi+'], preCutConfig=fei.config.PreCutConfiguration(userCut=
'alternative'))
148 self.assertNotEqual(a, b)
150 b = fei.config.Particle(
'D0', fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)',
'daughterAngle({}, {})']),
151 fei.config.PreCutConfiguration(userCut=
'test'), fei.config.PostCutConfiguration())
152 b.addChannel([
'pi-',
'pi+'], mvaConfig=fei.config.MVAConfiguration(variables=[
'daughter({}, p)']))
153 b.addChannel([
'K-',
'pi+'], preCutConfig=fei.config.PreCutConfiguration(userCut=
'alternative'))
154 self.assertNotEqual(a, b)
156 b = fei.config.Particle(
'D0', fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)',
'daughterAngle({}, {})']),
157 fei.config.PreCutConfiguration(userCut=
'test'), fei.config.PostCutConfiguration())
158 b.addChannel([
'pi-',
'pi+'], mvaConfig=fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)']))
159 b.addChannel([
'K-',
'pi+'], preCutConfig=fei.config.PreCutConfiguration(userCut=
'test'))
160 self.assertNotEqual(a, b)
162 b = fei.config.Particle(
'D0', fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)',
'daughterAngle({}, {})']),
163 fei.config.PreCutConfiguration(userCut=
'test'), fei.config.PostCutConfiguration(value=0.1))
164 b.addChannel([
'pi-',
'pi+'], mvaConfig=fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)']))
165 b.addChannel([
'K-',
'pi+'], preCutConfig=fei.config.PreCutConfiguration(userCut=
'alternative'))
166 self.assertNotEqual(a, b)
168 b = fei.config.Particle(
'D0', fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)',
'daughterAngle({}, {})']),
169 fei.config.PreCutConfiguration(userCut=
'dummy'), fei.config.PostCutConfiguration())
170 b.addChannel([
'pi-',
'pi+'], mvaConfig=fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)']))
171 b.addChannel([
'K-',
'pi+'], preCutConfig=fei.config.PreCutConfiguration(userCut=
'alternative'))
172 self.assertNotEqual(a, b)
174 def test_AddChannel(self):
175 mvaConfig = fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)',
'daughterAngle({}, {})'])
176 preCutConfig = fei.config.PreCutConfiguration(userCut=
'test')
177 postCutConfig = fei.config.PostCutConfiguration()
178 particle = fei.config.Particle(
'D0', mvaConfig, preCutConfig, postCutConfig)
180 particle.addChannel([
'pi-',
'pi+'], mvaConfig=fei.config.MVAConfiguration(variables=[
'E',
'daughter({}, p)']))
181 particle.addChannel([
'K-',
'pi+'], preCutConfig=fei.config.PreCutConfiguration(userCut=
'alternative'))
182 particle.addChannel([
'K-:specific',
'pi+',
'pi0'])
183 particle.addChannel([
'K-',
'K+'])
186 channels.append(fei.config.DecayChannel(name=
'D0:generic_0',
187 label=
'D0:generic ==> pi-:generic pi+:generic',
188 decayString=
'D0:generic_0 -> pi-:generic pi+:generic',
189 daughters=[
'pi-:generic',
'pi+:generic'],
190 mvaConfig=fei.config.MVAConfiguration(variables=[
'E',
193 preCutConfig=fei.config.PreCutConfiguration(userCut=
'test'),
195 channels.append(fei.config.DecayChannel(name=
'D0:generic_1',
196 label=
'D0:generic ==> K-:generic pi+:generic',
197 decayString=
'D0:generic_1 -> K-:generic pi+:generic',
198 daughters=[
'K-:generic',
'pi+:generic'],
199 mvaConfig=fei.config.MVAConfiguration(variables=[
'E',
202 'daughterAngle(0, 1)']),
203 preCutConfig=fei.config.PreCutConfiguration(userCut=
'alternative'),
205 channels.append(fei.config.DecayChannel(name=
'D0:generic_2',
206 label=
'D0:generic ==> K-:specific pi+:generic pi0:generic',
207 decayString=
'D0:generic_2 -> K-:specific pi+:generic pi0:generic',
208 daughters=[
'K-:specific',
'pi+:generic',
'pi0:generic'],
209 mvaConfig=fei.config.MVAConfiguration(variables=[
'E',
213 'daughterAngle(0, 1)',
214 'daughterAngle(0, 2)',
215 'daughterAngle(1, 2)']),
216 preCutConfig=fei.config.PreCutConfiguration(userCut=
'test'),
218 channels.append(fei.config.DecayChannel(name=
'D0:generic_3',
219 label=
'D0:generic ==> K-:generic K+:generic',
220 decayString=
'D0:generic_3 -> K-:generic K+:generic',
221 daughters=[
'K-:generic',
'K+:generic'],
222 mvaConfig=fei.config.MVAConfiguration(variables=[
'E',
225 'daughterAngle(0, 1)']),
226 preCutConfig=fei.config.PreCutConfiguration(userCut=
'test'),
228 self.assertEqual(particle.channels, channels)
229 self.assertEqual(sorted(particle.daughters), sorted([
'K+:generic',
'K-:generic',
'pi+:generic',
230 'pi-:generic',
'pi0:generic',
'K-:specific']))
233class TestVariables2MonitoringBinning(unittest.TestCase):
235 def test_Variables2MonitoringBinning1D(self):
236 self.assertEqual(fei.config.variables2binnings([
'mcErrors']), [(
'mcErrors', 513, -0.5, 512.5)])
237 self.assertEqual(fei.config.variables2binnings([
'default']), [(
'default', 100, -10.0, 10.0)])
239 def test_Variables2MonitoringBinning2D(self):
240 self.assertEqual(fei.config.variables2binnings_2d([(
'mcErrors',
'default')]),
241 [(
'mcErrors', 513, -0.5, 512.5,
'default', 100, -10.0, 10.0)])
242 self.assertEqual(fei.config.variables2binnings_2d([(
'default',
'default'), (
'mcErrors',
'mcErrors')]),
243 [(
'default', 100, -10.0, 10.0,
'default', 100, -10.0, 10.0),
244 (
'mcErrors', 513, -0.5, 512.5,
'mcErrors', 513, -0.5, 512.5)])
247if __name__ ==
'__main__':
248 tempdir = tempfile.mkdtemp()
251 atexit.register(shutil.rmtree, tempdir)