Belle II Software  release-05-01-25
decfiles_line_number.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # Compare length of decay description measured in number of lines
5 # (including comments).
6 
7 import re
8 
9 from ROOT import Belle2
10 from ROOT.Belle2 import EvtGenDatabasePDG
11 
12 database = EvtGenDatabasePDG.Instance()
13 
14 f = open(Belle2.FileSystem.findFile('decfiles/dec/DECAY_BELLE2.DEC'))
15 decfile_lines = f.readlines()
16 f.close()
17 
18 re_decay = re.compile('Decay *([^ ]+).*\n')
19 re_enddecay = re.compile('Enddecay *')
20 
21 in_decay = False
22 decays = []
23 for i in range(len(decfile_lines)):
24  if in_decay:
25  match = re_enddecay.match(decfile_lines[i])
26  if match is not None:
27  decays.append([particle, i - decay_line])
28  in_decay = False
29  else:
30  match = re_decay.match(decfile_lines[i])
31  if match is not None:
32  particle = match.group(1)
33  decay_line = i
34  in_decay = True
35 
36 
37 def get_decay_length(particle_name):
38  for decay in decays:
39  if (decay[0] == particle_name):
40  return decay[1]
41  return -1
42 
43 for particle in database.ParticleList():
44  code = particle.PdgCode()
45  name = particle.GetName()
46  if (code > 0):
47  antiparticle = database.GetParticle(-code)
48  if antiparticle:
49  antiname = antiparticle.GetName()
50  length = get_decay_length(name)
51  antilength = get_decay_length(antiname)
52  if (length > 0 and antilength > 0 and length != antilength):
53  print(f'Inconsistent length of decay description '
54  f'for {name} ({length}) and {antiname} ({antilength}).')
55  exit(1)
Belle2::FileSystem::findFile
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:147