Belle II Software  release-08-01-09
commondqm.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 import basf2 as b2
13 from svd import add_svd_create_recodigits
14 from svd.dqm_utils import add_svd_dqm_dose
15 from geometry import check_components
16 from analysisDQM import add_analysis_dqm, add_mirabelle_dqm
17 import neurotrigger
18 
19 
20 def add_common_dqm(path, components=None, dqm_environment="expressreco", dqm_mode="dont_care", create_hlt_unit_histograms=False):
21  """
22  This function adds DQMs which are common for Cosmic runs and Collion runs
23 
24  @param components: A list of the detector components which are available in this
25  run of basf2
26  @param dqm_environment: The environment the DQM modules are running in
27  "expressreco" (default) if running on the ExpressReco system
28  "hlt" if running on the HLT online reconstructon nodes
29  If running on the hlt, you may want to output less or other DQM plots
30  due to the limited bandwith of the HLT nodes.
31  @param dqm_mode: How to split up the path for online/HLT.
32  For dqm_mode == "dont_care" all the DQM modules should be added.
33  For dqm_mode == "all_events" only the DQM modules which should run on all events
34  (filtered and dismissed) should be added
35  For dqm_mode == "before_reco" only the DQM modules which should run before
36  all reconstruction
37  For dqm_mode == "filtered" only the DQM modules which should run on filtered
38  events should be added
39  @param create_hlt_unit_histograms: Parameter for SoftwareTiggerHLTDQMModule.
40  Should be True only when running on the HLT servers
41  """
42  assert dqm_mode in ["dont_care", "all_events", "filtered", "before_filter"]
43  # Check components.
44  check_components(components)
45 
46  if dqm_mode in ["dont_care", "filtered"]:
47  # TTD trigger and bunch injection monitoring
48  path.add_module('TTDDQM')
49 
50  if dqm_environment == "expressreco" and (dqm_mode in ["dont_care"]):
51  # PXD (not useful on HLT)
52  if components is None or 'PXD' in components:
53  path.add_module('PXDDAQDQM', histogramDirectoryName='PXDDAQ')
54  path.add_module('PXDROIDQM', histogramDirectoryName='PXDROI')
55  path.add_module('PXDDQMExpressReco', histogramDirectoryName='PXDER')
56  path.add_module('SetupGenfitExtrapolation')
57  path.add_module('PXDROIFinder',
58  recoTrackListName='RecoTracks',
59  PXDInterceptListName='PXDIntercepts')
60  # moved to cosmics/collision as we need different cuts
61  # path.add_module('PXDDQMEfficiency', histogramDirectoryName='PXDEFF')
62  path.add_module('PXDTrackClusterDQM', histogramDirectoryName='PXDER')
63  path.add_module('PXDInjectionDQM', histogramDirectoryName='PXDINJ', eachModule=True)
64  # SVD
65  if components is None or 'SVD' in components:
66  # reconstruct SVDRecoDigits first of all
67  add_svd_create_recodigits(path)
68 
69  # SVD DATA FORMAT
70  svdunpackerdqm = b2.register_module('SVDUnpackerDQM')
71  path.add_module(svdunpackerdqm)
72  # offline ZS emulator
73  path.add_module(
74  'SVDZeroSuppressionEmulator',
75  SNthreshold=5,
76  ShaperDigits='SVDShaperDigits',
77  ShaperDigitsIN='SVDShaperDigitsZS5',
78  FADCmode=True)
79  # SVD Occupancy after Injection
80  path.add_module('SVDDQMInjection', ShaperDigits='SVDShaperDigitsZS5')
81  # SVDDQMExpressReco General
82  path.add_module('SVDDQMExpressReco',
83  offlineZSShaperDigits='SVDShaperDigitsZS5')
84  # SVD HIT TIME
85  path.add_module('SVDDQMHitTime')
86  # SVD EFFICIENCY
87  path.add_module('SetupGenfitExtrapolation')
88  path.add_module('SVDROIFinder',
89  recoTrackListName='RecoTracks',
90  SVDInterceptListName='SVDIntercepts')
91  path.add_module('SVDDQMEfficiency')
92  # SVD CLUSTERS ON TRACK
93  path.add_module('SVDDQMClustersOnTrack')
94  # SVD DOSE
95  add_svd_dqm_dose(path, 'SVDShaperDigitsZS5')
96 
97  # Event time measuring detectors
98  if components is None or 'CDC' in components or 'ECL' in components or 'TOP' in components:
99  eventT0DQMmodule = b2.register_module('EventT0DQM')
100  path.add_module(eventT0DQMmodule)
101 
102  if dqm_environment == "hlt" and (dqm_mode in ["dont_care", "before_filter"]):
103  path.add_module(
104  "SoftwareTriggerHLTDQM",
105  createHLTUnitHistograms=create_hlt_unit_histograms,
106  createTotalResultHistograms=False,
107  createExpRunEventHistograms=False,
108  createErrorFlagHistograms=True,
109  cutResultIdentifiers={},
110  histogramDirectoryName="softwaretrigger_before_filter",
111  pathLocation="before filter",
112  ).set_name("SoftwareTriggerHLTDQM_before_filter")
113 
114  path.add_module(
115  "TrackingAbortDQM",
116  histogramDirectoryName="TrackingAbort_before_filter",
117  ).set_name("TrackingAbortDQM_before_filter")
118 
119  path.add_module("StatisticsTimingHLTDQM",
120  createHLTUnitHistograms=create_hlt_unit_histograms,
121  )
122 
123  if dqm_environment == "hlt" and (dqm_mode in ["dont_care", "filtered"]):
124  # HLT
125  hlt_trigger_lines_in_plot = []
126  hlt_skim_lines_in_plot = []
127 
128  hlt_trigger_lines_per_unit_in_plot = [
129  "ge3_loose_tracks_inc_1_tight_not_ee2leg",
130  "Elab_gt_0.5_plus_2_others_with_Elab_gt_0.18_plus_no_clust_with_Ecms_gt_2.0",
131  "selectee",
132  "Estargt2_GeV_cluster",
133  ]
134  cutResultIdentifiers = {}
135 
136  from softwaretrigger import filter_categories, skim_categories
137 
138  filter_cat = [method for method in dir(filter_categories) if method.startswith('__') is False if method != 'RESULTS']
139  skim_cat = [method for method in dir(skim_categories) if method.startswith('__') is False]
140 
141  def read_lines(category):
142  return [i.split(" ", 1)[1].replace(" ", "_") for i in category]
143 
144  for i in filter_cat:
145  cutResultIdentifiers[i] = {"filter": read_lines(getattr(filter_categories, i))}
146  hlt_trigger_lines_in_plot += read_lines(getattr(filter_categories, i))
147 
148  for i in skim_cat:
149  cutResultIdentifiers[i] = {"skim": read_lines(getattr(skim_categories, i))}
150  hlt_skim_lines_in_plot += read_lines(getattr(skim_categories, i))
151 
152  cutResultIdentifiers["skim"] = {"skim": hlt_skim_lines_in_plot}
153  cutResultIdentifiers["filter"] = {"filter": hlt_trigger_lines_in_plot}
154 
155  additionalL1Identifiers = [
156  'ffy',
157  'fyo',
158  'c4',
159  'hie',
160  'mu_b2b',
161  'mu_eb2b',
162  'beklm',
163  'eklm2',
164  'cdcklm1',
165  'seklm1',
166  'ieklm1',
167  'ecleklm1',
168  'fso',
169  'fioiecl1',
170  'ff30',
171  'stt',
172  'ioiecl1',
173  'ioiecl2',
174  'lml1',
175  'lml2',
176  'lml3',
177  'lml4',
178  'lml5',
179  'lml6',
180  'lml7',
181  'lml8',
182  'lml9',
183  'lml10',
184  'lml12',
185  'lml13',
186  'bhapur']
187 
188  # Default plot
189  path.add_module(
190  "SoftwareTriggerHLTDQM",
191  cutResultIdentifiers=cutResultIdentifiers,
192  l1Identifiers=["fff", "ffo", "lml0", "ffb", "fp"],
193  additionalL1Identifiers=additionalL1Identifiers,
194  createHLTUnitHistograms=create_hlt_unit_histograms,
195  cutResultIdentifiersPerUnit=hlt_trigger_lines_per_unit_in_plot,
196  pathLocation="after filter",
197  )
198 
199  path.add_module("TrackingAbortDQM")
200 
201  # Skim plots where bhabha contamination is removed
202  path.add_module(
203  "SoftwareTriggerHLTDQM",
204  cutResultIdentifiers={
205  "skim": {"skim": hlt_skim_lines_in_plot},
206  },
207  cutResultIdentifiersIgnored={
208  "skim": [
209  "accept_bhabha_all",
210  ]
211  },
212  createTotalResultHistograms=False,
213  createExpRunEventHistograms=False,
214  histogramDirectoryName="softwaretrigger_skim_nobhabha",
215  ).set_name("SoftwareTriggerHLTDQM_skim_nobhabha")
216 
217  if dqm_environment == "hlt" and (dqm_mode in ["dont_care", "filtered"]):
218  # SVD DATA FORMAT
219  if components is None or 'SVD' in components:
220  svdunpackerdqm = b2.register_module('SVDUnpackerDQM')
221  path.add_module(svdunpackerdqm)
222 
223  # CDC
224  if (components is None or 'CDC' in components) and (dqm_mode in ["dont_care", "filtered"]):
225  cdcdqm = b2.register_module('cdcDQM7')
226  path.add_module(cdcdqm)
227 
228  module_names = [m.name() for m in path.modules()]
229  if ('SoftwareTrigger' in module_names):
230  cdcdedxdqm = b2.register_module('CDCDedxDQM')
231  path.add_module(cdcdedxdqm)
232 
233  if dqm_environment == "expressreco":
234  path.add_module('CDCDQM')
235 
236  # ECL
237  if (components is None or 'ECL' in components) and (dqm_mode in ["dont_care", "filtered"]):
238  ecldqm = b2.register_module('ECLDQM')
239  path.add_module(ecldqm)
240  ecldqmext = b2.register_module('ECLDQMEXTENDED')
241  path.add_module(ecldqmext)
242  path.add_module('ECLDQMOutOfTimeDigits')
243  path.add_module('ECLDQMConnectedRegions')
244  # we dont want to create large histograms on HLT, thus ERECO only
245  if dqm_environment == "expressreco":
246  path.add_module('ECLDQMInjection', histogramDirectoryName='ECLINJ')
247 
248  # TOP
249  if (components is None or 'TOP' in components) and (dqm_mode in ["dont_care", "filtered"]):
250  topdqm = b2.register_module('TOPDQM')
251  path.add_module(topdqm)
252 
253  # KLM
254  if (components is None or 'KLM' in components) and (dqm_mode in ["dont_care", "filtered"]):
255  klmdqm = b2.register_module("KLMDQM")
256  path.add_module(klmdqm)
257 
258  # TRG before all reconstruction runs (so on all events with all unpacked information)
259  if (components is None or 'TRG' in components) and (dqm_mode in ["dont_care", "before_filter"]):
260  # TRGECL
261  trgecldqm = b2.register_module('TRGECLDQM')
262  path.add_module(trgecldqm)
263  trgecltimingdqm = b2.register_module('TRGECLEventTimingDQM')
264  path.add_module(trgecltimingdqm)
265  # TRGGDL
266  trggdldqm = b2.register_module('TRGGDLDQM')
267  trggdldqm.param('skim', 0)
268  path.add_module(trggdldqm)
269  # TRGTOP
270  trgtopdqm = b2.register_module('TRGTOPDQM')
271  trgtopdqm.param('skim', 0)
272  path.add_module(trgtopdqm)
273  # TRGGRL
274  trggrldqm = b2.register_module('TRGGRLDQM')
275  path.add_module(trggrldqm)
276  # TRGCDCTSF
277  nmod_tsf = [0, 1, 2, 3, 4, 5, 6]
278  for mod_tsf in nmod_tsf:
279  path.add_module('TRGCDCTSFDQM', TSFMOD=mod_tsf)
280  # TRGCDC2D
281  trgcdct2ddqm = b2.register_module('TRGCDCT2DDQM')
282  path.add_module(trgcdct2ddqm)
283  # TRGCDC3D
284  nmod_t3d = [0, 1, 2, 3]
285  for mod_t3d in nmod_t3d:
286  path.add_module('TRGCDCT3DConverter',
287  hitCollectionName='FirmCDCTriggerSegmentHits' + str(mod_t3d),
288  addTSToDatastore=True,
289  EventTimeName='FirmBinnedEventT0' + str(mod_t3d),
290  addEventTimeToDatastore=True,
291  inputCollectionName='FirmTRGCDC2DFinderTracks' + str(mod_t3d),
292  add2DFinderToDatastore=True,
293  outputCollectionName='FirmTRGCDC3DFitterTracks' + str(mod_t3d),
294  add3DToDatastore=True,
295  fit3DWithTSIM=0,
296  firmwareResultCollectionName='TRGCDCT3DUnpackerStore' + str(mod_t3d),
297  isVerbose=0)
298  path.add_module('TRGCDCT3DDQM', T3DMOD=mod_t3d)
299  # CDCTriggerNeuro
300  if dqm_environment != "expressreco":
302  path.add_module('CDCTriggerNeuroDQMOnline', histogramDirectoryName="TRGCDCTNN2", useRecoTracks=False)
303  path.add_module('CDCTriggerNeuroDQM')
304 
305  # TRG for expressreco:
306  if dqm_environment == "expressreco" and (components is None or 'TRG' in components) and (dqm_mode in ["dont_care"]):
307  # TRGCDCTNN
309  path.add_module('CDCTriggerRecoMatcher', TrgTrackCollectionName=neurotrigger.hwneurotracks,
310  hitCollectionName=neurotrigger.hwneuroinputsegmenthits, axialOnly=True)
311  path.add_module('CDCTriggerRecoMatcher', TrgTrackCollectionName=neurotrigger.hwsimneurotracks,
312  hitCollectionName=neurotrigger.hwneuroinputsegmenthits, axialOnly=True)
313  path.add_module('CDCTriggerRecoMatcher', TrgTrackCollectionName=neurotrigger.hwneuroinput2dfindertracks,
314  hitCollectionName=neurotrigger.hwneuroinputsegmenthits, axialOnly=True)
315  path.add_module('CDCTriggerNeuroDQMOnline', histogramDirectoryName="TRGCDCTNN2", useRecoTracks=True)
316 
317  # TRG after skim
318  if (components is None or 'TRG' in components) and (dqm_mode in ["dont_care", "filtered"]):
319  # TRGGDL
320  trggdldqm_skim = b2.register_module('TRGGDLDQM')
321  trggdldqm_skim.param('skim', 1)
322  path.add_module(trggdldqm_skim)
323  # TRGTOP
324  trgtopdqm_skim = b2.register_module('TRGTOPDQM')
325  trgtopdqm_skim.param('skim', 1)
326  path.add_module(trgtopdqm_skim)
327 
328  # TrackDQM, needs at least one VXD components to be present or will crash otherwise
329  if (components is None or 'SVD' in components or 'PXD' in components) and (dqm_mode in ["dont_care", "filtered"]):
330  if (dqm_environment == "hlt"):
331  path.add_module('TrackingHLTDQM')
332  else:
333  path.add_module('ParallelTrackFilter', min_d0=-0.5, max_d0=0.5, min_z0=-1, max_z0=1,
334  inputArrayName="", outputINArrayName="TracksFromIP", outputOUTArrayName="TracksNotFromIP")
335  path.add_module('TrackingExpressRecoDQM', histogramDirectoryName="TrackingERDQM_FromIP",
336  tracksStoreArrayName="TracksFromIP", histogramTitleSuffix=" - Tracks from IP") \
337  .set_name("TrackingExpressRecoDQM_FromIP")
338  path.add_module('TrackingExpressRecoDQM', histogramDirectoryName="TrackingERDQM_NotFromIP",
339  tracksStoreArrayName="TracksNotFromIP", histogramTitleSuffix=" - Tracks not from IP") \
340  .set_name("TrackingExpressRecoDQM_NotFromIP")
341 
342  # ARICH
343  if (components is None or 'ARICH' in components) and (dqm_mode in ["dont_care", "filtered"]):
344  path.add_module('ARICHDQM')
345 
346  if dqm_mode in ["dont_care", "filtered"]:
347  # PhysicsObjectsDQM
348  add_analysis_dqm(path)
349  if dqm_environment == "expressreco" and (dqm_mode in ["dont_care"]):
350  add_mirabelle_dqm(path)
351 
352  # KLM2 (requires mu+ particle list from add_analysis_dqm)
353  if (components is None or ('KLM' in components and 'CDC' in components)) and (dqm_mode in ["dont_care", "filtered"]):
354  path.add_module("KLMDQM2", MuonListName='mu+:KLMDQM',
355  MinimalMatchingDigits=12,
356  MinimalMatchingDigitsOuterLayers=0,
357  MinimalMomentumNoOuterLayers=4.0,
358  SoftwareTriggerName="")
359 
360  # We want to see the datasize of all events after removing the raw data
361  if dqm_mode in ["dont_care", "all_events"]:
362  # DAQ Monitor
363  path.add_module('DAQMonitor')
def add_neurotrigger_hw(path, nntweightfile=None, debug_level=4, debugout=False, **kwargs)