Belle II Software development
__init__.py
1#!/usr/bin/env python3
2
3
10
11import basf2 as b2
12
13
14def add_svd_reconstruction(path, isROIsimulation=False, createRecoDigits=False, applyMasking=False):
15 """
16 Adds the SVD reconstruction to the path.
17
18 Reconstruction starts with :ref:`SVDShaperDigits<svdshapers>`
19 and :ref:`SVDEventInfo<svdeventinfo>` and provides
20 :ref:`SVDClusters<svdclusters>` and :ref:`SVDSpacePoints<svdsps>`.
21
22 @param path: add the modules to this basf2 path.
23 @param isROIsimulation: SVD reconstruction can be run during simulation\
24 in order to simulate the PXD Data Reduction with ROI finding.
25 @param createRecoDigits: if True, :ref:`SVDRecoDigits<svdrecos>` are created.
26 @param applyMasking: if True, hot strips found in :ref:`SVDHotStripsCalibration<svdhotstrips>` are masked.
27 """
28
29 # setup the event level tracking info to log errors and stuff
30 if isROIsimulation:
31 nameTrackingInfoModule = "RegisterEventLevelTrackingInfo__ROI"
32 nameEventTrackingInfo = "EventLevelTrackingInfo__ROI"
33 nameSVDTrackingEventLevelMdstInfoFiller = "SVDTrackingEventLevelMdstInfoFiller__ROI"
34 else:
35 nameTrackingInfoModule = "RegisterEventLevelTrackingInfo"
36 nameEventTrackingInfo = "EventLevelTrackingInfo"
37 nameSVDTrackingEventLevelMdstInfoFiller = "SVDTrackingEventLevelMdstInfoFiller"
38
39 if nameTrackingInfoModule not in path:
40 registerEventlevelTrackingInfo = b2.register_module('RegisterEventLevelTrackingInfo')
41 registerEventlevelTrackingInfo.set_name(nameTrackingInfoModule)
42 registerEventlevelTrackingInfo.param('EventLevelTrackingInfoName', nameEventTrackingInfo)
43 path.add_module(registerEventlevelTrackingInfo)
44
45 if(isROIsimulation):
46 clusterizerName = '__ROISVDClusterizer'
47 timeGroupComposerName = '__ROISVDTimeGrouping'
48 recocreatorName = '__ROISVDRecoDigitCreator'
49 dataFormatName = '__ROISVDDataFormat'
50 # recoDigitsName = '__ROIsvdRecoDigits'
51 clustersName = '__ROIsvdClusters'
52 shaperDigitsName = ""
53 missingAPVsClusterCreatorName = '__ROISVDMissingAPVsClusterCreator'
54 else:
55 clusterizerName = 'SVDClusterizer'
56 timeGroupComposerName = 'SVDTimeGrouping'
57 recocreatorName = 'SVDRecoDigitCreator'
58 dataFormatName = 'SVDDataFormat'
59 # recoDigitsName = ""
60 clustersName = ""
61 shaperDigitsName = ""
62 missingAPVsClusterCreatorName = 'SVDMissingAPVsClusterCreator'
63
64 # mask HotStrips from SVDHotStripsCalibration payloads
65 if(applyMasking):
66 if(isROIsimulation):
67 shaperDigitsName = '__ROISVDShaperDigitsUnmasked'
68 maskingName = '__ROISVDStripMasking'
69 else:
70 shaperDigitsName = 'SVDShaperDigitsUnmasked'
71 maskingName = 'SVDStripMasking'
72
73 if maskingName not in [e.name() for e in path.modules()]:
74 masking = b2.register_module('SVDStripMasking')
75 masking.set_name(maskingName)
76 masking.param('ShaperDigitsUnmasked', shaperDigitsName)
77 path.add_module(masking)
78
79 # data format check NOT appended
80 if dataFormatName not in [e.name() for e in path.modules()]:
81 dataFormat = b2.register_module('SVDDataFormatCheck')
82 dataFormat.param('ShaperDigits', shaperDigitsName)
83
84 if clusterizerName not in [e.name() for e in path.modules()]:
85 clusterizer = b2.register_module('SVDClusterizer')
86 clusterizer.set_name(clusterizerName)
87 clusterizer.param('ShaperDigits', shaperDigitsName)
88 clusterizer.param('Clusters', clustersName)
89 path.add_module(clusterizer)
90
91 if missingAPVsClusterCreatorName not in [e.name() for e in path.modules()]:
92 missingAPVCreator = b2.register_module('SVDMissingAPVsClusterCreator')
93 missingAPVCreator.set_name(missingAPVsClusterCreatorName)
94 path.add_module(missingAPVCreator)
95
96 if nameSVDTrackingEventLevelMdstInfoFiller not in path:
97 svdTrackingEventLevelMdstInfoFiller = b2.register_module('SVDTrackingEventLevelMdstInfoFiller')
98 svdTrackingEventLevelMdstInfoFiller.set_name(nameSVDTrackingEventLevelMdstInfoFiller)
99 svdTrackingEventLevelMdstInfoFiller.param('EventLevelTrackingInfoName', nameEventTrackingInfo)
100 svdTrackingEventLevelMdstInfoFiller.param('svdClustersName', clustersName)
101 path.add_module(svdTrackingEventLevelMdstInfoFiller)
102
103 if timeGroupComposerName not in [e.name() for e in path.modules()]:
104 svdTimeGrouping = b2.register_module('SVDTimeGrouping')
105 svdTimeGrouping.set_name(timeGroupComposerName)
106 svdTimeGrouping.param('SVDClusters', clustersName)
107 path.add_module(svdTimeGrouping)
108
109 # Add SVDSpacePointCreator
110 add_svd_SPcreation(path, isROIsimulation)
111
112 if createRecoDigits and not isROIsimulation:
113 # Add SVDRecoDigit creator module if not ROI simulation
114 # useful for SVD performance studies
115 add_svd_create_recodigits(path, recocreatorName, shaperDigitsName)
116
117
118def add_svd_create_recodigits(path, recocreatorName="SVDRecoDigitCreator", shaperDigitsName=""):
119 """
120 Adds the strip reconstruction to the path.
121
122 Produce :ref:`SVDRecoDigits<svdrecos>` from :ref:`SVDShaperDigits<svdshapers>`.
123
124 @param path: add the modules to this basf2 path.
125 @param recocreatorName: name of the module.
126 @param shaperDigitsName: name of the SVDShaperDigits StoreArray.
127 """
128
129 if recocreatorName not in [e.name() for e in path.modules()]:
130 recoDigitCreator = b2.register_module('SVDRecoDigitCreator')
131 recoDigitCreator.param('ShaperDigits', shaperDigitsName)
132 recoDigitCreator.param('timeAlgorithm6Samples', "CoG3")
133 recoDigitCreator.param('timeAlgorithm3Samples', "CoG3")
134 recoDigitCreator.param('chargeAlgorithm6Samples', "MaxSample")
135 recoDigitCreator.param('chargeAlgorithm3Samples', "MaxSample")
136 recoDigitCreator.param('useDB', False)
137 path.add_module(recoDigitCreator)
138
139
140def add_rel5_svd_reconstruction(path, isROIsimulation=False, applyMasking=False):
141 """
142 Adds the old (up to release-05) SVD recontruction to the path.
143
144 Reconstruction starts with :ref:`SVDShaperDigits<svdshapers>` and
145 :ref:`SVDEventInfo<svdeventinfo>` and provides :ref:`SVDClusters<svdclusters>`
146 and :ref:`SVDSpacePoints<svdsps>`.
147
148 @param path: add the modules to this basf2 path.
149 @param isROIsimulation: SVD reconstruction can be run during simulation\
150 in order to simulate the PXD Data Reduction with ROI finding.
151 @param applyMasking: if True, hot strips found in :ref:`SVDHotStripsCalibration<svdhotstrips>` are masked.
152 """
153
154 # setup the event level tracking info to log errors and stuff
155 if isROIsimulation:
156 nameTrackingInfoModule = "RegisterEventLevelTrackingInfo__ROI"
157 nameEventTrackingInfo = "EventLevelTrackingInfo__ROI"
158 nameSVDTrackingEventLevelMdstInfoFiller = "SVDTrackingEventLevelMdstInfoFiller__ROI"
159 else:
160 nameTrackingInfoModule = "RegisterEventLevelTrackingInfo"
161 nameEventTrackingInfo = "EventLevelTrackingInfo"
162 nameSVDTrackingEventLevelMdstInfoFiller = "SVDTrackingEventLevelMdstInfoFiller"
163
164 if nameTrackingInfoModule not in path:
165 registerEventlevelTrackingInfo = b2.register_module('RegisterEventLevelTrackingInfo')
166 registerEventlevelTrackingInfo.set_name(nameTrackingInfoModule)
167 registerEventlevelTrackingInfo.param('EventLevelTrackingInfoName', nameEventTrackingInfo)
168 path.add_module(registerEventlevelTrackingInfo)
169
170 if(isROIsimulation):
171 fitterName = '__ROISVDCoGTimeEstimator'
172 clusterizerName = '__ROISVDSimpleClusterizer'
173 timeGroupComposerName = '__ROISVDTimeGrouping'
174 dataFormatName = '__ROISVDDataFormat'
175 clusterName = '__ROIsvdClusters'
176 recoDigitsName = '__ROIsvdRecoDigits'
177 shaperDigitsName = ""
178 missingAPVsClusterCreatorName = '__ROISVDMissingAPVsClusterCreator'
179 else:
180 fitterName = 'SVDCoGTimeEstimator'
181 clusterizerName = 'SVDSimpleClusterizer'
182 timeGroupComposerName = 'SVDTimeGrouping'
183 dataFormatName = 'SVDDataFormat'
184 clusterName = ""
185 recoDigitsName = ""
186 shaperDigitsName = ""
187 missingAPVsClusterCreatorName = 'SVDMissingAPVsClusterCreator'
188
189 # add strip masking if needed
190 if(applyMasking):
191 if(isROIsimulation):
192 shaperDigitsName = '__ROISVDShaperDigitsUnmasked'
193 maskingName = '__ROISVDStripMasking'
194 else:
195 shaperDigitsName = 'SVDShaperDigitsUnmasked'
196 maskingName = 'SVDStripMasking'
197
198 if maskingName not in [e.name() for e in path.modules()]:
199 masking = b2.register_module('SVDStripMasking')
200 masking.set_name(maskingName)
201 masking.param('ShaperDigitsUnmasked', shaperDigitsName)
202 path.add_module(masking)
203
204 if dataFormatName not in [e.name() for e in path.modules()]:
205 dataFormat = b2.register_module('SVDDataFormatCheck')
206 dataFormat.param('ShaperDigits', shaperDigitsName)
207
208 if fitterName not in [e.name() for e in path.modules()]:
209 fitter = b2.register_module('SVDCoGTimeEstimator')
210 fitter.set_name(fitterName)
211 fitter.param('RecoDigits', recoDigitsName)
212 path.add_module(fitter)
213
214 if clusterizerName not in [e.name() for e in path.modules()]:
215 clusterizer = b2.register_module('SVDSimpleClusterizer')
216 clusterizer.set_name(clusterizerName)
217 clusterizer.param('RecoDigits', recoDigitsName)
218 clusterizer.param('Clusters', clusterName)
219 clusterizer.param('useDB', True)
220 path.add_module(clusterizer)
221
222 if missingAPVsClusterCreatorName not in [e.name() for e in path.modules()]:
223 missingAPVCreator = b2.register_module('SVDMissingAPVsClusterCreator')
224 missingAPVCreator.set_name(missingAPVsClusterCreatorName)
225 path.add_module(missingAPVCreator)
226
227 if nameSVDTrackingEventLevelMdstInfoFiller not in path:
228 svdTrackingEventLevelMdstInfoFiller = b2.register_module('SVDTrackingEventLevelMdstInfoFiller')
229 svdTrackingEventLevelMdstInfoFiller.set_name(nameSVDTrackingEventLevelMdstInfoFiller)
230 svdTrackingEventLevelMdstInfoFiller.param('EventLevelTrackingInfoName', nameEventTrackingInfo)
231 svdTrackingEventLevelMdstInfoFiller.param('svdClustersName', clusterName)
232 path.add_module(svdTrackingEventLevelMdstInfoFiller)
233
234 if timeGroupComposerName not in [e.name() for e in path.modules()]:
235 svdTimeGrouping = b2.register_module('SVDTimeGrouping')
236 svdTimeGrouping.set_name(timeGroupComposerName)
237 svdTimeGrouping.param('SVDClusters', clusterName)
238 path.add_module(svdTimeGrouping)
239
240 # Add SVDSpacePointCreator
241 add_svd_SPcreation(path, isROIsimulation)
242
243
244def add_svd_simulation(path, useConfigFromDB=False, daqMode=2, relativeShift=9):
245 """
246 Adds the SVD simulation to the path.
247
248 Simulation ends with :ref:`SVDShaperDigits<svdshapers>` and :ref:`SVDEventInfo<svdeventinfo>`.
249
250 @param path: add the modules to this basf2 path.
251 @param useConfigFromDB: if True, read the SVD configuration from :ref:`SVDGlobalConfigParameters<svdglobalconfig>`.
252 @param daqMode: = 2 for the default 6-sample mode, = 1 for the 3-sample mode, = 3 for the 3-mixed-6 sample mode.
253 @param relativeShift: relative time shift between the 3-sample and the 6-sample mode in units of 1/4 of APV clock.\
254 If ``useConfigFromDB`` is True, the value of this parameter is overwritten.
255 """
256
257 svdevtinfoset = b2.register_module("SVDEventInfoSetter")
258 svdevtinfoset.param("useDB", useConfigFromDB)
259 path.add_module(svdevtinfoset)
260
261 digitizer = b2.register_module('SVDDigitizer')
262 path.add_module(digitizer)
263
264 if not useConfigFromDB:
265 if daqMode != 2 and daqMode != 1 and daqMode != 3:
266 message = 'OOPS the acquisition mode that you want to simulate is not available.\n' \
267 'Please choose among daqMode = 2 (6-sample) and daqMode = 1 (3-sample).'
268 b2.B2FATAL(message)
269
270 # TODO add check of relative shift value
271 svdevtinfoset.param("daqMode", daqMode)
272 svdevtinfoset.param("relativeShift", relativeShift)
273
274
275def add_svd_unpacker(path):
276 """
277 Adds the SVD Unpacker to the path.
278
279 The unpacker produces :ref:`SVDShaperDigits<svdshapers>` and :ref:`SVDEventInfo<svdeventinfo>`.
280
281 @param path: add the modules to this basf2 path.
282 """
283
284 unpacker = b2.register_module('SVDUnpacker')
285 path.add_module(unpacker)
286
287
288def add_svd_unpacker_simulate3sampleDAQ(path, latencyShift=-1, relativeShift=-1):
289 """
290 Adds the SVD Unpacker to the path, emulating the 3-sample mode from the 6-sample mode.
291
292 @param path: add the modules to this basf2 path.
293 @param latencyShift: relative time shift between the 3-sample and the 6-sample mode, in APV clocks.\
294 0 <= latencyShift <=3
295 @param relativeShift: relative time shift between the 3-sample and the 6-sample mode, in units of 1/4 of APV clock.\
296 0 <= relativeShift <=12
297
298 .. warning:: at least one between ``relativeShift`` and ``latencyShift`` should be set (different from -1).
299 """
300
301 if relativeShift != -1 and latencyShift != -1:
302 b2.B2FATAL("OOPS please choose only one between relativeShift and latencyShift. Exiting now.")
303
304 unpacker = b2.register_module('SVDUnpacker')
305 unpacker.param("SVDEventInfo", "SVDEventInfoOriginal")
306 unpacker.param("svdShaperDigitListName", "SVDShaperDigitsOriginal")
307 path.add_module(unpacker)
308
309 # emulate the 3-sample acquisition
310 emulator = b2.register_module("SVD3SamplesEmulator")
311 emulator.param("SVDEventInfo", "SVDEventInfoOriginal")
312 emulator.param("SVDShaperDigits", "SVDShaperDigitsOriginal")
313 if latencyShift == -1:
314 emulator.param("chooseStartingSample", False)
315 else:
316 emulator.param("chooseStartingSample", True)
317 if latencyShift < 0 or latencyShift > 3:
318 b2.B2FATAL("the latencyShift must be an integer >=0 and <= 3")
319 else:
320 emulator.param("StartingSample", latencyShift)
321
322 if relativeShift == -1:
323 emulator.param("chooseRelativeShift", False)
324 else:
325 emulator.param("chooseRelativeShift", True)
326 if relativeShift < 0 or relativeShift > 12:
327 b2.B2FATAL("the relativeShift must be an integer >=0 and <= 12")
328 else:
329 emulator.param("relativeShift", relativeShift)
330
331 emulator.param("outputSVDEventInfo", "SVDEventInfo")
332 emulator.param("outputSVDShaperDigits", "SVDShaperDigits3SampleAll")
333 path.add_module(emulator)
334
335 # emulate online zero-suppression
336 zsonline = b2.register_module("SVDZeroSuppressionEmulator")
337 zsonline.param("ShaperDigits", "SVDShaperDigits3SampleAll")
338 zsonline.param("ShaperDigitsIN", "SVDShaperDigits")
339 path.add_module(zsonline)
340
341
342def add_svd_packer(path):
343 """
344 Adds the SVD Packer to the path.
345
346 @param path: add the modules to this basf2 path.
347 """
348
349 packer = b2.register_module('SVDPacker')
350 path.add_module(packer)
351
352
353def add_svd_SPcreation(path, isROIsimulation=False):
354 """
355 Adds the SVD SpacePoint Creator to the path.
356
357 @param path: add the modules to this basf2 path.
358 @param isROIsimulation: SVD reconstruction can be run during simulation\
359 in order to simulate the PXD Data Reduction with ROI finding.
360 """
361
362 # register EventTrackingInfo
363 if isROIsimulation:
364 nameTrackingInfoModule = "RegisterEventLevelTrackingInfo__ROI"
365 nameEventTrackingInfo = "EventLevelTrackingInfo__ROI"
366 else:
367 nameTrackingInfoModule = "RegisterEventLevelTrackingInfo"
368 nameEventTrackingInfo = "EventLevelTrackingInfo"
369
370 if nameTrackingInfoModule not in path:
371 registerEventlevelTrackingInfo = b2.register_module('RegisterEventLevelTrackingInfo')
372 registerEventlevelTrackingInfo.set_name(nameTrackingInfoModule)
373 registerEventlevelTrackingInfo.param('EventLevelTrackingInfoName', nameEventTrackingInfo)
374 path.add_module(registerEventlevelTrackingInfo)
375
376 if(isROIsimulation):
377 svdSPCreatorName = '__ROISVDSpacePointCreator'
378 svd_clusters = '__ROIsvdClusters'
379 nameSPs = 'SVDSpacePoints__ROI'
380 else:
381 svdSPCreatorName = 'SVDSpacePointCreator'
382 svd_clusters = ''
383 nameSPs = 'SVDSpacePoints'
384
385 if svdSPCreatorName not in [e.name() for e in path.modules()]:
386 spCreatorSVD = b2.register_module('SVDSpacePointCreator')
387 spCreatorSVD.set_name(svdSPCreatorName)
388 spCreatorSVD.param('NameOfInstance', 'SVDSpacePoints')
389 spCreatorSVD.param('SpacePoints', nameSPs)
390 spCreatorSVD.param('SVDClusters', svd_clusters)
391 spCreatorSVD.param('EventLevelTrackingInfoName', nameEventTrackingInfo)
392 path.add_module(spCreatorSVD)