Belle II Software  release-08-01-10
SVDChargeSharing.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import math
13 import basf2 as b2
14 
15 # Some ROOT tools
16 from ROOT import Belle2
17 
18 
19 class SVDChargeSharing(b2.Module):
20 
21  """A module to gather data on charge sharing in the SVD."""
22 
23  def __init__(self):
24  """Initialize the module"""
25 
26  super(SVDChargeSharing, self).__init__()
27 
28  self.filefile = open('SVDChargeSharingData.txt', 'w')
29 
30  def beginRun(self):
31  """ Write legend for file columns """
32 
33  self.filefile.write('sensor_type layer ladder sensor truehit_index cluster_index ')
34  self.filefile.write('truehit_u truehit_eta_u truehit_v truehit_eta_v charge_keV ')
35  self.filefile.write('theta_u theta_v cluster_isU cluster_pos cluster_eta ')
36  self.filefile.write('cluster_charge_ADU seed_charge_ADU cluster_size\n')
37 
38  def event(self):
39  """Find clusters with a truehit and print some stats."""
40 
41  # truehits = Belle2.PyStoreArray('SVDTrueHits')
42  # nTruehits = truehits.getEntries()
43  clusters = Belle2.PyStoreArray('SVDClusters')
44  nClusters = clusters.getEntries()
45  print("nClusters = "+str(nClusters))
47  # Start with clusters and use the relation to get the corresponding
48  # digits and truehits.
49  for cluster_index in range(nClusters):
50  cluster = clusters[cluster_index]
51  # Get SensorInfo for the sensor
52  truehit = cluster.getRelated('SVDTrueHits')
53  # Here we ask only for clusters with exactly one TrueHit.
54  if (not truehit):
55  continue
56 
57  # Now let's store some data
58  s = ''
59  # Sesnor identification
60  sensorID = Belle2.VxdID(truehit.getRawSensorID())
61  info = geoCache.get(sensorID)
62  layer = sensorID.getLayerNumber()
63  ladder = sensorID.getLadderNumber()
64  sensor = sensorID.getSensorNumber()
65  # No wedge sensor data
66  if sensor == 1 and layer != 3:
67  continue
68 
69  sensorType = 'barrel' if layer > 3 else 'layer3'
70  s += '{sID} {layer} {ladder} {sensor} {indexT:4d} {indexC:4d} '.format(
71  sID=sensorType,
72  layer=layer,
73  ladder=ladder,
74  sensor=sensor,
75  indexT=truehit.getArrayIndex(),
76  indexC=cluster_index
77  )
78  # TrueHit information
79  truehit_u = truehit.getU()
80  truehit_v = truehit.getV()
81  pitch_u = info.getUPitch()
82  truehit_eta_u = (truehit_u / pitch_u) % 1
83  pitch_v = info.getVPitch()
84  truehit_eta_v = (truehit_v / pitch_v) % 1
85  thetaU = math.atan2(truehit.getExitU() - truehit.getEntryU(),
86  info.getThickness())
87  thetaV = math.atan2(truehit.getExitV() - truehit.getEntryV(),
88  info.getThickness())
89  s += '{uTH:10.5f} {uTHeta:10.5f} {vTH:10.5f} {vTHeta:10.5f} {eTH:10.7f} '.format(
90  uTH=truehit_u, uTHeta=truehit_eta_u,
91  vTH=truehit_v, vTHeta=truehit_eta_v,
92  eTH=1.0e6 * truehit.getEnergyDep()
93  ) + '{thetaU:6.3f} {thetaV:6.3f} '.format(
94  thetaU=thetaU, thetaV=thetaV
95  )
96  # Cluster information
97  cluster_pitch = (pitch_u if cluster.isUCluster() else pitch_v)
98  cluster_eta = (cluster.getPosition() / cluster_pitch) % 1
99  s += '{isU} {uvC:10.5f} {uvCeta:10.5f} {eC:10.1f} '.format(
100  isU=cluster.isUCluster(),
101  uvC=cluster.getPosition(),
102  uvCeta=cluster_eta,
103  eC=cluster.getCharge()
104  ) + '{eSeed:10.1f} {size:5d}'.format(
105  eSeed=cluster.getSeedCharge(),
106  size=cluster.getSize())
107 
108  s += '\n'
109  self.filefile.write(s)
110 
111  def terminate(self):
112  """ Close the output file."""
113 
114  self.filefile.close()
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition: GeoCache.cc:214
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33