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