20 from ROOT
import Belle2
22 logging = pybasf2.LogPythonInterface()
24 ROOT.gSystem.Load(
"libanalysis.so")
25 ROOT.gSystem.Load(
"libanalysis_utility.so")
28 def _bitwiseConversion(value, i='f', o='i'):
30 Bitwise conversion between to python types
31 This is equivalently to
38 @param i input data type (e.g. f for float)
39 @param o output data type (e.g. i for integer)
41 s = struct.pack(
'>' + i, value)
42 return struct.unpack(
'>' + o, s)[0]
45 def _decayHashFloatToInt(decayHash, decayHashExtended):
47 Convert decayHash and decayHashExtended 32 bit floats to an 64 bit integer
49 decayHashInt = _bitwiseConversion(np.float32(decayHash))
50 decayHashExtendedInt = _bitwiseConversion(np.float32(decayHashExtended))
51 decayHashFullInt = decayHashInt << 32
52 decayHashFullInt += decayHashExtendedInt
53 return decayHashFullInt
58 DecayHashMap using the C++ implementation of DecayTree and DecayNode
61 def __init__(self, rootfile, removeRadiativeGammaFlag=False):
64 ntuple = root_numpy.root2array(rootfile)
70 for decayHash, decayHashExtended, decayString
in ntuple:
72 if decayInt
in self.
_string_string:
74 self.
_string_string[decayInt] = decayString
79 Return DecayString given the decayHash and decayHashExtended
80 @param decayHash output of extraInfo(decayHash)
81 @param decayHashExtended output of extraInfo(decayHashExtended)
87 Return original (MC) DecayTree given the decayHash and decayHashExtended
88 @param decayHash output of extraInfo(decayHash)
89 @param decayHashExtended output of extraInfo(decayHashExtended)
95 Return reconstructed DecayTree given the decayHash and decayHashExtended
96 @param decayHash output of extraInfo(decayHash)
97 @param decayHashExtended output of extraInfo(decayHashExtended)
103 Print the DecayString in a fancy way given the decayHash and decayHashExtended
104 @param decayHash output of extraInfo(decayHash)
105 @param decayHashExtended output of extraInfo(decayHashExtended)
107 entry = self.
get_stringget_string(decayHash, decayHashExtended)
108 entries = entry.split(
'|')
109 all_particles = re.findall(
r"(-?[0-9]+)", entries[0])
111 if len(all_particles) != len(entries) - 1:
113 raise RuntimeError(
"Bad format of decay string: " +
114 str(len(all_particles)) +
" " + str(len(entries)) +
" " + str(entries))
117 table.append([
"Decay ", prettify_pdg_codes(entries[0])])
118 for particle, mc_decay_string
in zip(all_particles, entries[1:]):
119 table.append([prettify_pdg_codes(particle), prettify_pdg_codes(mc_decay_string)])
121 basf2.pretty_print_table(table, column_widths=[6,
'*'])
126 Convert PDG code to a name
135 pdg_string = str(pdg_code)
138 except BaseException:
142 if pybasf2.LogPythonInterface.terminal_supports_colors():
143 return '\x1b[31m' + pdg_string +
'\x1b[0m'
145 return '^' + pdg_string
149 def prettify_pdg_codes(text):
151 Prettifiy a string containing PDG codes by replacing PDG codes
152 with their corresponding names.
155 text = re.sub(
r"(\^?-?[0-9]+)",
lambda x: _pdg_to_name(x.group(0)), text)
156 text = text.replace(
'gamma',
'g').replace(
'--> ',
'').replace(
'anti-',
'a-')
157 text = text.replace(
'Upsilon',
'Y').replace(
') ',
')').replace(
' (',
'(')
Contains several DecayTree objects, which belong all to the same candidate.
static int decayHashFloatToInt(float decayHash, float decayHashExtended)
Convert DecayHashes outputted by ParticleMCDecayString module to an integer.
_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)