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