Belle II Software development
PXDHitErrorsTTree.py
1#!/usr/bin/env python3
2
3
10
11from ROOT import EventData
12import math
13import basf2 as b2
14
15# Some ROOT tools
16import ROOT
17from ROOT import Belle2
18
19from ROOT import gROOT, AddressOf
20
21# Define a ROOT struct to hold output data in the TTree.
22gROOT.ProcessLine('struct EventData {\
23 int vxd_id;\
24 int layer;\
25 int ladder;\
26 int sensor;\
27 int truehit_index;\
28 int cluster_index;\
29 float truehit_u;\
30 float truehit_v;\
31 float truehit_time;\
32 float truehit_charge;\
33 float theta_u;\
34 float theta_v;\
35 float cluster_u;\
36 float cluster_v;\
37 float cluster_uError;\
38 float cluster_vError;\
39 float cluster_rho;\
40 float cluster_charge;\
41 float cluster_seed;\
42 float cluster_size;\
43 float cluster_uSize;\
44 float cluster_vSize;\
45 float cluster_uPull;\
46 float cluster_vPull;\
47};'
48 )
49
50
51class PXDHitErrorsTTree(b2.Module):
52
53 """
54 A simple module to check the reconstruction of PXDTrueHits.
55 This module writes its output to a ROOT tree.
56 """
57
58 def __init__(self):
59 """Initialize the module"""
60
61 super().__init__()
62
63 self.file = ROOT.TFile('PXDHitErrorOutput.root', 'recreate')
64
65 self.tree = ROOT.TTree('tree', 'Event data of PXD simulation')
66
67 self.data = EventData()
68 # Declare tree branches
69 for key in EventData.__dict__:
70 if '__' not in key:
71 formstring = '/F'
72 if isinstance(self.data.__getattribute__(key), int):
73 formstring = '/I'
74 self.tree.Branch(
75 key,
76 AddressOf(
77 self.data,
78 key),
79 key +
80 formstring)
81
82 def beginRun(self):
83 """ Does nothing """
84
85 def event(self):
86 """Find clusters with a truehit and print some stats."""
87
88 clusters = Belle2.PyStoreArray('PXDClusters')
89
90 # Start with clusters and use the relation to get the corresponding
91 # digits and truehits.
92 for cluster in clusters:
93 cluster_truehits = cluster.getRelationsTo('PXDTrueHits')
94
95 # Here we ask only for clusters with exactly one TrueHit.
96 if len(cluster_truehits) != 1:
97 continue
98
99 for truehit in cluster_truehits:
100 # Now let's store some data
101 # Sesnor identification
102 vxd_id = truehit.getSensorID()
103 self.data.vxd_id = vxd_id.getID()
104 self.data.layer = vxd_id.getLayerNumber()
105 self.data.ladder = vxd_id.getLadderNumber()
106 self.data.sensor = vxd_id.getSensorNumber()
107 self.data.truehit_index = truehit.getArrayIndex()
108 self.data.cluster_index = cluster.getArrayIndex()
109
110 # Get sensor geometry information
111 sensor_info = Belle2.VXD.GeoCache.getInstance().getSensorInfo(vxd_id)
112 thickness = sensor_info.getThickness()
113
114 # TrueHit information
115 self.data.truehit_u = truehit.getU()
116 self.data.truehit_v = truehit.getV()
117 self.data.truehit_time = truehit.getGlobalTime()
118 self.data.truehit_charge = truehit.getEnergyDep()
119 self.data.theta_u = math.atan2(
120 truehit.getExitU() - truehit.getEntryU(), thickness)
121 self.data.theta_v = math.atan2(
122 truehit.getExitV() - truehit.getEntryV(), thickness)
123 # Cluster information
124 self.data.cluster_u = cluster.getU()
125 self.data.cluster_v = cluster.getV()
126 self.data.cluster_uError = cluster.getUSigma()
127 self.data.cluster_vError = cluster.getVSigma()
128 self.data.cluster_rho = cluster.getRho()
129 self.data.cluster_charge = cluster.getCharge()
130 self.data.cluster_seed = cluster.getSeedCharge()
131 self.data.cluster_size = cluster.getSize()
132 self.data.cluster_uSize = cluster.getUSize()
133 self.data.cluster_vSize = cluster.getVSize()
134 self.data.cluster_uPull = (
135 cluster.getU() - truehit.getU()) / cluster.getUSigma()
136 self.data.cluster_vPull = (
137 cluster.getV() - truehit.getV()) / cluster.getVSigma()
138 self.file.cd()
139 self.tree.Fill()
140
141 def terminate(self):
142 """ Close the output file."""
143
144 self.file.cd()
145 self.file.Write()
146 self.file.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
data
Instance of EventData class.