283 def makeAlgs (self, config) :
285 log = logging.getLogger(
'ElectronWorkingPointConfig')
287 if self.forceFullSimConfig:
288 log.warning(
"You are running ElectronWorkingPointConfig forcing full sim config")
289 log.warning(
"This is only intended to be used for testing purposes")
291 selectionPostfix = self.selectionName
292 if selectionPostfix !=
'' and selectionPostfix[0] !=
'_' :
293 selectionPostfix =
'_' + selectionPostfix
296 if config.geometry()
is LHCPeriod.Run1:
297 raise ValueError (
"Can't set up the ElectronWorkingPointConfig with %s, there must be something wrong!" % config.geometry().value)
299 postfix = self.postfix
301 postfix = self.selectionName
302 if postfix !=
'' and postfix[0] !=
'_' :
303 postfix =
'_' + postfix
306 if self.writeTrackD0Z0
or self.trackSelection :
307 alg = config.createAlgorithm(
'CP::AsgLeptonTrackSelectionAlg',
308 'ElectronTrackSelectionAlg' + postfix )
309 alg.selectionDecoration =
'trackSelection' + postfix +
',as_bits'
310 alg.maxD0Significance = self.maxD0Significance
311 alg.maxDeltaZ0SinTheta = self.maxDeltaZ0SinTheta
312 alg.decorateTTVAVars = self.writeTrackD0Z0
313 alg.particles = config.readName (self.containerName)
314 alg.preselection = config.getPreselection (self.containerName,
'')
315 if self.trackSelection :
316 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration)
317 if self.writeTrackD0Z0 :
318 alg.d0sigDecoration =
'd0sig' + postfix
319 alg.z0sinthetaDecoration =
'z0sintheta' + postfix
320 config.addOutputVar (self.containerName, alg.d0sigDecoration, alg.d0sigDecoration,noSys=
True)
321 config.addOutputVar (self.containerName, alg.z0sinthetaDecoration, alg.z0sinthetaDecoration,noSys=
True)
323 if 'LH' in self.identificationWP:
326 alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
'ElectronLikelihoodAlg' + postfix )
327 alg.selectionDecoration =
'selectLikelihood' + selectionPostfix +
',as_bits'
330 config.addPrivateTool(
'selectionTool',
'AsgElectronLikelihoodTool' )
331 alg.selectionTool.primaryVertexContainer =
'PrimaryVertices'
334 if config.geometry() >= LHCPeriod.Run3:
335 alg.selectionTool.WorkingPoint = self.identificationWP.
replace(
"BLayer",
"BL") +
'Electron'
336 elif config.geometry()
is LHCPeriod.Run2:
337 alg.selectionTool.WorkingPoint = self.identificationWP.
replace(
"BLayer",
"BL") +
'Electron_Run2'
340 config.addPrivateTool(
'selectionTool',
'CP::AsgFlagSelectionTool' )
341 dfFlag =
"DFCommonElectronsLH" + self.identificationWP.
split(
'LH')[0]
342 dfFlag = dfFlag.replace(
"BLayer",
"BL")
343 alg.selectionTool.selectionFlags = [dfFlag]
344 elif 'SiHit' in self.identificationWP:
346 algVeto = config.createAlgorithm(
'CP::AsgSelectionAlg',
'ElectronLikelihoodAlgVeto' + postfix +
'Veto')
347 algVeto.selectionDecoration =
'selectLikelihoodVeto' + postfix +
',as_bits'
348 config.addPrivateTool(
'selectionTool',
'CP::AsgFlagSelectionTool' )
349 algVeto.selectionTool.selectionFlags = [
"DFCommonElectronsLHLoose"]
350 algVeto.selectionTool.invertFlags = [
True]
351 algVeto.particles = config.readName (self.containerName)
352 algVeto.preselection = config.getPreselection (self.containerName, self.selectionName)
354 config.addSelection (self.containerName, self.selectionName, algVeto.selectionDecoration)
357 alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
'ElectronLikelihoodAlg' + postfix )
358 alg.selectionDecoration =
'selectSiHit' + selectionPostfix +
',as_bits'
360 config.addPrivateTool(
'selectionTool',
'CP::AsgMaskSelectionTool' )
361 dfVar =
"DFCommonElectronsLHLooseBLIsEMValue"
362 alg.selectionTool.selectionVars = [dfVar]
363 mask =
int( 0 | 0x1 << 1 | 0x1 << 2)
364 alg.selectionTool.selectionMasks = [mask]
367 algDec = config.createAlgorithm(
'CP::ElectronSiHitDecAlg',
'ElectronSiHitDecAlg' + postfix )
368 selDec =
'siHitEvtHasLeptonPair' + selectionPostfix +
',as_bits'
369 algDec.selectionName = selDec.split(
",")[0]
370 algDec.ElectronContainer = config.readName (self.containerName)
372 algDec.RequireTwoLeptons =
True
373 config.addSelection (self.containerName, self.selectionName, selDec)
374 elif 'DNN' in self.identificationWP:
375 if self.chargeIDSelectionRun2:
376 raise ValueError(
'DNN is not intended to be used with '
377 '`chargeIDSelectionRun2` option as there are '
378 'DNN WPs containing charge flip rejection.')
380 alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
'ElectronDNNAlg' + postfix )
381 alg.selectionDecoration =
'selectDNN' + selectionPostfix +
',as_bits'
384 config.addPrivateTool(
'selectionTool',
'AsgElectronSelectorTool' )
386 if config.geometry()
is LHCPeriod.Run3:
387 raise ValueError (
"DNN working points are not available for Run 3 yet.")
389 alg.selectionTool.WorkingPoint = self.identificationWP +
'Electron'
392 config.addPrivateTool(
'selectionTool',
'CP::AsgFlagSelectionTool' )
393 dfFlag =
"DFCommonElectronsDNN" + self.identificationWP.
split(
'DNN')[0]
394 alg.selectionTool.selectionFlags = [dfFlag]
396 alg.particles = config.readName (self.containerName)
397 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
398 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration)
401 if self.doFSRSelection :
403 wpFlag = alg.selectionDecoration.split(
",")[0]
404 alg = config.createAlgorithm(
'CP::EgammaFSRForMuonsCollectorAlg',
'EgammaFSRForMuonsCollectorAlg' + postfix )
405 alg.selectionDecoration = wpFlag
406 alg.ElectronOrPhotonContKey = config.readName (self.containerName)
410 if 'SiHit' in self.identificationWP:
414 if self.isolationWP !=
'NonIso' :
415 alg = config.createAlgorithm(
'CP::EgammaIsolationSelectionAlg',
416 'ElectronIsolationSelectionAlg' + postfix )
417 alg.selectionDecoration =
'isolated' + selectionPostfix +
',as_bits'
418 config.addPrivateTool(
'selectionTool',
'CP::IsolationSelectionTool' )
419 alg.selectionTool.ElectronWP = self.isolationWP
420 if self.closeByCorrection:
421 alg.selectionTool.IsoDecSuffix =
"CloseByCorr"
422 alg.egammas = config.readName (self.containerName)
423 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
424 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration)
426 if self.chargeIDSelectionRun2
and config.geometry() >= LHCPeriod.Run3:
427 log.warning(
"ECIDS is only available for Run 2 and will not have effect in run 3.")
430 if self.chargeIDSelectionRun2
and config.geometry() < LHCPeriod.Run3:
431 alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
432 'ElectronChargeIDSelectionAlg' + postfix )
433 alg.selectionDecoration =
'chargeID' + selectionPostfix +
',as_bits'
434 if self.recomputeChargeID:
436 config.addPrivateTool(
'selectionTool',
437 'AsgElectronChargeIDSelectorTool' )
438 alg.selectionTool.TrainingFile = \
439 'ElectronPhotonSelectorTools/ChargeID/ECIDS_20180731rel21Summer2018.root'
440 alg.selectionTool.WorkingPoint =
'Loose'
441 alg.selectionTool.CutOnBDT = -0.337671
444 config.addPrivateTool(
'selectionTool',
'CP::AsgFlagSelectionTool' )
445 alg.selectionTool.selectionFlags = [
"DFCommonElectronsECIDS"]
447 alg.particles = config.readName (self.containerName)
448 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
449 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration)
451 correlationModels = [
"SIMPLIFIED",
"FULL",
"TOTAL",
"TOYS"]
454 if config.dataType()
is not DataType.Data
and not self.noEffSF:
456 if config.geometry()
is LHCPeriod.Run2:
457 raise ValueError(
'Run 2 does not yet have efficiency correction, '
458 'please disable it by setting `noEffSF` to True.')
459 if 'DNN' in self.identificationWP:
460 raise ValueError(
'DNN does not yet have efficiency correction, '
461 'please disable it by setting `noEffSF` to True.')
463 alg = config.createAlgorithm(
'CP::ElectronEfficiencyCorrectionAlg',
464 'ElectronEfficiencyCorrectionAlgReco' + postfix )
465 config.addPrivateTool(
'efficiencyCorrectionTool',
466 'AsgElectronEfficiencyCorrectionTool' )
467 alg.scaleFactorDecoration =
'el_reco_effSF' + selectionPostfix +
'_%SYS%'
468 alg.efficiencyCorrectionTool.RecoKey =
"Reconstruction"
469 if self.correlationModelReco
not in correlationModels:
470 raise ValueError(
'Invalid correlation model for reconstruction efficiency, '
471 f
'has to be one of: {", ".join(correlationModels)}')
472 if config.geometry() >= LHCPeriod.Run3
and self.correlationModelReco !=
"TOTAL":
473 log.warning(
"Only TOTAL correlation model is currently supported "
474 "for reconstruction efficiency correction in Run 3.")
475 alg.efficiencyCorrectionTool.CorrelationModel =
"TOTAL"
477 alg.efficiencyCorrectionTool.CorrelationModel = self.correlationModelReco
478 if config.dataType()
is DataType.FastSim:
479 alg.efficiencyCorrectionTool.ForceDataType = (
480 PATCore.ParticleDataType.Full
if self.forceFullSimConfig
481 else PATCore.ParticleDataType.Fast)
482 elif config.dataType()
is DataType.FullSim:
483 alg.efficiencyCorrectionTool.ForceDataType = \
484 PATCore.ParticleDataType.Full
485 alg.outOfValidity = 2
486 alg.outOfValidityDeco =
'el_reco_bad_eff' + selectionPostfix
487 alg.electrons = config.readName (self.containerName)
488 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
489 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
'reco_effSF' + postfix)
492 if config.dataType()
is not DataType.Data
and not self.noEffSF:
493 alg = config.createAlgorithm(
'CP::ElectronEfficiencyCorrectionAlg',
494 'ElectronEfficiencyCorrectionAlgID' + postfix )
495 config.addPrivateTool(
'efficiencyCorrectionTool',
496 'AsgElectronEfficiencyCorrectionTool' )
497 alg.scaleFactorDecoration =
'el_id_effSF' + selectionPostfix +
'_%SYS%'
498 alg.efficiencyCorrectionTool.IdKey = self.identificationWP.
replace(
"LH",
"")
499 if self.correlationModelId
not in correlationModels:
500 raise ValueError(
'Invalid correlation model for identification efficiency, '
501 f
'has to be one of: {", ".join(correlationModels)}')
502 alg.efficiencyCorrectionTool.CorrelationModel = self.correlationModelId
503 if config.dataType()
is DataType.FastSim:
504 alg.efficiencyCorrectionTool.ForceDataType = (
505 PATCore.ParticleDataType.Full
if self.forceFullSimConfig
506 else PATCore.ParticleDataType.Fast)
507 elif config.dataType()
is DataType.FullSim:
508 alg.efficiencyCorrectionTool.ForceDataType = \
509 PATCore.ParticleDataType.Full
510 alg.outOfValidity = 2
511 alg.outOfValidityDeco =
'el_id_bad_eff' + selectionPostfix
512 alg.electrons = config.readName (self.containerName)
513 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
514 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
'id_effSF' + postfix)
517 if config.dataType()
is not DataType.Data
and self.isolationWP !=
'NonIso' and not self.noEffSF:
518 alg = config.createAlgorithm(
'CP::ElectronEfficiencyCorrectionAlg',
519 'ElectronEfficiencyCorrectionAlgIsol' + postfix )
520 config.addPrivateTool(
'efficiencyCorrectionTool',
521 'AsgElectronEfficiencyCorrectionTool' )
522 alg.scaleFactorDecoration =
'el_isol_effSF' + selectionPostfix +
'_%SYS%'
523 alg.efficiencyCorrectionTool.IdKey = self.identificationWP.
replace(
"LH",
"")
524 alg.efficiencyCorrectionTool.IsoKey = self.isolationWP
525 if self.correlationModelIso
not in correlationModels:
526 raise ValueError(
'Invalid correlation model for isolation efficiency, '
527 f
'has to be one of: {", ".join(correlationModels)}')
528 if config.geometry() >= LHCPeriod.Run3:
529 log.warning(
"Only TOTAL correlation model is currently supported "
530 "for isolation efficiency correction in Run 3.")
531 alg.efficiencyCorrectionTool.CorrelationModel =
"TOTAL"
533 alg.efficiencyCorrectionTool.CorrelationModel = self.correlationModelIso
534 if config.dataType()
is DataType.FastSim:
535 alg.efficiencyCorrectionTool.ForceDataType = (
536 PATCore.ParticleDataType.Full
if self.forceFullSimConfig
537 else PATCore.ParticleDataType.Fast)
538 elif config.dataType()
is DataType.FullSim:
539 alg.efficiencyCorrectionTool.ForceDataType = \
540 PATCore.ParticleDataType.Full
541 alg.outOfValidity = 2
542 alg.outOfValidityDeco =
'el_isol_bad_eff' + selectionPostfix
543 alg.electrons = config.readName (self.containerName)
544 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
545 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
'isol_effSF' + postfix)
549 if self.chargeIDSelectionRun2: