Belle II Software development
SVDValidationTTreeCluster Class Reference
Inheritance diagram for SVDValidationTTreeCluster:

Public Member Functions

 __init__ (self)
 
 event (self)
 
 terminate (self)
 

Public Attributes

 file = ROOT.TFile('../SVDValidationTTreeCluster.root', 'recreate')
 Output ROOT file.
 
 tree = ROOT.TTree('tree', 'Event data of SVD validation events')
 TTree for output data.
 
 data = EventDataCluster()
 instance of EventData class
 

Detailed Description

class to produce the ttree for cluster reconstruction validation

Definition at line 71 of file SVDValidationTTreeCluster.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self)
Initialize the module

Definition at line 74 of file SVDValidationTTreeCluster.py.

74 def __init__(self):
75 """Initialize the module"""
76
77 super().__init__()
78
79
80 self.file = ROOT.TFile('../SVDValidationTTreeCluster.root', 'recreate')
81
82 self.tree = ROOT.TTree('tree', 'Event data of SVD validation events')
83
84 self.data = EventDataCluster()
85
86 # Declare tree branches
87 for key in EventDataCluster.__dict__:
88 if '__' not in key:
89 formstring = '/F'
90 if isinstance(self.data.__getattribute__(key), int):
91 formstring = '/I'
92 self.tree.Branch(key, addressof(self.data, key), key + formstring)
93

Member Function Documentation

◆ event()

event ( self)
 Find clusters with a truehit and save needed information 

Definition at line 94 of file SVDValidationTTreeCluster.py.

