Belle II Software development
trackingInputValidationBkg.py
1#!/usr/bin/env python3
2
3
10
11"""
12<header>
13 <contact>software-tracking@belle2.org</contact>
14 <input>EvtGenSim.root</input>
15 <output>TrackingInputValidationBkg.root</output>
16 <description>
17 This module checks the number of input hits for tracking.
18 </description>
19</header>
20"""
21
22from tracking.validation.plot import ValidationPlot
23from ROOT import Belle2
24import collections
25import ROOT
26import basf2
27from svd import add_svd_reconstruction
28from pxd import add_pxd_reconstruction
29NAME = 'Tracking Input Validation' # not used?
30CONTACT = 'software-tracking@belle2.org'
31INPUT_FILE = '../EvtGenSim.root'
32OUTPUT_FILE = 'TrackingInputValidationBkg.root'
33N_EVENTS = 1000
34
35ACTIVE = True
36
37
38def run():
39 """
40 Check the number of hits that are the input for tracking.
41 """
42 class TrackingInputValidation(basf2.Module):
43 """
44 Module to collect information about the number of
45 * PXDDigits
46 * PXDClusters
47 * PXDSpacePoints
48 * SVDShaperDigits
49 * SVDClusters
50 * SVDSpacePoints
51 * CDCHits
52 """
53
54 def __init__(
55 self,
56 name='',
57 contact='',
58 output_file_name=None,
59 ):
60 """Constructor"""
61
62 super().__init__()
63
64 self.validation_name = NAME
65
66 self.contact = CONTACT
67
68 self.output_file_name = OUTPUT_FILE
69
70 def initialize(self):
71 """Receive signal at the start of event processing"""
72
73
74 self.PXDDigits = Belle2.PyStoreArray('PXDDigits')
75
76 self.PXDClusters = Belle2.PyStoreArray('PXDClusters')
77
78 self.PXDSpacePoints = Belle2.PyStoreArray('PXDSpacePoints')
79
80
81 self.SVDShaperDigits = Belle2.PyStoreArray('SVDShaperDigits')
82
83 self.SVDClusters = Belle2.PyStoreArray('SVDClusters')
84
85 self.SVDSpacePoints = Belle2.PyStoreArray('SVDSpacePoints')
86
87
88 self.CDCHits = Belle2.PyStoreArray('CDCHits')
89
90
91 self.nPXDDigits = collections.deque()
92
93 self.nPXDClusters = collections.deque()
94
95 self.nPXDSpacePoints = collections.deque()
96
97
98 self.nSVDShaperDigits = collections.deque()
99
100 self.nSVDClusters = collections.deque()
101
102 self.nSVDSpacePoints = collections.deque()
103
104
105 self.nCDCHits = collections.deque()
106
107 def event(self):
108 '''Event function'''
109
110 self.nPXDDigits.append(self.PXDDigits.getEntries())
111 self.nPXDClusters.append(self.PXDClusters.getEntries())
112 self.nPXDSpacePoints.append(self.PXDSpacePoints.getEntries())
113 self.nSVDShaperDigits.append(self.SVDShaperDigits.getEntries())
114 self.nSVDClusters.append(self.SVDClusters.getEntries())
115 self.nSVDSpacePoints.append(self.SVDSpacePoints.getEntries())
116 self.nCDCHits.append(self.CDCHits.getEntries())
117
118 def terminate(self):
119 """Receive signal at the end of event processing"""
120
121 ''' Saving'''
122 output_tfile = ROOT.TFile(self.output_file_name, 'recreate')
123
124 h_nPXDDigits = ValidationPlot('h_nPXDDigits')
125 h_nPXDDigits.hist(self.nPXDDigits, bins=100, lower_bound=0, upper_bound=2000)
126 h_nPXDDigits.contact = self.contact
127 h_nPXDDigits.check = 'Average of 500 +/- 100 is expected.'
128 h_nPXDDigits.description = 'Number of PXDDigits after ROI filtering'
129 h_nPXDDigits.title = 'Number of selected PXDDigits per event'
130 h_nPXDDigits.xlabel = 'Number of PXDDigits'
131 h_nPXDDigits.ylabel = ''
132 h_nPXDDigits.write(output_tfile)
133
134 h_nPXDClusters = ValidationPlot('h_nPXDClusters')
135 h_nPXDClusters.hist(self.nPXDClusters, bins=100, lower_bound=0, upper_bound=500)
136 h_nPXDClusters.contact = self.contact
137 h_nPXDClusters.check = 'Average of 150 +/- 30 is expected'
138 h_nPXDClusters.description = 'Number of PXDClusters after ROI filtering.'
139 h_nPXDClusters.title = 'Number of PXDClusters per event'
140 h_nPXDClusters.xlabel = 'Number of PXDClusters'
141 h_nPXDClusters.ylabel = ''
142 h_nPXDClusters.write(output_tfile)
143
144 h_nPXDSpacePoints = ValidationPlot('h_nPXDSpacePoints')
145 h_nPXDSpacePoints.hist(self.nPXDSpacePoints, bins=100, lower_bound=0, upper_bound=500)
146 h_nPXDSpacePoints.contact = self.contact
147 h_nPXDSpacePoints.check = 'Average of 150 +/- 30 is expected'
148 h_nPXDSpacePoints.description = 'Number of PXDSpacePoints after ROI filtering. \
149 Should be the same as the number of PXDClusters.'
150 h_nPXDSpacePoints.title = 'Number of PXDSpacePoints per event'
151 h_nPXDSpacePoints.xlabel = 'Number of PXDSpacePoints'
152 h_nPXDSpacePoints.ylabel = ''
153 h_nPXDSpacePoints.write(output_tfile)
154
155 h_nSVDShaperDigits = ValidationPlot('h_nSVDShaperDigits')
156 h_nSVDShaperDigits.hist(self.nSVDShaperDigits, bins=100, lower_bound=0, upper_bound=10000)
157 h_nSVDShaperDigits.contact = self.contact
158 h_nSVDShaperDigits.check = 'First peak at about 5500 +/- 200 is expected.'
159 h_nSVDShaperDigits.description = 'Number of SVDDigits'
160 h_nSVDShaperDigits.title = 'Number of SVDDigits per event'
161 h_nSVDShaperDigits.xlabel = 'Number of SVDDigits'
162 h_nSVDShaperDigits.ylabel = ''
163 h_nSVDShaperDigits.write(output_tfile)
164
165 h_nSVDClusters = ValidationPlot('h_nSVDClusters')
166 h_nSVDClusters.hist(self.nSVDClusters, bins=100, lower_bound=0, upper_bound=2000)
167 h_nSVDClusters.contact = self.contact
168 h_nSVDClusters.check = 'Average of 1100 +/- 100 is expected.'
169 h_nSVDClusters.description = 'Number of SVDClusters'
170 h_nSVDClusters.title = 'Number of SVDClusters per event'
171 h_nSVDClusters.xlabel = 'Number of SVDClusters'
172 h_nSVDClusters.ylabel = ''
173 h_nSVDClusters.write(output_tfile)
174
175 h_nSVDSpacePoints = ValidationPlot('h_nSVDSpacePoints')
176 h_nSVDSpacePoints.hist(self.nSVDSpacePoints, bins=100, lower_bound=0, upper_bound=2000)
177 h_nSVDSpacePoints.contact = self.contact
178 h_nSVDSpacePoints.check = 'Average of 200 +/- 50 is expected.'
179 h_nSVDSpacePoints.description = 'Number of SVDSpacePoints'
180 h_nSVDSpacePoints.title = 'Number of SVDSpacePoints per event'
181 h_nSVDSpacePoints.xlabel = 'Number of SVDSpacePoints'
182 h_nSVDSpacePoints.ylabel = ''
183 h_nSVDSpacePoints.write(output_tfile)
184
185 h_nCDCHits = ValidationPlot('h_nCDCHits')
186 h_nCDCHits.hist(self.nCDCHits, bins=100, lower_bound=0, upper_bound=6000)
187 h_nCDCHits.contact = self.contact
188 h_nCDCHits.check = 'Average of 3500 +/- 200 is expected.'
189 h_nCDCHits.description = 'Number of CDCHits'
190 h_nCDCHits.title = 'Number of CDCHits per event'
191 h_nCDCHits.xlabel = 'Number of CDCHits'
192 h_nCDCHits.ylabel = ''
193 h_nCDCHits.write(output_tfile)
194
195 output_tfile.Close()
196
197 """ Steering """
198 basf2.set_random_seed(1509)
199
200 path = basf2.create_path()
201
202 path.add_module('RootInput', inputFileName=INPUT_FILE)
203 path.add_module('Gearbox')
204 path.add_module('Geometry')
205 add_svd_reconstruction(path, isROIsimulation=False)
206 add_pxd_reconstruction(path)
207
208 path.add_module(TrackingInputValidation())
209
210 path.add_module('Progress')
211
212 print(path)
213 basf2.process(path)
214 print(basf2.statistics)
215
216
217if __name__ == '__main__':
218 if ACTIVE:
219 run()
220 else:
221 print("This validation deactivated and thus basf2 is not executed.\n"
222 "If you want to run this validation, please set the 'ACTIVE' flag above to 'True'.\n"
223 "Exiting.")
A (simplified) python wrapper for StoreArray.
Definition: PyStoreArray.h:72