Belle II Software development
dump_clusters.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12
13# Some ROOT tools
14from ROOT import Belle2
15
16
17class dump_clusters(b2.Module):
18
19 """A simple module to timing of SVD clusters.
20 Intended for use with the RandomizeEventTimes feature of SVDDigitizer,
21 which stores (randomized) event times in EventMetaData.
22 For background studies, it distinguishes signal and background clusters..
23 """
24
25 def __init__(self, filename='dump_clusters.txt', collection='SVDClusters'):
26 """Initialize the module"""
27
28 super().__init__()
29
30 self.file = open(filename, 'w')
31
32 self.collection = collection
33
34 self.vxdid_factors = (8192, 256, 32)
35
36 def beginRun(self):
37 """ Write legend for file columns """
38
39 self.file.write(
40 'EventNo Layer Ladder Sensor Side Position Bg Time_event' +
41 'Time_cluster Charge_cluster Size_cluster Chi2_cluster\n'
42 )
43
44 def event(self):
45 """Save information on all clusters together with event time data. """
46
47 eventData = Belle2.PyStoreObj('EventMetaData')
48 eventNo = eventData.getEvent()
49 svd_evt_info = Belle2.PyStoreObj('SVDEventInfo')
50 mode_byte = svd_evt_info.getModeByte()
51 clusters = Belle2.PyStoreArray(self.collection)
52
53 for cluster in clusters:
54
55 bg_label = 's'
56 reco_digit = cluster.getRelatedTo('SVDRecoDigits')
57 triggerTime = 0.0
58 if reco_digit:
59 # Trigger bin from SVDModeByte
60 triggerBin = ord(mode_byte.getTriggerBin())
61 triggerTime = 0.25 * 31.44 * (-4 + triggerBin + 0.5)
62
63 sensorID = cluster.getRawSensorID()
64
65 uSide = cluster.isUCluster()
66
67 # Sesnor identification
68 [layer, ladder, sensor] = self.decode(sensorID)
69 side_str = 'u' if uSide else 'v'
70
71 s = f'{eventNo} {layer} {ladder} {sensor} {side_str} {cluster.getPosition()} {bg_label} {triggerTime}'
72 # Cluster information
73 s += f' {cluster.getClsTime()} {cluster.getCharge()} {cluster.getSize()} {cluster.getChi2()}\n'
74 self.file.write(s)
75
76 def terminate(self):
77 """ Close the output file."""
78
79 self.file.close()
80
81 def decode(self, vxdid):
82 """ Utility to decode sensor IDs """
83
84 result = []
85 for f in self.vxdid_factors:
86 result.append(vxdid // f)
87 vxdid = vxdid % f
88
89 return result
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
def __init__(self, filename='dump_clusters.txt', collection='SVDClusters')