Belle II Software  release-08-01-10
dump_digits.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2 as b2
13 
14 # Some ROOT tools
15 from ROOT import Belle2
16 
17 
18 class dump_digits(b2.Module):
19 
20  """A simple module to check SVD digit fits."""
21 
22  def __init__(self, filename='dumped_digits.txt'):
23  """Initialize the module"""
24 
25  super(dump_digits, self).__init__()
26 
27  self.outfileoutfile = open(filename, 'w')
28 
29  self.vxdid_factorsvxdid_factors = (8192, 256, 32)
30  # Get a handle on the GeoCache
31 
32  self.geoCache = Belle2.VXD.GeoCache.getInstance()
33  # Record filenames
34 
35  self.noise_cal = Belle2.SVDNoiseCalibrations()
36 
37  self.pulse_cal = Belle2.SVDPulseShapeCalibrations()
38 
39  def beginRun(self):
40  """ Tasks at the start of a run """
41  # Write header to output file
42  self.outfileoutfile.write(
43  'EventNo Layer Ladder Sensor Side StripNo TimeTrigger ' +
44  'GoodStrip Gain Noise Width TimeShift ' +
45  'Sample0 Sample1 Sample2 Sample3 Sample4 Sample5 Charge TimeFit Chi2\n')
46 
47  def event(self):
48  """Cycle through RecoDigit/ShaperDigit pairs and dump the corresponding data"""
49 
50  evt_info = Belle2.PyStoreObj('EventMetaData')
51  svd_evt_info = Belle2.PyStoreObj('SVDEventInfo')
52  event_number = evt_info.getEvent()
53  mode_byte = svd_evt_info.getModeByte()
54  reco_digits = Belle2.PyStoreArray('SVDRecoDigits')
55 
56  for reco_digit in reco_digits:
57 
58  shaper_digit = reco_digit.getRelatedTo('SVDShaperDigits')
59 
60  s = ''
61 
62  # Sesnor/side/strip identification
63  [layer, ladder, sensor] = self.decode(reco_digit.getRawSensorID())
64  s += '{event} {layer} {ladder} {sensor} {side} {strip} '.format(
65  event=event_number,
66  layer=layer,
67  ladder=ladder,
68  sensor=sensor,
69  side=('u' if reco_digit.isUStrip() else 'v'),
70  strip=reco_digit.getCellID()
71  )
72  sensorID = reco_digit.getSensorID()
73  stripNo = reco_digit.getCellID()
74  # Trigger bin from SVDModeByte
75  triggerBin = ord(mode_byte.getTriggerBin())
76  triggerTime = 0.25 * 31.44 * (-4 + triggerBin + 0.5)
77  s += '{trigger:.3f} '.format(trigger=triggerTime)
78  # Calibrations
79  stripNoise = self.noise_cal.getNoise(sensorID, reco_digit.isUStrip(), stripNo)
80  stripGain = 22500 / self.pulse_cal.getADCFromCharge(sensorID, reco_digit.isUStrip(), stripNo, 22500)
81 
82  stripT0 = self.pulse_cal.getPeakTime(sensorID, reco_digit.isUStrip(), stripNo)
83  stripWidth = self.pulse_cal.getWidth(sensorID, reco_digit.isUStrip(), stripNo)
84  s += '{mask} {gain:.3f} {noise:.3f} {width} {delay:.3f} '.format(
85  mask='y',
86  gain=stripGain,
87  noise=stripNoise,
88  width=stripWidth,
89  delay=stripT0
90  )
91 
92  # Digit information
93  samples = shaper_digit.getSamples()
94  for iSample in range(6):
95  s += '{0} '.format(samples[iSample])
96 
97  # Data from time fit
98  s += '{amplitude:.3f} {time:.3f} {chi2:.3f}'.format(
99  amplitude=reco_digit.getCharge(),
100  time=reco_digit.getTime(),
101  chi2=reco_digit.getChi2Ndf()
102  )
103 
104  s += '\n'
105  self.outfileoutfile.write(s)
106 
107  def terminate(self):
108  """ Close the output file."""
109 
110  self.outfileoutfile.close()
111 
112  def decode(self, vxdid):
113  """ Utility to decode sensor IDs """
114 
115  result = []
116  for f in self.vxdid_factorsvxdid_factors:
117  result.append(vxdid // f)
118  vxdid = vxdid % f
119 
120  return result
121 
122  def three_test(self, digit, threshold):
123  ''' 3-samples digit test '''
124 
125  counter = 0
126  for sample in digit.getSamples():
127  if counter == 3:
128  continue
129  elif sample >= threshold:
130  counter += 1
131  else:
132  counter = 0
133  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:22
vxdid_factors
Factors for decoding VXDId's.
Definition: dump_digits.py:29
outfile
Input file object.
Definition: dump_digits.py:27