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