Belle II Software development
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 import Belle2 # noqa: make Belle2 namespace available
17from ROOT.Belle2 import EvtGenDatabasePDG
18
19database = EvtGenDatabasePDG.Instance()
20
21f = open(basf2.find_file('decfiles/dec/DECAY_BELLE2.DEC'))
22decfile_lines = f.readlines()
23f.close()
24
25re_decay = re.compile('Decay *([^ ]+).*\n')
26re_enddecay = re.compile('Enddecay *')
27
28in_decay = False
29decays = []
30particle = ''
31decay_line = 0
32for i in range(len(decfile_lines)):
33 if in_decay:
34 match = re_enddecay.match(decfile_lines[i])
35 if match is not None:
36 decays.append([particle, i - decay_line])
37 in_decay = False
38 else:
39 match = re_decay.match(decfile_lines[i])
40 if match is not None:
41 particle = match.group(1)
42 decay_line = i
43 in_decay = True
44
45
46def get_decay_length(particle_name):
47 for decay in decays:
48 if (decay[0] == particle_name):
49 return decay[1]
50 return -1
51
52
53for particle in database.ParticleList():
54 code = particle.PdgCode()
55 name = particle.GetName()
56 if (code > 0):
57 antiparticle = database.GetParticle(-code)
58 if antiparticle:
59 antiname = antiparticle.GetName()
60 length = get_decay_length(name)
61 antilength = get_decay_length(antiname)
62 if (length > 0 and antilength > 0 and length != antilength):
63 print(f'Inconsistent length of decay description '
64 f'for {name} ({length}) and {antiname} ({antilength}).')
65 exit(1)