Belle II Software release-09-00-00
decfiles_line_number.py
1#!/usr/bin/env python
2
3
10
11# Compare length of decay description measured in number of lines
12# (including comments).
13
14import re
15import basf2
16from ROOT.Belle2 import EvtGenDatabasePDG
17
18database = EvtGenDatabasePDG.Instance()
19
20f = open(basf2.find_file('decfiles/dec/DECAY_BELLE2.DEC'))
21decfile_lines = f.readlines()
22f.close()
23
24re_decay = re.compile('Decay *([^ ]+).*\n')
25re_enddecay = re.compile('Enddecay *')
26
27in_decay = False
28decays = []
29particle = ''
30decay_line = 0
31for i in range(len(decfile_lines)):
32 if in_decay:
33 match = re_enddecay.match(decfile_lines[i])
34 if match is not None:
35 decays.append([particle, i - decay_line])
36 in_decay = False
37 else:
38 match = re_decay.match(decfile_lines[i])
39 if match is not None:
40 particle = match.group(1)
41 decay_line = i
42 in_decay = True
43
44
45def get_decay_length(particle_name):
46 for decay in decays:
47 if (decay[0] == particle_name):
48 return decay[1]
49 return -1
50
51
52for particle in database.ParticleList():
53 code = particle.PdgCode()
54 name = particle.GetName()
55 if (code > 0):
56 antiparticle = database.GetParticle(-code)
57 if antiparticle:
58 antiname = antiparticle.GetName()
59 length = get_decay_length(name)
60 antilength = get_decay_length(antiname)
61 if (length > 0 and antilength > 0 and length != antilength):
62 print(f'Inconsistent length of decay description '
63 f'for {name} ({length}) and {antiname} ({antilength}).')
64 exit(1)