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