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