94 def event(self):
95 """ Find clusters with a truehit and save needed information """
96 clusters = Belle2.PyStoreArray('SVDClusters')
97 eventt0 = Belle2.PyStoreObj('EventT0')
98
99 # get EventT0: combined, TOP, CDC, ECL
100 self.data.eventt0_all = -1
101 self.data.eventt0_top = -1
102 self.data.eventt0_cdc = -1
103 self.data.eventt0_ecl = -1
104 self.data.eventt0_svd = -1
105 top = Belle2.Const.DetectorSet(Belle2.Const.TOP)
106 cdc = Belle2.Const.DetectorSet(Belle2.Const.CDC)
107 ecl = Belle2.Const.DetectorSet(Belle2.Const.ECL)
108 svd = Belle2.Const.DetectorSet(Belle2.Const.SVD)
109 if eventt0.hasEventT0():
110 self.data.eventt0_all = eventt0.getEventT0()
111 if eventt0.hasTemporaryEventT0(svd):
112 tmp = eventt0.getTemporaryEventT0s(Belle2.Const.SVD)
113 self.data.eventt0_svd = tmp.back().eventT0
114 if eventt0.hasTemporaryEventT0(cdc):
115 tmp = eventt0.getTemporaryEventT0s(Belle2.Const.CDC)
116 self.data.eventt0_cdc = tmp.back().eventT0
117 if eventt0.hasTemporaryEventT0(top):
118 tmp = eventt0.getTemporaryEventT0s(Belle2.Const.TOP)
119 self.data.eventt0_top = tmp.back().eventT0
120 if eventt0.hasTemporaryEventT0(ecl):
121 evtT0List_ECL = eventt0.getTemporaryEventT0s(Belle2.Const.ECL)
122 # Select the event t0 value from the ECL as the one with the smallest chi squared value (defined as ".quality")
123 smallest_ECL_t0_minChi2 = evtT0List_ECL[0].quality
124 self.data.eventt0_ecl = evtT0List_ECL[0].eventT0
125 for tmp in evtT0List_ECL:
126 if tmp.quality < smallest_ECL_t0_minChi2:
127 smallest_ECL_t0_minChi2 = tmp.quality
128 self.data.eventt0_ecl = tmp.eventT0
129
130 for cluster in clusters:
131
132 cluster_truehits = cluster.getRelationsTo('SVDTrueHits')
133
134 # Sensor identification
135 sensorInfo = Belle2.VXD.GeoCache.getInstance().getSensorInfo(cluster.getSensorID())
136 sensorID = cluster.getSensorID()
137 self.data.sensor_id = int(sensorID)
138 sensorNum = sensorID.getSensorNumber()
139 self.data.sensor = sensorNum
140 layerNum = sensorID.getLayerNumber()
141 self.data.layer = layerNum
142 if (layerNum == 3):
143 sensorType = 1
144 else:
145 if (sensorNum == 1):
146 sensorType = 0
147 else:
148 sensorType = 1
149 self.data.sensor_type = sensorType
150 ladderNum = sensorID.getLadderNumber()
151 self.data.ladder = ladderNum
152 if cluster.isUCluster():
153 strip_dir = 0
154 else:
155 strip_dir = 1
156
157 self.data.matched = 1
158 # We want only clusters with at least one associated TrueHit
159 # but, to compute purity, we need to store also some information
160 # for clusters not related to true hits
161 if len(cluster_truehits) == 0:
162 self.data.matched = 0
163 # Fill tree
164 self.file.cd()
165 self.tree.Fill()
166 continue
167
168 # find the trueHit with highest energy deposit (the "best" match)
169 energy = 0
170 bestTrueHitIndex = 0
171 for i, trueHit in enumerate(cluster_truehits):
172 if trueHit.getEnergyDep() > energy:
173 energy = trueHit.getEnergyDep()
174 bestTrueHitIndex = i
175 bestTrueHit = cluster_truehits[bestTrueHitIndex]
176
177 # Cluster information
178 self.data.cluster_clsTime = cluster.getClsTime()
179 self.data.cluster_clsTimeSigma = cluster.getClsTimeSigma()
180 self.data.cluster_charge = cluster.getCharge()
181 self.data.cluster_seedCharge = cluster.getSeedCharge()
182 self.data.cluster_size = cluster.getSize()
183 self.data.cluster_snr = cluster.getSNR()
184 cluster_position = cluster.getPosition()
185 if cluster.isUCluster():
186 cluster_position = cluster.getPosition(bestTrueHit.getV())
187 # Interstrip position calculations
188 strip_pitch = sensorInfo.getUPitch(bestTrueHit.getV())
189 else:
190 strip_pitch = sensorInfo.getVPitch(bestTrueHit.getU())
191 self.data.strip_dir = strip_dir
192 self.data.strip_pitch = strip_pitch
193 self.data.cluster_interstripPosition = cluster_position % strip_pitch / strip_pitch
194 # theta and phi definitions
195 if cluster.isUCluster():
196 uPos = cluster_position
197 vPos = 0
198 else:
199 uPos = 0
200 vPos = cluster_position
201 localPosition = Math.XYZVector(uPos, vPos, 0) # sensor center at (0, 0, 0)
202 globalPosition = sensorInfo.pointToGlobal(localPosition, True)
203 x = globalPosition.X()
204 y = globalPosition.Y()
205 z = globalPosition.Z()
206 # see https://d2comp.kek.jp/record/242?ln=en for the Belle II
207 # coordinate system and related variables
208 rho = math.sqrt(x * x + y * y)
209 r = math.sqrt(x * x + y * y + z * z)
210 # get theta as arccosine(z/r)
211 thetaRadians = math.acos(z / r)
212 theta = (thetaRadians * 180) / math.pi
213 # get phi as arccosine(x/rho)
214 phiRadians = math.acos(x / rho)
215 if y < 0:
216 phi = 360 - (phiRadians * 180) / math.pi
217 else:
218 phi = (phiRadians * 180) / math.pi
219 self.data.cluster_theta = theta
220 self.data.cluster_phi = phi
221 # Pull calculations
222 clusterPos = cluster_position
223 clusterPosSigma = cluster.getPositionSigma()
224 if cluster.isUCluster():
225 truehitPos = bestTrueHit.getU()
226 else:
227 truehitPos = bestTrueHit.getV()
228 cluster_residual = clusterPos - truehitPos
229 cluster_pull = cluster_residual / clusterPosSigma
230 self.data.cluster_position = clusterPos
231 self.data.cluster_positionSigma = clusterPosSigma
232 self.data.cluster_residual = cluster_residual
233 self.data.cluster_pull = cluster_pull
234 # Truehit information
235 self.data.truehit_position = truehitPos
236 truehit_interstripPosition = truehitPos % strip_pitch / strip_pitch
237 self.data.truehit_interstripPosition = truehit_interstripPosition
238 self.data.truehit_deposEnergy = bestTrueHit.getEnergyDep()
239 self.data.truehit_lossmomentum = bestTrueHit.getEntryMomentum().R() - bestTrueHit.getExitMomentum().R()
240 self.data.truehit_time = bestTrueHit.getGlobalTime()
241
242 # DEBUG options, commented out
243 # print("\n new cluster with at least one true hit ("+str(len(cluster_truehits))+")")
244 # print("best True hit has energy = "+str(bestTrueHit.getEnergyDep()*1e6)+" eV,\
245 # global time = "+str(bestTrueHit.getGlobalTime()))
246 # print("cluster isU = "+str(cluster.isUCluster())+", size = "+str(self.data.cluster_size)+"\
247 # position = "+str(clusterPos))
248 # print("cluster charge = "+str(self.data.cluster_charge)+", time = "+str(self.data.cluster_clsTime))
249
250 # Fill tree
251 self.file.cd()
252 self.tree.Fill()
253
The DetectorSet class for sets of detector IDs in the form of EDetector values.
Definition Const.h:80
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
Definition PyStoreObj.h:67
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition GeoCache.cc:214

◆ terminate()

terminate ( self)
Close the output file. 

Definition at line 254 of file SVDValidationTTreeCluster.py.

254 def terminate(self):
255 """Close the output file. """
256 self.file.cd()
257 self.file.Write()
258 self.file.Close()

Member Data Documentation

◆ data

data = EventDataCluster()

instance of EventData class

Definition at line 84 of file SVDValidationTTreeCluster.py.

◆ file

file = ROOT.TFile('../SVDValidationTTreeCluster.root', 'recreate')

Output ROOT file.

Definition at line 80 of file SVDValidationTTreeCluster.py.

◆ tree

tree = ROOT.TTree('tree', 'Event data of SVD validation events')

TTree for output data.

Definition at line 82 of file SVDValidationTTreeCluster.py.


The documentation for this class was generated from the following file: