Belle II Software  release-06-01-15
DumpDigits.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 DumpDigits(b2.Module):
19 
20  """A simple module to dump PXD digits."""
21 
22  def __init__(self):
23  """Initialize the module"""
24 
25  super(DumpDigits, self).__init__()
26 
27  self.dumpfiledumpfile = 'PXDDigitsDump.txt'
28 
29  self.vxdid_factorsvxdid_factors = (8192, 256, 32)
30 
31  def beginRun(self):
32  """ Write legend for file columns """
33  with open(self.dumpfiledumpfile, 'w') as dumpfile:
34  dumpfile.write('vxd.id layer ladder sensor digit.u digit.v digit.charge ')
35 
36  def event(self):
37  """Find clusters with a truehit and print some stats."""
38 
39  digits = Belle2.PyStoreArray('PXDDigits')
40  # nDigits = digits.getEntries()
41  # Start with clusters and use the relation to get the corresponding
42  # digits and truehits.
43  with open(self.dumpfiledumpfile, 'a') as dumpfile:
44  s = ''
45  for digit in digits:
46  # Sesnor identification
47  sensorID = digit.getSensorID().getID()
48  [layer, ladder, sensor] = self.decodedecode(sensorID)
49  s += '{sID} {layer:3d} {ladder:3d} {sensor:3d} {u:6d} {v:6d} {c:8.1f}'.format(
50  sID=sensorID,
51  layer=layer,
52  ladder=ladder,
53  sensor=sensor,
54  u=digit.getUCellID(),
55  v=digit.getVCellID(),
56  c=digit.getCharge()
57  )
58  s += '\n'
59  dumpfile.write(s)
60 
61  def terminate(self):
62  """ Nothing."""
63 
64  def decode(self, vxdid):
65  """ Utility to decode sensor IDs """
66 
67  result = []
68  for f in self.vxdid_factors:
69  result.append(vxdid // f)
70  vxdid = vxdid % f
71 
72  return result
a (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:56
def decode(self, vxdid)
Definition: DumpDigits.py:64
vxdid_factors
Factors for decoding VXDId's.
Definition: DumpDigits.py:29
dumpfile
Output file object.
Definition: DumpDigits.py:27
int getID(const std::vector< double > &breaks, double t)
get id of the time point t
Definition: calibTools.h:60