Belle II Software  release-08-01-10
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 particle = ''
31 decay_line = 0
32 for 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 
46 def 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 
53 for 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)