220 def makeAlgs (self, config) :
221 log = logging.getLogger(
'MuonWorkingPointConfig')
223 from xAODMuon.xAODMuonEnums
import xAODMuonEnums
224 if self.quality ==
'Tight' :
225 quality = xAODMuonEnums.Quality.Tight
226 elif self.quality ==
'Medium' :
227 quality = xAODMuonEnums.Quality.Medium
228 elif self.quality ==
'Loose' :
229 quality = xAODMuonEnums.Quality.Loose
230 elif self.quality ==
'VeryLoose' :
231 quality = xAODMuonEnums.Quality.VeryLoose
232 elif self.quality ==
'HighPt' :
234 elif self.quality ==
'LowPtEfficiency' :
237 raise ValueError (
"invalid muon quality: \"" + self.quality +
238 "\", allowed values are Tight, Medium, Loose, " +
239 "VeryLoose, HighPt, LowPtEfficiency")
242 if config.geometry()
is LHCPeriod.Run1:
243 raise ValueError (
"Can't set up the MuonWorkingPointConfig with %s, there must be something wrong!" % config.geometry().value)
245 postfix = self.postfix
247 postfix = self.selectionName
248 if postfix !=
'' and postfix[0] !=
'_' :
249 postfix =
'_' + postfix
252 if self.trackSelection:
253 alg = config.createAlgorithm(
'CP::AsgLeptonTrackSelectionAlg',
254 'MuonTrackSelectionAlg',
256 alg.selectionDecoration =
'trackSelection' + postfix +
',as_bits'
257 alg.maxD0Significance = self.maxD0Significance
258 alg.maxDeltaZ0SinTheta = self.maxDeltaZ0SinTheta
259 alg.particles = config.readName (self.containerName)
260 alg.preselection = config.getPreselection (self.containerName,
'')
261 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration, preselection=self.addSelectionToPreselection)
264 alg = config.createAlgorithm(
'CP::MuonSelectionAlgV2',
266 config.addPrivateTool(
'selectionTool',
'CP::MuonSelectionTool' )
267 alg.selectionTool.MuQuality = quality
268 alg.selectionTool.IsRun3Geo = config.geometry() >= LHCPeriod.Run3
269 if config.geometry()
is LHCPeriod.Run4:
270 log.warning(
"Disabling NSW hits for Run4 geometry")
271 alg.selectionTool.ExcludeNSWFromPrecisionLayers =
True
273 alg.selectionTool.ExcludeNSWFromPrecisionLayers = self.excludeNSWFromPrecisionLayers
and (config.geometry() >= LHCPeriod.Run3)
274 alg.selectionDecoration =
'good_muon' + postfix +
',as_char'
275 alg.badMuonVetoDecoration =
'is_bad' + postfix +
',as_char'
276 alg.muons = config.readName (self.containerName)
277 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
278 config.addSelection (self.containerName, self.selectionName,
279 alg.selectionDecoration,
280 preselection=self.addSelectionToPreselection)
281 if self.quality ==
'HighPt':
282 config.addOutputVar (self.containerName,
'is_bad' + postfix,
'is_bad' + postfix)
285 if self.isolation !=
'NonIso' :
286 alg = config.createAlgorithm(
'CP::MuonIsolationAlg',
288 config.addPrivateTool(
'isolationTool',
'CP::IsolationSelectionTool' )
289 alg.isolationTool.MuonWP = self.isolation
290 alg.isolationTool.IsoDecSuffix = self.isoDecSuffix
291 alg.isolationDecoration =
'isolated_muon' + postfix +
',as_char'
292 alg.muons = config.readName (self.containerName)
293 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
294 config.addSelection (self.containerName, self.selectionName,
295 alg.isolationDecoration,
296 preselection=self.addSelectionToPreselection)
300 if config.dataType()
is not DataType.Data
and (
not self.noEffSF
or self.onlyRecoEffSF):
301 alg = config.createAlgorithm(
'CP::MuonEfficiencyScaleFactorAlg',
302 'MuonEfficiencyScaleFactorAlgReco' )
303 config.addPrivateTool(
'efficiencyScaleFactorTool',
304 'CP::MuonEfficiencyScaleFactors' )
305 alg.scaleFactorDecoration =
'muon_reco_effSF' + postfix +
"_%SYS%"
306 alg.outOfValidity = 2
307 alg.outOfValidityDeco =
'muon_reco_bad_eff' + postfix
308 alg.efficiencyScaleFactorTool.WorkingPoint = self.quality
309 if config.geometry() >= LHCPeriod.Run3:
310 alg.efficiencyScaleFactorTool.CalibrationRelease =
'250418_Preliminary_r24run3'
311 alg.efficiencyScaleFactorTool.BreakDownSystematics = self.systematicBreakdown
312 alg.muons = config.readName (self.containerName)
313 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
314 if self.saveDetailedSF:
315 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
316 'reco_effSF' + postfix)
317 sfList += [alg.scaleFactorDecoration]
320 if config.dataType()
is not DataType.Data
and self.quality ==
'HighPt' and not self.onlyRecoEffSF
and not self.noEffSF:
321 alg = config.createAlgorithm(
'CP::MuonEfficiencyScaleFactorAlg',
322 'MuonEfficiencyScaleFactorAlgBMVHighPt' )
323 config.addPrivateTool(
'efficiencyScaleFactorTool',
324 'CP::MuonEfficiencyScaleFactors' )
325 alg.scaleFactorDecoration =
'muon_BadMuonVeto_effSF' + postfix +
"_%SYS%"
326 alg.outOfValidity = 2
327 alg.outOfValidityDeco =
'muon_BadMuonVeto_bad_eff' + postfix
328 alg.efficiencyScaleFactorTool.WorkingPoint =
'BadMuonVeto_HighPt'
329 if config.geometry() >= LHCPeriod.Run3:
330 alg.efficiencyScaleFactorTool.CalibrationRelease =
'220817_Preliminary_r22run3'
331 alg.efficiencyScaleFactorTool.BreakDownSystematics = self.systematicBreakdown
332 alg.muons = config.readName (self.containerName)
333 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
334 if self.saveDetailedSF:
335 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
336 'BadMuonVeto_effSF' + postfix)
337 sfList += [alg.scaleFactorDecoration]
340 if config.dataType()
is not DataType.Data
and self.isolation !=
'NonIso' and not self.onlyRecoEffSF
and not self.noEffSF:
341 alg = config.createAlgorithm(
'CP::MuonEfficiencyScaleFactorAlg',
342 'MuonEfficiencyScaleFactorAlgIsol' )
343 config.addPrivateTool(
'efficiencyScaleFactorTool',
344 'CP::MuonEfficiencyScaleFactors' )
345 alg.scaleFactorDecoration =
'muon_isol_effSF' + postfix +
"_%SYS%"
346 alg.outOfValidity = 2
347 alg.outOfValidityDeco =
'muon_isol_bad_eff' + postfix
348 alg.efficiencyScaleFactorTool.WorkingPoint = self.isolation +
'Iso'
349 if config.geometry() >= LHCPeriod.Run3:
350 alg.efficiencyScaleFactorTool.CalibrationRelease =
'250418_Preliminary_r24run3'
351 alg.efficiencyScaleFactorTool.BreakDownSystematics = self.systematicBreakdown
352 alg.muons = config.readName (self.containerName)
353 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
354 if self.saveDetailedSF:
355 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
356 'isol_effSF' + postfix)
357 sfList += [alg.scaleFactorDecoration]
360 if config.dataType()
is not DataType.Data
and self.trackSelection
and not self.onlyRecoEffSF
and not self.noEffSF:
361 alg = config.createAlgorithm(
'CP::MuonEfficiencyScaleFactorAlg',
362 'MuonEfficiencyScaleFactorAlgTTVA' )
363 config.addPrivateTool(
'efficiencyScaleFactorTool',
364 'CP::MuonEfficiencyScaleFactors' )
365 alg.scaleFactorDecoration =
'muon_TTVA_effSF' + postfix +
"_%SYS%"
366 alg.outOfValidity = 2
367 alg.outOfValidityDeco =
'muon_TTVA_bad_eff' + postfix
368 alg.efficiencyScaleFactorTool.WorkingPoint =
'TTVA'
369 if config.geometry() >= LHCPeriod.Run3:
370 alg.efficiencyScaleFactorTool.CalibrationRelease =
'250418_Preliminary_r24run3'
371 alg.efficiencyScaleFactorTool.BreakDownSystematics = self.systematicBreakdown
372 alg.muons = config.readName (self.containerName)
373 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
374 if self.saveDetailedSF:
375 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
376 'TTVA_effSF' + postfix)
377 sfList += [alg.scaleFactorDecoration]
379 if config.dataType()
is not DataType.Data
and not self.noEffSF
and self.saveCombinedSF:
380 alg = config.createAlgorithm(
'CP::AsgObjectScaleFactorAlg',
381 'MuonCombinedEfficiencyScaleFactorAlg' )
382 alg.particles = config.readName (self.containerName)
383 alg.inScaleFactors = sfList
384 alg.outScaleFactor =
'effSF' + postfix +
'_%SYS%'
385 config.addOutputVar (self.containerName, alg.outScaleFactor,
'effSF' + postfix)