21 def _bitwiseConversion(value, i='f', o='i'):
23 Bitwise conversion between to python types
24 This is equivalently to
31 @param i input data type (e.g. f for float)
32 @param o output data type (e.g. i for integer)
34 s = struct.pack(
'>' + i, value)
35 return struct.unpack(
'>' + o, s)[0]
38 def _decayHashFloatToInt(decayHash, decayHashExtended):
40 Convert decayHash and decayHashExtended 32 bit floats to an 64 bit integer
42 decayHashInt = _bitwiseConversion(np.float32(decayHash))
43 decayHashExtendedInt = _bitwiseConversion(np.float32(decayHashExtended))
44 decayHashFullInt = decayHashInt << 32
45 decayHashFullInt += decayHashExtendedInt
46 return decayHashFullInt
51 DecayHashMap using the C++ implementation of DecayTree and DecayNode
54 def __init__(self, rootfile, removeRadiativeGammaFlag=False):
58 ntuple = root_numpy.root2array(rootfile)
64 for decayHash, decayHashExtended, decayString
in ntuple:
65 decayInt = ROOT.Belle2.DecayForest.decayHashFloatToInt(decayHash, decayHashExtended)
66 if decayInt
in self.
_string_string:
68 self.
_string_string[decayInt] = decayString
69 self.
_forest_forest[decayInt] = ROOT.Belle2.DecayForest(decayString,
True, removeRadiativeGammaFlag)
73 Return DecayString given the decayHash and decayHashExtended
74 @param decayHash output of extraInfo(decayHash)
75 @param decayHashExtended output of extraInfo(decayHashExtended)
78 return self.
_string_string[ROOT.Belle2.DecayForest.decayHashFloatToInt(decayHash, 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)
87 return self.
_forest_forest[ROOT.Belle2.DecayForest.decayHashFloatToInt(decayHash, decayHashExtended)].getOriginalTree()
91 Return reconstructed DecayTree given the decayHash and decayHashExtended
92 @param decayHash output of extraInfo(decayHash)
93 @param decayHashExtended output of extraInfo(decayHashExtended)
96 return self.
_forest_forest[ROOT.Belle2.DecayForest.decayHashFloatToInt(decayHash, decayHashExtended)].getReconstructedTree()
100 Print the DecayString in a fancy way given the decayHash and decayHashExtended
101 @param decayHash output of extraInfo(decayHash)
102 @param decayHashExtended output of extraInfo(decayHashExtended)
104 entry = self.
get_stringget_string(decayHash, decayHashExtended)
105 entries = entry.split(
'|')
106 all_particles = re.findall(
r"(-?[0-9]+)", entries[0])
108 if len(all_particles) != len(entries) - 1:
110 raise RuntimeError(
"Bad format of decay string: " +
111 str(len(all_particles)) +
" " + str(len(entries)) +
" " + str(entries))
114 table.append([
"Decay ", prettify_pdg_codes(entries[0])])
115 for particle, mc_decay_string
in zip(all_particles, entries[1:]):
116 table.append([prettify_pdg_codes(particle), prettify_pdg_codes(mc_decay_string)])
118 basf2.pretty_print_table(table, column_widths=[6,
'*'])
123 Convert PDG code to a name
132 pdg_string = str(pdg_code)
135 except BaseException:
139 if pybasf2.LogPythonInterface.terminal_supports_colors():
140 return '\x1b[31m' + pdg_string +
'\x1b[0m'
142 return '^' + pdg_string
146 def prettify_pdg_codes(text):
148 Prettifiy a string containing PDG codes by replacing PDG codes
149 with their corresponding names.
152 text = re.sub(
r"(\^?-?[0-9]+)",
lambda x: _pdg_to_name(x.group(0)), text)
153 text = text.replace(
'gamma',
'g').replace(
'--> ',
'').replace(
'anti-',
'a-')
154 text = text.replace(
'Upsilon',
'Y').replace(
') ',
')').replace(
' (',
'(')
_forest
Dict Int -> Reconstructed DecayTree.
_string
Dict Int -> DecayStrings.
def get_original_decay(self, decayHash, decayHashExtended)
def get_reconstructed_decay(self, decayHash, decayHashExtended)
def __init__(self, rootfile, removeRadiativeGammaFlag=False)
def get_string(self, decayHash, decayHashExtended)
def print_hash(self, decayHash, decayHashExtended)