13 logging = pybasf2.LogPythonInterface()
19 ROOT.gSystem.Load(
"libanalysis.so")
20 ROOT.gSystem.Load(
"libanalysis_utility.so")
21 from ROOT
import Belle2
24 def _bitwiseConversion(value, i='f', o='i'):
26 Bitwise conversion between to python types
27 This is equivalently to
34 @param i input data type (e.g. f for float)
35 @param o output data type (e.g. i for integer)
37 s = struct.pack(
'>' + i, value)
38 return struct.unpack(
'>' + o, s)[0]
41 def _decayHashFloatToInt(decayHash, decayHashExtended):
43 Convert decayHash and decayHashExtended 32 bit floats to an 64 bit integer
45 decayHashInt = _bitwiseConversion(np.float32(decayHash))
46 decayHashExtendedInt = _bitwiseConversion(np.float32(decayHashExtended))
47 decayHashFullInt = decayHashInt << 32
48 decayHashFullInt += decayHashExtendedInt
49 return decayHashFullInt
54 DecayHashMap using the C++ implementation of DecayTree and DecayNode
56 def __init__(self, rootfile, removeRadiativeGammaFlag=False):
59 ntuple = root_numpy.root2array(rootfile)
65 for decayHash, decayHashExtended, decayString
in ntuple:
69 self.
_string[decayInt] = decayString
74 Return DecayString given the decayHash and decayHashExtended
75 @param decayHash output of extraInfo(decayHash)
76 @param decayHashExtended output of extraInfo(decayHashExtended)
82 Return original (MC) DecayTree given the decayHash and decayHashExtended
83 @param decayHash output of extraInfo(decayHash)
84 @param decayHashExtended output of extraInfo(decayHashExtended)
90 Return reconstructed DecayTree given the decayHash and decayHashExtended
91 @param decayHash output of extraInfo(decayHash)
92 @param decayHashExtended output of extraInfo(decayHashExtended)
98 Print the DecayString in a fancy way given the decayHash and decayHashExtended
99 @param decayHash output of extraInfo(decayHash)
100 @param decayHashExtended output of extraInfo(decayHashExtended)
102 entry = self.
get_string(decayHash, decayHashExtended)
103 entries = entry.split(
'|')
104 all_particles = re.findall(
r"(-?[0-9]+)", entries[0])
106 if len(all_particles) != len(entries) - 1:
108 raise RuntimeError(
"Bad format of decay string: " +
109 str(len(all_particles)) +
" " + str(len(entries)) +
" " + str(entries))
112 table.append([
"Decay ", prettify_pdg_codes(entries[0])])
113 for particle, mc_decay_string
in zip(all_particles, entries[1:]):
114 table.append([prettify_pdg_codes(particle), prettify_pdg_codes(mc_decay_string)])
116 basf2.pretty_print_table(table, column_widths=[6,
'*'])
121 Convert PDG code to a name
130 pdg_string = str(pdg_code)
137 if LogPythonInterface.terminal_supports_colors():
138 return '\x1b[31m' + pdg_string +
'\x1b[0m'
140 return '^' + pdg_string
144 def prettify_pdg_codes(text):
146 Prettifiy a string containing PDG codes by replacing PDG codes
147 with their corresponding names.
150 text = re.sub(
r"(\^?-?[0-9]+)",
lambda x: _pdg_to_name(x.group(0)), text)
151 text = text.replace(
'gamma',
'g').replace(
'--> ',
'').replace(
'anti-',
'a-')
152 text = text.replace(
'Upsilon',
'Y').replace(
') ',
')').replace(
' (',
'(')