Belle II Software  release-08-01-10
dump_clusters.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_clusters(b2.Module):
19 
20  """A simple module to timing of SVD clusters.
21  Intended for use with the RandomizeEventTimes feature of SVDDigitizer,
22  which stores (randomized) event times in EventMetaData.
23  For background studies, it distinguishes signal and background clusters..
24  """
25 
26  def __init__(self, filename='dump_clusters.txt', collection='SVDClusters'):
27  """Initialize the module"""
28 
29  super(dump_clusters, self).__init__()
30 
31  self.filefile = open(filename, 'w')
32 
33  self.collection = collection
34 
35  self.vxdid_factors = (8192, 256, 32)
36 
37  def beginRun(self):
38  """ Write legend for file columns """
39 
40  self.filefile.write(
41  'EventNo Layer Ladder Sensor Side Position Bg Time_event' +
42  'Time_cluster Charge_cluster Size_cluster Chi2_cluster\n'
43  )
44 
45  def event(self):
46  """Save information on all clusters together with event time data. """
47 
48  eventData = Belle2.PyStoreObj('EventMetaData')
49  eventNo = eventData.getEvent()
50  svd_evt_info = Belle2.PyStoreObj('SVDEventInfo')
51  mode_byte = svd_evt_info.getModeByte()
52  clusters = Belle2.PyStoreArray(self.collection)
53 
54  for cluster in clusters:
55 
56  bg_label = 's'
57  reco_digit = cluster.getRelatedTo('SVDRecoDigits')
58  triggerTime = 0.0
59  if reco_digit:
60  # Trigger bin from SVDModeByte
61  triggerBin = ord(mode_byte.getTriggerBin())
62  triggerTime = 0.25 * 31.44 * (-4 + triggerBin + 0.5)
63 
64  sensorID = cluster.getRawSensorID()
65 
66  uSide = cluster.isUCluster()
67 
68  # Sesnor identification
69  [layer, ladder, sensor] = self.decode(sensorID)
70  side_str = 'u' if uSide else 'v'
71 
72  s = '{event} {layer} {ladder} {sensor} {side} {strip} {bg} {etime}'.format(
73  event=eventNo,
74  layer=layer,
75  ladder=ladder,
76  sensor=sensor,
77  side=side_str,
78  strip=cluster.getPosition(),
79  bg=bg_label,
80  etime=triggerTime
81  )
82  # Cluster information
83  s += ' {clstime} {clscharge} {clssize} {clschi}\n'.format(
84  clstime=cluster.getClsTime(),
85  clscharge=cluster.getCharge(),
86  clssize=cluster.getSize(),
87  clschi=cluster.getChi2()
88  )
89  self.filefile.write(s)
90 
91  def terminate(self):
92  """ Close the output file."""
93 
94  self.filefile.close()
95 
96  def decode(self, vxdid):
97  """ Utility to decode sensor IDs """
98 
99  result = []
100  for f in self.vxdid_factors:
101  result.append(vxdid // f)
102  vxdid = vxdid % f
103 
104  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')