Skip to content
Snippets Groups Projects

add benchmark for pion0

Merged Chao Peng requested to merge add_pi0_benchmark into master
@@ -21,7 +21,13 @@ class AthenaDecoder:
def get(self, idvals, field):
start, width = self.fieldsmap[field]
return np.bitwise_and(np.right_shift(idvals, start), (1 << width) - 1)
if width >= 0:
return np.bitwise_and(np.right_shift(idvals, start), (1 << width) - 1)
# first bit is sign bit
else:
width = abs(width) - 1
vals = np.bitwise_and(np.right_shift(idvals, start), (1 << width) - 1)
return np.where(np.bitwise_and(np.right_shift(idvals, start + width), 1), vals - (1 << width), vals)
@staticmethod
def getReadouts(path):
@@ -53,11 +59,11 @@ class AthenaDecoder:
for field_bits in id_str.split(','):
elements = field_bits.split(':')
field_name = elements[0]
bit_width = abs(int(elements[-1]))
bit_width = int(elements[-1])
if len(elements) == 3:
curr_bit = int(elements[1])
res[field_name] = (curr_bit, bit_width)
curr_bit += bit_width
curr_bit += abs(bit_width)
return res
@@ -113,17 +119,15 @@ if __name__ == '__main__':
# kernel = DDG4.Kernel()
# description = kernel.detectorDescription()
# kernel.loadGeometry("file:{}".format(args.compact))
# decoder = description.readout(args.readout).idSpec().decoder()
# lindex = decoder.index('layer')
# get_layer_id = np.vectorize(lambda cid: decoder.get(cid, lindex))
# dd4hep_decoder = description.readout(args.readout).idSpec().decoder()
# lindex = dd4hep_decoder.index('x')
# get_layer_id = np.vectorize(lambda cid: dd4hep_decoder.get(cid, lindex))
# df.loc[:, 'layerID'] = get_layer_id(df['cellID'].astype(int).values)
# print(df[['cellID', 'layerID', 'position.x', 'position.y', 'position.z', 'energy']])
# always terminate dd4hep kernel
# kernel.terminate()
# faster way to get layerids
df.loc[:, 'layerID'] = decoder.get(df['cellID'].values, 'layer')
print(df[['cellID', 'layerID', 'position.x', 'position.y', 'position.z', 'energy']])
df.loc[:, 'xID'] = decoder.get(df['cellID'].values, 'x')
print(df[['cellID', 'layerID', 'xID', 'position.x', 'position.y', 'position.z', 'energy']])
Loading