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