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