Skip to content

Commit 589e1f9

Browse files
committed
Implement consistency check for Validators
- associatormap, label and muonHistoParameters must have the same size - associatormap and label must share the same input collection (associatormap and label vectors must have the same ordering)
1 parent b0ed129 commit 589e1f9

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

Validation/RecoMuon/python/muonValidationHLT_cff.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@
4141
label = (
4242
'hltL2Muons',
4343
'hltL2Muons:UpdatedAtVtx',
44-
'hltIterL3OIMuonTrackSelectionHighPurity:',
45-
'hltIterL3MuonMerged:',
46-
'hltIterL3MuonAndMuonFromL1Merged:',
47-
'hltIter0IterL3FromL1MuonTrackSelectionHighPurity:',
48-
'hltIterL3GlbMuon:',
49-
'hltIterL3MuonsNoIDTracks:',
50-
'hltIterL3MuonsTracks:'
44+
'hltIterL3OIMuonTrackSelectionHighPurity',
45+
'hltIterL3MuonMerged',
46+
'hltIterL3MuonAndMuonFromL1Merged',
47+
'hltIter0IterL3FromL1MuonTrackSelectionHighPurity',
48+
'hltIterL3GlbMuon',
49+
'hltIterL3MuonsNoIDTracks',
50+
'hltIterL3MuonsTracks'
5151
),
5252
muonHistoParameters = (
5353
staMuonHistoParameters,
@@ -119,13 +119,38 @@ def _modify_for_OI_first(validator):
119119
(phase2L2AndL3Muons & ~phase2L3MuonsOIFirst).toModify(_hltMuonMultiTrackValidator, _modify_for_IO_first)
120120
(phase2L2AndL3Muons & phase2L3MuonsOIFirst).toModify(_hltMuonMultiTrackValidator, _modify_for_OI_first)
121121

122+
# Check that the associators and labels are consistent
123+
# All MTV clones are DQMEDAnalyzers
124+
from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer
125+
# Access all the global variables
126+
global_items = list(globals().items())
127+
for _name, _obj in global_items:
128+
# Find all MTV clones
129+
if isinstance(_obj, DQMEDAnalyzer) and hasattr(_obj, 'label') and hasattr(_obj, 'associatormap') and hasattr(_obj, 'muonHistoParameters'):
130+
# Check that the size of the associators, lables and muonHistoParameters are the same
131+
if (len(_obj.label) != len(_obj.associatormap) or len(_obj.label) != len(_obj.muonHistoParameters)
132+
or len(_obj.associatormap) != len(_obj.muonHistoParameters)):
133+
raise RuntimeError(f"MuonTrackValidatorHLT -- {_name}: associatormap, label and muonHistoParameters must have the same length!")
134+
# Check that the trackCollection used in each associator corresponds to the validator's label
135+
for i in range(0, len(_obj.label)):
136+
# Dynamically import the associators module to have access to procModifiers changes
137+
associators_module = __import__('Validation.RecoMuon.associators_cff', globals(), locals(), ['associators'], 0)
138+
_assoc = getattr(associators_module, _obj.associatormap[i].value()) if isinstance(_obj.associatormap[i], cms.InputTag) else getattr(associators_module, _obj.associatormap[i])
139+
_label = _obj.label[i].value() if isinstance(_obj.label[i], cms.InputTag) else _obj.label[i]
140+
_tracksTag = _assoc.tracksTag.value() if hasattr(_assoc, 'tracksTag') else _assoc.label_tr.value()
141+
if _tracksTag != _label:
142+
raise RuntimeError(f"MuonTrackValidatorHLT -- {_name}: associatormap and label do not match for index {i}.\n"
143+
f"Associator's tracksTag: {_tracksTag}, collection label in the validator: {_label}.\n"
144+
"Make sure to have the correct ordering!")
145+
146+
from Configuration.Eras.Modifier_phase2_muon_cff import phase2_muon
147+
phase2_muon.toReplaceWith(hltMuonMultiTrackValidator, _hltMuonMultiTrackValidator)
148+
122149
#
123150
# The full Muon HLT validation sequence
124151
#
125-
muonValidationHLT_seq = cms.Sequence(muonAssociationHLT_seq + hltMuonMultiTrackValidator)
126152

127-
from Configuration.Eras.Modifier_phase2_muon_cff import phase2_muon
128-
phase2_muon.toReplaceWith(hltMuonMultiTrackValidator, _hltMuonMultiTrackValidator)
153+
muonValidationHLT_seq = cms.Sequence(muonAssociationHLT_seq + hltMuonMultiTrackValidator)
129154

130155
recoMuonValidationHLT_seq = cms.Sequence(
131156
cms.SequencePlaceholder("TPmu") +

Validation/RecoMuon/python/muonValidation_cff.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,30 @@
227227
)
228228
)
229229

230+
# Check that the associators and labels are consistent
231+
# All MTV clones are DQMEDAnalyzers
232+
from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer
233+
# Access all the global variables
234+
global_items = list(globals().items())
235+
for _name, _obj in global_items:
236+
# Find all MTV clones
237+
if isinstance(_obj, DQMEDAnalyzer) and hasattr(_obj, 'label') and hasattr(_obj, 'associatormap') and hasattr(_obj, 'muonHistoParameters'):
238+
# Check that the size of the associators, lables and muonHistoParameters are the same
239+
if (len(_obj.label) != len(_obj.associatormap) or len(_obj.label) != len(_obj.muonHistoParameters)
240+
or len(_obj.associatormap) != len(_obj.muonHistoParameters)):
241+
raise RuntimeError(f"MuonTrackValidator -- {_name}: associatormap, label and muonHistoParameters must have the same length!")
242+
# Check that the trackCollection used in each associator corresponds to the validator's label
243+
for i in range(0, len(_obj.label)):
244+
# Dynamically import the associators module to have access to procModifiers changes
245+
associators_module = __import__('Validation.RecoMuon.associators_cff', globals(), locals(), ['associators'], 0)
246+
_assoc = getattr(associators_module, _obj.associatormap[i].value()) if isinstance(_obj.associatormap[i], cms.InputTag) else getattr(associators_module, _obj.associatormap[i])
247+
_label = _obj.label[i].value() if isinstance(_obj.label[i], cms.InputTag) else _obj.label[i]
248+
_tracksTag = _assoc.tracksTag.value() if hasattr(_assoc, 'tracksTag') else _assoc.label_tr.value()
249+
if _tracksTag != _label:
250+
raise RuntimeError(f"MuonTrackValidator -- {_name}: associatormap and label do not match for index {i}.\n"
251+
f"Associator's tracksTag: {_tracksTag}, collection label in the validator: {_label}.\n"
252+
"Make sure to have the correct ordering!")
253+
230254
##################################################################################
231255
# Muon validation sequences using MuonTrackValidator
232256
#

0 commit comments

Comments
 (0)