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