Belle II Software development
dump_digits.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_digits(b2.Module):
18
19 """A simple module to check SVD digit fits."""
20
21 def __init__(self, filename='dumped_digits.txt'):
22 """Initialize the module"""
23
24 super().__init__()
25
26 self.outfile = open(filename, 'w')
27
28 self.vxdid_factors = (8192, 256, 32)
29 # Get a handle on the GeoCache
30
31 self.geoCache = Belle2.VXD.GeoCache.getInstance()
32 # Record filenames
33
34 self.noise_cal = Belle2.SVDNoiseCalibrations()
35
36 self.pulse_cal = Belle2.SVDPulseShapeCalibrations()
37
38 def beginRun(self):
39 """ Tasks at the start of a run """
40 # Write header to output file
41 self.outfile.write(
42 'EventNo Layer Ladder Sensor Side StripNo TimeTrigger ' +
43 'GoodStrip Gain Noise Width TimeShift ' +
44 'Sample0 Sample1 Sample2 Sample3 Sample4 Sample5 Charge TimeFit Chi2\n')
45
46 def event(self):
47 """Cycle through RecoDigit/ShaperDigit pairs and dump the corresponding data"""
48
49 evt_info = Belle2.PyStoreObj('EventMetaData')
50 svd_evt_info = Belle2.PyStoreObj('SVDEventInfo')
51 event_number = evt_info.getEvent()
52 mode_byte = svd_evt_info.getModeByte()
53 reco_digits = Belle2.PyStoreArray('SVDRecoDigits')
54
55 for reco_digit in reco_digits:
56
57 shaper_digit = reco_digit.getRelatedTo('SVDShaperDigits')
58
59 s = ''
60
61 # Sesnor/side/strip identification
62 [layer, ladder, sensor] = self.decode(reco_digit.getRawSensorID())
63 s += f'{event_number} {layer} {ladder} {sensor} {"u" if reco_digit.isUStrip() else "v"} {reco_digit.getCellID()} '
64 sensorID = reco_digit.getSensorID()
65 stripNo = reco_digit.getCellID()
66 # Trigger bin from SVDModeByte
67 triggerBin = ord(mode_byte.getTriggerBin())
68 triggerTime = 0.25 * 31.44 * (-4 + triggerBin + 0.5)
69 s += f'{triggerTime:.3f} '
70 # Calibrations
71 stripNoise = self.noise_cal.getNoise(sensorID, reco_digit.isUStrip(), stripNo)
72 stripGain = 22500 / self.pulse_cal.getADCFromCharge(sensorID, reco_digit.isUStrip(), stripNo, 22500)
73
74 stripT0 = self.pulse_cal.getPeakTime(sensorID, reco_digit.isUStrip(), stripNo)
75 stripWidth = self.pulse_cal.getWidth(sensorID, reco_digit.isUStrip(), stripNo)
76 s += f'{"y"} {stripGain:.3f} {stripNoise:.3f} {stripWidth} {stripT0:.3f} '
77
78 # Digit information
79 samples = shaper_digit.getSamples()
80 for iSample in range(6):
81 s += f'{samples[iSample]} '
82
83 # Data from time fit
84 s += f'{reco_digit.getCharge():.3f} {reco_digit.getTime():.3f} {reco_digit.getChi2Ndf():.3f}'
85 s += '\n'
86 self.outfile.write(s)
87
88 def terminate(self):
89 """ Close the output file."""
90
91 self.outfile.close()
92
93 def decode(self, vxdid):
94 """ Utility to decode sensor IDs """
95
96 result = []
97 for f in self.vxdid_factors:
98 result.append(vxdid // f)
99 vxdid = vxdid % f
100
101 return result
102
103 def three_test(self, digit, threshold):
104 ''' 3-samples digit test '''
105
106 counter = 0
107 for sample in digit.getSamples():
108 if counter == 3:
109 continue
110 elif sample >= threshold:
111 counter += 1
112 else:
113 counter = 0
114 return (counter >= 3)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
This class defines the dbobject and the method to access SVD calibrations from the noise local runs.
This class defines the dbobject and the methods to access the SVD calibrations from the local runs pr...
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
def __init__(self, filename='dumped_digits.txt')
Definition: dump_digits.py:21
vxdid_factors
Factors for decoding VXDId's.
Definition: dump_digits.py:28
outfile
Input file object.
Definition: dump_digits.py:26