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