Belle II Software development
test_fei_default_channels.py
1#!/usr/bin/env python3
2
3
10
11import unittest
12import unittest.mock
13import os
14import tempfile
15import atexit
16import shutil
17
19
20import b2bii
21
22# @cond
23
24
25class TestGetDefaultChannels(unittest.TestCase):
26 def test_get_default(self):
28 self.assertEqual([p.identifier for p in particles],
29 ['pi+:generic', 'K+:generic', 'p+:generic', 'mu+:generic', 'e+:generic', 'gamma:generic',
30 'pi0:generic', 'K_S0:generic', 'Lambda0:generic', 'Sigma+:generic', 'J/psi:generic',
31 'D0:generic', 'D+:generic', 'D_s+:generic', 'Lambda_c+:generic',
32 'D*0:generic', 'D*+:generic', 'D_s*+:generic',
33 'B0:generic', 'B+:generic',
34 'D0:semileptonic', 'D+:semileptonic', 'D*0:semileptonic', 'D*+:semileptonic',
35 'B0:semileptonic', 'B+:semileptonic'])
36
37 def test_get_hadronic(self):
38 particles = fei.default_channels.get_default_channels(hadronic=True, semileptonic=False, baryonic=False)
39 self.assertEqual([p.identifier for p in particles],
40 ['pi+:generic', 'K+:generic', 'mu+:generic', 'e+:generic', 'gamma:generic', 'pi0:generic', 'K_S0:generic',
41 'J/psi:generic', 'D0:generic', 'D+:generic', 'D_s+:generic', 'D*0:generic', 'D*+:generic',
42 'D_s*+:generic', 'B0:generic', 'B+:generic'])
43
44 def test_get_semileptonic(self):
45 particles = fei.default_channels.get_default_channels(hadronic=False, semileptonic=True, baryonic=False)
46 self.assertEqual([p.identifier for p in particles],
47 ['pi+:generic', 'K+:generic', 'mu+:generic', 'e+:generic', 'gamma:generic', 'pi0:generic', 'K_S0:generic',
48 'J/psi:generic', 'D0:generic', 'D+:generic', 'D_s+:generic', 'D*0:generic', 'D*+:generic',
49 'D_s*+:generic', 'D0:semileptonic', 'D+:semileptonic', 'D*0:semileptonic', 'D*+:semileptonic',
50 'B0:semileptonic', 'B+:semileptonic'])
51
52 def test_get_charged(self):
53 particles = fei.default_channels.get_default_channels(chargedB=True, neutralB=False, baryonic=False)
54 self.assertEqual([p.identifier for p in particles],
55 ['pi+:generic', 'K+:generic', 'mu+:generic', 'e+:generic', 'gamma:generic', 'pi0:generic', 'K_S0:generic',
56 'J/psi:generic', 'D0:generic', 'D+:generic', 'D_s+:generic', 'D*0:generic', 'D*+:generic',
57 'D_s*+:generic', 'B+:generic', 'D0:semileptonic', 'D+:semileptonic', 'D*0:semileptonic',
58 'D*+:semileptonic', 'B+:semileptonic'])
59
60 def test_get_neutral(self):
61 particles = fei.default_channels.get_default_channels(chargedB=False, neutralB=True, baryonic=False)
62 self.assertEqual([p.identifier for p in particles],
63 ['pi+:generic', 'K+:generic', 'mu+:generic', 'e+:generic', 'gamma:generic', 'pi0:generic', 'K_S0:generic',
64 'J/psi:generic', 'D0:generic', 'D+:generic', 'D_s+:generic', 'D*0:generic', 'D*+:generic',
65 'D_s*+:generic', 'B0:generic', 'D0:semileptonic', 'D+:semileptonic', 'D*0:semileptonic',
66 'D*+:semileptonic', 'B0:semileptonic'])
67
68 def test_get_klong(self):
69 particles = fei.default_channels.get_default_channels(hadronic=False, semileptonic=False, KLong=True, baryonic=False)
70 self.assertEqual([p.identifier for p in particles],
71 ['pi+:generic', 'K+:generic', 'mu+:generic', 'e+:generic', 'gamma:generic', 'pi0:generic', 'K_S0:generic',
72 'J/psi:generic', 'D0:generic', 'D+:generic', 'D_s+:generic', 'D*0:generic', 'D*+:generic',
73 'D_s*+:generic', 'K_L0:generic', 'D0:KL', 'D+:KL', 'D_s+:KL', 'D*0:KL', 'D*+:KL', 'D_s*+:KL',
74 'B0:KL', 'B+:KL'])
75
76 def test_B_extra_cut(self):
77 particles = fei.default_channels.get_default_channels(B_extra_cut='nRemainingTracksInROE == 0', KLong=True, baryonic=False)
78 self.assertEqual([p.identifier for p in particles],
79 ['pi+:generic', 'K+:generic', 'mu+:generic', 'e+:generic', 'gamma:generic', 'pi0:generic', 'K_S0:generic',
80 'J/psi:generic', 'D0:generic', 'D+:generic', 'D_s+:generic', 'D*0:generic', 'D*+:generic',
81 'D_s*+:generic', 'B0:generic', 'B+:generic',
82 'K_L0:generic', 'D0:KL', 'D+:KL', 'D_s+:KL', 'D*0:KL', 'D*+:KL', 'D_s*+:KL', 'B0:KL', 'B+:KL',
83 'D0:semileptonic', 'D+:semileptonic', 'D*0:semileptonic', 'D*+:semileptonic',
84 'B0:semileptonic', 'B+:semileptonic',
85 ])
86 self.assertEqual(particles[14].preCutConfig.userCut, 'Mbc > 5.2 and abs(deltaE) < 0.5 and [nRemainingTracksInROE == 0]')
87 self.assertEqual(particles[15].preCutConfig.userCut, 'Mbc > 5.2 and abs(deltaE) < 0.5 and [nRemainingTracksInROE == 0]')
88 self.assertEqual(particles[23].preCutConfig.userCut, 'nRemainingTracksInROE == 0')
89 self.assertEqual(particles[24].preCutConfig.userCut, 'nRemainingTracksInROE == 0')
90 self.assertEqual(particles[29].preCutConfig.userCut, 'nRemainingTracksInROE == 0')
91 self.assertEqual(particles[30].preCutConfig.userCut, 'nRemainingTracksInROE == 0')
92
93 def test_get_specific(self):
94 particles = fei.default_channels.get_default_channels(specific=True, KLong=True, baryonic=False)
95 self.assertEqual([p.identifier for p in particles],
96 ['pi+:generic', 'K+:generic', 'mu+:generic', 'e+:generic', 'gamma:generic', 'pi0:generic', 'K_S0:generic',
97 'J/psi:generic', 'D0:generic', 'D+:generic', 'D_s+:generic', 'D*0:generic', 'D*+:generic',
98 'D_s*+:generic', 'B0:generic', 'B+:generic',
99 'K_L0:generic', 'D0:KL', 'D+:KL', 'D_s+:KL', 'D*0:KL', 'D*+:KL', 'D_s*+:KL', 'B0:KL', 'B+:KL',
100 'D0:semileptonic', 'D+:semileptonic', 'D*0:semileptonic', 'D*+:semileptonic',
101 'B0:semileptonic', 'B+:semileptonic'])
102 self.assertEqual(particles[0].preCutConfig.userCut, '[dr < 2] and [abs(dz) < 4] and isInRestOfEvent > 0.5')
103 self.assertEqual(particles[1].preCutConfig.userCut, '[dr < 2] and [abs(dz) < 4] and isInRestOfEvent > 0.5')
104 self.assertEqual(particles[2].preCutConfig.userCut, '[dr < 2] and [abs(dz) < 4] and isInRestOfEvent > 0.5')
105 self.assertEqual(particles[3].preCutConfig.userCut, '[dr < 2] and [abs(dz) < 4] and isInRestOfEvent > 0.5')
106 self.assertEqual(particles[4].preCutConfig.userCut, '[[clusterReg == 1 and E > 0.10] or [clusterReg == 2 and E > 0.05]'
107 ' or [clusterReg == 3 and E > 0.15]] and isInRestOfEvent > 0.5')
108 self.assertEqual(particles[6].preCutConfig.userCut, '0.4 < M < 0.6')
109 self.assertEqual(particles[6].channels[2].preCutConfig.userCut, '0.4 < M < 0.6 and isInRestOfEvent > 0.5')
110 self.assertEqual(particles[16].preCutConfig.userCut, 'isInRestOfEvent > 0.5')
111
112 def test_get_specific_converted(self):
114 particles = fei.default_channels.get_default_channels(specific=True, KLong=True, baryonic=False)
115 self.assertEqual([p.identifier for p in particles],
116 ['pi+:generic', 'K+:generic', 'mu+:generic', 'e+:generic', 'gamma:generic', 'pi0:generic', 'K_S0:generic',
117 'J/psi:generic', 'D0:generic', 'D+:generic', 'D_s+:generic', 'D*0:generic', 'D*+:generic',
118 'D_s*+:generic', 'B0:generic', 'B+:generic',
119 'K_L0:generic', 'D0:KL', 'D+:KL', 'D_s+:KL', 'D*0:KL', 'D*+:KL', 'D_s*+:KL', 'B0:KL', 'B+:KL',
120 'D0:semileptonic', 'D+:semileptonic', 'D*0:semileptonic', 'D*+:semileptonic',
121 'B0:semileptonic', 'B+:semileptonic'])
122 self.assertEqual(particles[0].preCutConfig.userCut, '[dr < 2] and [abs(dz) < 4] and isInRestOfEvent > 0.5')
123 self.assertEqual(particles[1].preCutConfig.userCut, '[dr < 2] and [abs(dz) < 4] and isInRestOfEvent > 0.5')
124 self.assertEqual(particles[2].preCutConfig.userCut, '[dr < 2] and [abs(dz) < 4] and isInRestOfEvent > 0.5')
125 self.assertEqual(particles[3].preCutConfig.userCut, '[dr < 2] and [abs(dz) < 4] and isInRestOfEvent > 0.5')
126 self.assertEqual(particles[4].preCutConfig.userCut, 'goodBelleGamma == 1 and clusterBelleQuality == 0 '
127 'and isInRestOfEvent > 0.5')
128 self.assertEqual(particles[5].preCutConfig.userCut, '0.08 < InvM < 0.18 and isInRestOfEvent > 0.5')
129 self.assertEqual(particles[6].preCutConfig.userCut, '0.4 < M < 0.6 and isInRestOfEvent > 0.5')
130 self.assertEqual(particles[16].preCutConfig.userCut, 'isInRestOfEvent > 0.5')
132
133 def test_get_converted(self):
135 particles = fei.default_channels.get_default_channels(baryonic=False)
136 self.assertEqual([p.identifier for p in particles],
137 ['pi+:generic', 'K+:generic', 'mu+:generic', 'e+:generic', 'gamma:generic', 'pi0:generic', 'K_S0:generic',
138 'J/psi:generic', 'D0:generic', 'D+:generic', 'D_s+:generic', 'D*0:generic', 'D*+:generic',
139 'D_s*+:generic', 'B0:generic', 'B+:generic',
140 'D0:semileptonic', 'D+:semileptonic', 'D*0:semileptonic', 'D*+:semileptonic',
141 'B0:semileptonic', 'B+:semileptonic'])
142
143 chargedVariables = ['eIDBelle',
144 'atcPIDBelle(3,2)',
145 'atcPIDBelle(4,2)', 'atcPIDBelle(4,3)',
146 'muIDBelle',
147 'p', 'pt', 'pz', 'dr', 'dz', 'chiProb', 'extraInfo(preCut_rank)']
148 self.assertEqual(particles[0].preCutConfig.userCut, '[dr < 2] and [abs(dz) < 4]')
149 self.assertEqual(particles[0].mvaConfig.variables, chargedVariables)
150 self.assertEqual(particles[0].preCutConfig.bestCandidateVariable, 'atcPIDBelle(2,3)')
151 self.assertEqual(particles[1].preCutConfig.userCut, '[dr < 2] and [abs(dz) < 4]')
152 self.assertEqual(particles[1].mvaConfig.variables, chargedVariables)
153 self.assertEqual(particles[1].preCutConfig.bestCandidateVariable, 'atcPIDBelle(3,2)')
154 self.assertEqual(particles[2].preCutConfig.userCut, '[dr < 2] and [abs(dz) < 4]')
155 self.assertEqual(particles[2].mvaConfig.variables, chargedVariables)
156 self.assertEqual(particles[2].preCutConfig.bestCandidateVariable, 'muIDBelle')
157 self.assertEqual(particles[3].preCutConfig.userCut, '[dr < 2] and [abs(dz) < 4]')
158 self.assertEqual(particles[3].mvaConfig.variables, chargedVariables)
159 self.assertEqual(particles[3].preCutConfig.bestCandidateVariable, 'eIDBelle')
160 self.assertEqual(particles[4].preCutConfig.userCut, 'goodBelleGamma == 1 and clusterBelleQuality == 0')
161 self.assertEqual(particles[6].mvaConfig.variables, ['dr', 'dz', 'distance', 'significanceOfDistance', 'chiProb',
162 'M', 'abs(dM)',
163 'useCMSFrame(E)', 'daughterAngle(0,1)',
164 'cosAngleBetweenMomentumAndVertexVector',
165 'extraInfo(preCut_rank)', 'extraInfo(goodKs)', 'extraInfo(ksnbVLike)',
166 'extraInfo(ksnbNoLam)', 'extraInfo(ksnbStandard)'])
168
169
170class TestGetFRChannels(unittest.TestCase):
171 def test_get_default(self):
173 self.assertEqual([p.identifier for p in particles],
174 ['pi+:generic', 'K+:generic', 'mu+:generic', 'e+:generic', 'gamma:generic', 'pi0:generic', 'K_S0:generic',
175 'J/psi:generic', 'D0:generic', 'D+:generic', 'D_s+:generic', 'D*0:generic', 'D*+:generic',
176 'D_s*+:generic', 'B0:generic', 'B+:generic'])
177 self.assertEqual(len(particles[0].channels), 1)
178 self.assertEqual(len(particles[1].channels), 1)
179 self.assertEqual(len(particles[2].channels), 1)
180 self.assertEqual(len(particles[3].channels), 1)
181 self.assertEqual(len(particles[4].channels), 2)
182 self.assertEqual(len(particles[5].channels), 1)
183 self.assertEqual(len(particles[6].channels), 3)
184 self.assertEqual(len(particles[7].channels), 2)
185 self.assertEqual(len(particles[8].channels), 10)
186 self.assertEqual(len(particles[9].channels), 7)
187 self.assertEqual(len(particles[10].channels), 8)
188 self.assertEqual(len(particles[11].channels), 2)
189 self.assertEqual(len(particles[12].channels), 2)
190 self.assertEqual(len(particles[13].channels), 1)
191 self.assertEqual(len(particles[14].channels), 15)
192 self.assertEqual(len(particles[15].channels), 17)
193
194 def test_get_mode_names(self):
195 had_modes = fei.default_channels.get_mode_names('B0', hadronic=True, semileptonic=False)
196 self.assertEqual(len(had_modes), 32)
197 sl_modes = fei.default_channels.get_mode_names('B0', hadronic=False, semileptonic=True)
198 self.assertEqual(len(sl_modes), 8)
199 had_modes = fei.default_channels.get_mode_names('B+', hadronic=True, semileptonic=False)
200 self.assertEqual(len(had_modes), 36)
201 sl_modes = fei.default_channels.get_mode_names('B+', hadronic=False, semileptonic=True)
202 self.assertEqual(len(sl_modes), 8)
203
204
205if __name__ == '__main__':
206 tempdir = tempfile.mkdtemp()
207 os.chdir(tempdir)
208 # main() never returns, so install exit handler to do our cleanup
209 atexit.register(shutil.rmtree, tempdir)
210 unittest.main()
211
212# @endcond
def setB2BII()
Definition: b2bii.py:21
def unsetB2BII()
Definition: b2bii.py:25
def get_fr_channels(convertedFromBelle=False)
def get_default_channels(B_extra_cut=None, hadronic=True, semileptonic=True, KLong=False, baryonic=True, chargedB=True, neutralB=True, specific=False, removeSLD=False, strangeB=False)
list get_mode_names(str particle_name, hadronic=True, semileptonic=False, removeSLD=True, remove_list_labels=True, **channel_kwargs)