Belle II Software development
svdCoGCalibrationAnalysisToolModule.py
1#!/usr/bin/env python
2
3
10
11import basf2 as b2
12from ROOT import Belle2, TFile, TTree, gROOT
13import numpy
14
15
16import numpy as np
17
18import sys
19
20inputFile = sys.argv[1]
21outputFile = sys.argv[2]
22time0 = "EventT0"
23svd_Clusters = "SVDClusters"
24svd_ClustersFromTracks = "SVDClustersFromTracks"
25svd_EventInfo = "SVDEventInfo"
26svd_EventMD = "EventMetaData"
27
28b2.set_random_seed(11)
29
30gROOT.SetBatch(True)
31
32
34 """
35 Class used to check the goodness of the CoG time calibration
36 """
37
38 def initialize(self):
39 """
40 Initialize object (histograms, lists, ...) used by the class
41 """
42
43 self.outputFileName = outputFile
44
45 self.layer = np.zeros(1, dtype=int)
46
47 self.ladder = np.zeros(1, dtype=int)
48
49 self.sensor = np.zeros(1, dtype=int)
50
51 self.side = np.zeros(1, dtype=int)
52
53 self.TB = np.zeros(1, dtype=int)
54
55 self.evtTime = np.zeros(1, dtype=float)
56
57 self.evtTimeSync = np.zeros(1, dtype=float)
58
59 self.clsTime = np.zeros(1, dtype=float)
60
61 self.clsSize = np.zeros(1, dtype=float)
62
63 self.clsCharge = np.zeros(1, dtype=float)
64
65 self.clsSNR = np.zeros(1, dtype=float)
66
67 self.run = np.zeros(1, dtype=int)
68
69 self.exp = np.zeros(1, dtype=int)
70
71
72 self.layerTracks = np.zeros(1, dtype=int)
73
74 self.ladderTracks = np.zeros(1, dtype=int)
75
76 self.sensorTracks = np.zeros(1, dtype=int)
77
78 self.sideTracks = np.zeros(1, dtype=int)
79
80 self.evtTimeTracks = np.zeros(1, dtype=float)
81
82 self.evtTimeSyncTracks = np.zeros(1, dtype=float)
83
84 self.clsTimeTracks = np.zeros(1, dtype=float)
85
86 self.clsSizeTracks = np.zeros(1, dtype=float)
87
88 self.clsChargeTracks = np.zeros(1, dtype=float)
89
90 self.clsSNRTracks = np.zeros(1, dtype=float)
91
92 # self.tFile = TFile(self.outputFileName, 'recreate')
93 # self.tFile.cd()
94
95
96 self.tree = TTree('cls', 'tree')
97
98 self.tree.Branch('layer', self.layer, 'layer/I')
99
100 self.tree.Branch('ladder', self.ladder, 'ladder/I')
101
102 self.tree.Branch('sensor', self.sensor, 'sensor/I')
103
104 self.tree.Branch('side', self.side, 'side/I')
105
106 self.tree.Branch('tb', self.TB, 'tb/I')
107
108 self.tree.Branch('evtT0', self.evtTime, 'evtT0/D')
109
110 self.tree.Branch('evtT0Sync', self.evtTimeSync, 'evtT0Sync/D')
111
112 self.tree.Branch('clsTime', self.clsTime, 'clsTime/D')
113
114 self.tree.Branch('clsSize', self.clsSize, 'clsSize/D')
115
116 self.tree.Branch('clsCharge', self.clsCharge, 'clsCharge/D')
117
118 self.tree.Branch('clsSNR', self.clsSNR, 'clsSNR/D')
119
120 self.tree.Branch('run', self.run, 'run/I')
121
122 self.tree.Branch('exp', self.exp, 'exp/I')
123
124
125 self.treeTracks = TTree('clsTracks', 'treeTracks')
126
127 self.treeTracks.Branch('layer', self.layerTracks, 'layer/I')
128
129 self.treeTracks.Branch('ladder', self.ladderTracks, 'ladder/I')
130
131 self.treeTracks.Branch('sensor', self.sensorTracks, 'sensor/I')
132
133 self.treeTracks.Branch('side', self.sideTracks, 'side/I')
134
135 self.treeTracks.Branch('tb', self.TB, 'tb/I')
136
137 self.treeTracks.Branch('evtT0', self.evtTimeTracks, 'evtT0/D')
138
139 self.treeTracks.Branch('evtT0Sync', self.evtTimeSyncTracks, 'evtT0Sync/D')
140
141 self.treeTracks.Branch('clsTime', self.clsTimeTracks, 'clsTime/D')
142
143 self.treeTracks.Branch('clsSize', self.clsSizeTracks, 'clsSize/D')
144
145 self.treeTracks.Branch('clsCharge', self.clsChargeTracks, 'clsCharge/D')
146
147 self.treeTracks.Branch('clsSNR', self.clsSNRTracks, 'clsSNR/D')
148
149 self.treeTracks.Branch('run', self.run, 'run/I')
150
151 self.treeTracks.Branch('exp', self.exp, 'exp/I')
152
153 def event(self):
154 """
155 Function that allows to cicle on the events
156 """
157 svd_cls = Belle2.PyStoreArray(svd_Clusters)
158 svd_clsFromTrks = Belle2.PyStoreArray(svd_ClustersFromTracks)
159 et0 = Belle2.PyStoreObj(time0)
160 svd_evtInfo = Belle2.PyStoreObj(svd_EventInfo)
161 clsTB = svd_evtInfo.getModeByte().getTriggerBin()
162 self.TB[0] = ord(clsTB)
163 svd_evtMD = Belle2.PyStoreObj(svd_EventMD)
164 self.run[0] = svd_evtMD.getRun()
165 self.exp[0] = svd_evtMD.getExperiment()
166
167 for svdCluster in svd_cls:
168 self.clsTime[0] = svdCluster.getClsTime()
169 self.clsSize[0] = svdCluster.getSize()
170 self.clsCharge[0] = svdCluster.getCharge()
171 self.clsSNR[0] = svdCluster.getSNR()
172 self.layer[0] = svdCluster.getSensorID().getLayerNumber()
173 self.ladder[0] = svdCluster.getSensorID().getLadderNumber()
174 self.sensor[0] = svdCluster.getSensorID().getSensorNumber()
175 self.side[0] = svdCluster.isUCluster()
176
177 self.ftswShift = svd_evtInfo.getSVD2FTSWTimeShift(svdCluster.getFirstFrame())
178 hasT0 = et0.hasEventT0()
179 if hasT0:
180 self.evtTime[0] = et0.getEventT0()
181 self.evtTimeSync[0] = et0.getEventT0() - self.ftswShift
182 else:
183 self.evtTime[0] = -999
184 self.evtTimeSync[0] = -999
185 self.tree.Fill()
186
187 for svdClusterTracks in svd_clsFromTrks:
188 self.clsTimeTracks[0] = svdClusterTracks.getClsTime()
189 self.clsSizeTracks[0] = svdClusterTracks.getSize()
190 self.clsChargeTracks[0] = svdClusterTracks.getCharge()
191 self.clsSNRTracks[0] = svdClusterTracks.getSNR()
192 self.layerTracks[0] = svdClusterTracks.getSensorID().getLayerNumber()
193 self.ladderTracks[0] = svdClusterTracks.getSensorID().getLadderNumber()
194 self.sensorTracks[0] = svdClusterTracks.getSensorID().getSensorNumber()
195 self.sideTracks[0] = svdClusterTracks.isUCluster()
196
197 self.ftswShiftTracks = svd_evtInfo.getSVD2FTSWTimeShift(svdCluster.getFirstFrame())
198 hasT0 = et0.hasEventT0()
199 if hasT0:
200 self.evtTimeTracks[0] = et0.getEventT0()
201 self.evtTimeSyncTracks[0] = et0.getEventT0() - self.ftswShiftTracks
202 else:
203 self.evtTimeTracks[0] = -999
204 self.evtTimeSyncTracks[0] = -999
205 self.treeTracks.Fill()
206
207 def terminate(self):
208 """
209 Terminates te class and produces the output rootfile
210 """
211
212 self.tFile = TFile(self.outputFileName, 'recreate')
213 self.tFile.cd()
214 self.tree.Write()
215 self.treeTracks.Write()
216 self.tFile.Close()
217 del self.tFile
218
219# conditions.override_globaltags()
220# conditions.globaltags = ["online"]
221
222
223main = b2.create_path()
224
225rootinput = b2.register_module('RootInput')
226rootinput.param('inputFileName', inputFile)
227main.add_module(rootinput)
228
229# main.add_module("Gearbox")
230# main.add_module("Geometry", useDB = True)
231
232main.add_module(svdCoGCalibrationAnalysisTool())
233
234# Show progress of processing
235progress = b2.register_module('Progress')
236main.add_module(progress)
237
238# Process events
239b2.process(main)
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
ladderTracks
ladder array for the tree for clusters associated to tracks
clsSizeTracks
cluster size array for the tree for clusters associated to tracks
evtTimeSyncTracks
T0Sync array for the tree for clusters associated to tracks.
clsSNRTracks
cluster SNR array for the tree for clusters associated to tracks
sensorTracks
sensor array for the tree for clusters associated to tracks
clsChargeTracks
cluster charge array for the tree for clusters associated to tracks
clsTimeTracks
cluster time array for the tree for clusters associated to tracks