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