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