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