294 def makeAlgs (self, config) :
296 log = logging.getLogger(
'ElectronWorkingPointConfig')
298 if self.forceFullSimConfig:
299 log.warning(
"You are running ElectronWorkingPointConfig forcing full sim config")
300 log.warning(
"This is only intended to be used for testing purposes")
302 selectionPostfix = self.selectionName
303 if selectionPostfix !=
'' and selectionPostfix[0] !=
'_' :
304 selectionPostfix =
'_' + selectionPostfix
307 if config.geometry()
is LHCPeriod.Run1:
308 raise ValueError (
"Can't set up the ElectronWorkingPointConfig with %s, there must be something wrong!" % config.geometry().value)
310 postfix = self.postfix
312 postfix = self.selectionName
313 if postfix !=
'' and postfix[0] !=
'_' :
314 postfix =
'_' + postfix
317 if self.writeTrackD0Z0
or self.trackSelection :
318 alg = config.createAlgorithm(
'CP::AsgLeptonTrackSelectionAlg',
319 'ElectronTrackSelectionAlg' + postfix )
320 alg.selectionDecoration =
'trackSelection' + postfix +
',as_bits'
321 alg.maxD0Significance = self.maxD0Significance
322 alg.maxDeltaZ0SinTheta = self.maxDeltaZ0SinTheta
323 alg.decorateTTVAVars = self.writeTrackD0Z0
324 alg.particles = config.readName (self.containerName)
325 alg.preselection = config.getPreselection (self.containerName,
'')
326 if self.trackSelection :
327 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration)
328 if self.writeTrackD0Z0 :
329 alg.d0sigDecoration =
'd0sig' + postfix
330 alg.z0sinthetaDecoration =
'z0sintheta' + postfix
331 config.addOutputVar (self.containerName, alg.d0sigDecoration, alg.d0sigDecoration,noSys=
True)
332 config.addOutputVar (self.containerName, alg.z0sinthetaDecoration, alg.z0sinthetaDecoration,noSys=
True)
334 if 'LH' in self.identificationWP:
337 alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
'ElectronLikelihoodAlg' + postfix )
338 alg.selectionDecoration =
'selectLikelihood' + selectionPostfix +
',as_bits'
341 config.addPrivateTool(
'selectionTool',
'AsgElectronLikelihoodTool' )
342 alg.selectionTool.primaryVertexContainer =
'PrimaryVertices'
345 if config.geometry() >= LHCPeriod.Run3:
346 alg.selectionTool.WorkingPoint = self.identificationWP.
replace(
"BLayer",
"BL") +
'Electron'
347 elif config.geometry()
is LHCPeriod.Run2:
348 alg.selectionTool.WorkingPoint = self.identificationWP.
replace(
"BLayer",
"BL") +
'Electron_Run2'
351 config.addPrivateTool(
'selectionTool',
'CP::AsgFlagSelectionTool' )
352 dfFlag =
"DFCommonElectronsLH" + self.identificationWP.
split(
'LH')[0]
353 dfFlag = dfFlag.replace(
"BLayer",
"BL")
354 alg.selectionTool.selectionFlags = [dfFlag]
355 elif 'SiHit' in self.identificationWP:
357 algVeto = config.createAlgorithm(
'CP::AsgSelectionAlg',
'ElectronLikelihoodAlgVeto' + postfix +
'Veto')
358 algVeto.selectionDecoration =
'selectLikelihoodVeto' + postfix +
',as_bits'
359 config.addPrivateTool(
'selectionTool',
'CP::AsgFlagSelectionTool' )
360 algVeto.selectionTool.selectionFlags = [
"DFCommonElectronsLHLoose"]
361 algVeto.selectionTool.invertFlags = [
True]
362 algVeto.particles = config.readName (self.containerName)
363 algVeto.preselection = config.getPreselection (self.containerName, self.selectionName)
365 config.addSelection (self.containerName, self.selectionName, algVeto.selectionDecoration)
368 alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
'ElectronLikelihoodAlg' + postfix )
369 alg.selectionDecoration =
'selectSiHit' + selectionPostfix +
',as_bits'
371 config.addPrivateTool(
'selectionTool',
'CP::AsgMaskSelectionTool' )
372 dfVar =
"DFCommonElectronsLHLooseBLIsEMValue"
373 alg.selectionTool.selectionVars = [dfVar]
374 mask =
int( 0 | 0x1 << 1 | 0x1 << 2)
375 alg.selectionTool.selectionMasks = [mask]
378 algDec = config.createAlgorithm(
'CP::ElectronSiHitDecAlg',
'ElectronSiHitDecAlg' + postfix )
379 selDec =
'siHitEvtHasLeptonPair' + selectionPostfix +
',as_bits'
380 algDec.selectionName = selDec.split(
",")[0]
381 algDec.ElectronContainer = config.readName (self.containerName)
383 algDec.RequireTwoLeptons =
True
384 config.addSelection (self.containerName, self.selectionName, selDec)
385 elif 'DNN' in self.identificationWP:
386 if self.chargeIDSelectionRun2:
387 raise ValueError(
'DNN is not intended to be used with '
388 '`chargeIDSelectionRun2` option as there are '
389 'DNN WPs containing charge flip rejection.')
391 alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
'ElectronDNNAlg' + postfix )
392 alg.selectionDecoration =
'selectDNN' + selectionPostfix +
',as_bits'
395 config.addPrivateTool(
'selectionTool',
'AsgElectronSelectorTool' )
397 if config.geometry()
is LHCPeriod.Run3:
398 raise ValueError (
"DNN working points are not available for Run 3 yet.")
400 alg.selectionTool.WorkingPoint = self.identificationWP +
'Electron'
403 config.addPrivateTool(
'selectionTool',
'CP::AsgFlagSelectionTool' )
404 dfFlag =
"DFCommonElectronsDNN" + self.identificationWP.
split(
'DNN')[0]
405 alg.selectionTool.selectionFlags = [dfFlag]
407 alg.particles = config.readName (self.containerName)
408 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
409 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration)
412 if self.doFSRSelection :
414 wpFlag = alg.selectionDecoration.split(
",")[0]
415 alg = config.createAlgorithm(
'CP::EgammaFSRForMuonsCollectorAlg',
'EgammaFSRForMuonsCollectorAlg' + postfix )
416 alg.selectionDecoration = wpFlag
417 alg.ElectronOrPhotonContKey = config.readName (self.containerName)
421 if 'SiHit' in self.identificationWP:
425 if self.isolationWP !=
'NonIso' :
426 alg = config.createAlgorithm(
'CP::EgammaIsolationSelectionAlg',
427 'ElectronIsolationSelectionAlg' + postfix )
428 alg.selectionDecoration =
'isolated' + selectionPostfix +
',as_bits'
429 config.addPrivateTool(
'selectionTool',
'CP::IsolationSelectionTool' )
430 alg.selectionTool.ElectronWP = self.isolationWP
431 if self.closeByCorrection:
432 alg.selectionTool.IsoDecSuffix =
"CloseByCorr"
433 alg.egammas = config.readName (self.containerName)
434 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
435 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration)
437 if self.chargeIDSelectionRun2
and config.geometry() >= LHCPeriod.Run3:
438 log.warning(
"ECIDS is only available for Run 2 and will not have effect in run 3.")
441 if self.chargeIDSelectionRun2
and config.geometry() < LHCPeriod.Run3:
442 alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
443 'ElectronChargeIDSelectionAlg' + postfix )
444 alg.selectionDecoration =
'chargeID' + selectionPostfix +
',as_bits'
445 if self.recomputeChargeID:
447 config.addPrivateTool(
'selectionTool',
448 'AsgElectronChargeIDSelectorTool' )
449 alg.selectionTool.TrainingFile = \
450 'ElectronPhotonSelectorTools/ChargeID/ECIDS_20180731rel21Summer2018.root'
451 alg.selectionTool.WorkingPoint =
'Loose'
452 alg.selectionTool.CutOnBDT = -0.337671
455 config.addPrivateTool(
'selectionTool',
'CP::AsgFlagSelectionTool' )
456 alg.selectionTool.selectionFlags = [
"DFCommonElectronsECIDS"]
458 alg.particles = config.readName (self.containerName)
459 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
460 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration)
462 correlationModels = [
"SIMPLIFIED",
"FULL",
"TOTAL",
"TOYS"]
465 if config.dataType()
is not DataType.Data
and not self.noEffSF:
467 if config.geometry()
is LHCPeriod.Run2:
468 raise ValueError(
'Run 2 does not yet have efficiency correction, '
469 'please disable it by setting `noEffSF` to True.')
470 if 'DNN' in self.identificationWP:
471 raise ValueError(
'DNN does not yet have efficiency correction, '
472 'please disable it by setting `noEffSF` to True.')
474 alg = config.createAlgorithm(
'CP::ElectronEfficiencyCorrectionAlg',
475 'ElectronEfficiencyCorrectionAlgReco' + postfix )
476 config.addPrivateTool(
'efficiencyCorrectionTool',
477 'AsgElectronEfficiencyCorrectionTool' )
478 alg.scaleFactorDecoration =
'el_reco_effSF' + selectionPostfix +
'_%SYS%'
479 alg.efficiencyCorrectionTool.RecoKey =
"Reconstruction"
480 if self.correlationModelReco
not in correlationModels:
481 raise ValueError(
'Invalid correlation model for reconstruction efficiency, '
482 f
'has to be one of: {", ".join(correlationModels)}')
483 if config.geometry() >= LHCPeriod.Run3
and self.correlationModelReco !=
"TOTAL":
484 log.warning(
"Only TOTAL correlation model is currently supported "
485 "for reconstruction efficiency correction in Run 3.")
486 alg.efficiencyCorrectionTool.CorrelationModel =
"TOTAL"
488 alg.efficiencyCorrectionTool.CorrelationModel = self.correlationModelReco
489 if config.dataType()
is DataType.FastSim:
490 alg.efficiencyCorrectionTool.ForceDataType = (
491 PATCore.ParticleDataType.Full
if self.forceFullSimConfig
492 else PATCore.ParticleDataType.Fast)
493 elif config.dataType()
is DataType.FullSim:
494 alg.efficiencyCorrectionTool.ForceDataType = \
495 PATCore.ParticleDataType.Full
496 alg.outOfValidity = 2
497 alg.outOfValidityDeco =
'el_reco_bad_eff' + selectionPostfix
498 alg.electrons = config.readName (self.containerName)
499 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
500 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
'reco_effSF' + postfix)
503 if config.dataType()
is not DataType.Data
and not self.noEffSF:
504 alg = config.createAlgorithm(
'CP::ElectronEfficiencyCorrectionAlg',
505 'ElectronEfficiencyCorrectionAlgID' + postfix )
506 config.addPrivateTool(
'efficiencyCorrectionTool',
507 'AsgElectronEfficiencyCorrectionTool' )
508 alg.scaleFactorDecoration =
'el_id_effSF' + selectionPostfix +
'_%SYS%'
509 alg.efficiencyCorrectionTool.IdKey = self.identificationWP.
replace(
"LH",
"")
510 if self.correlationModelId
not in correlationModels:
511 raise ValueError(
'Invalid correlation model for identification efficiency, '
512 f
'has to be one of: {", ".join(correlationModels)}')
513 alg.efficiencyCorrectionTool.CorrelationModel = self.correlationModelId
514 if config.dataType()
is DataType.FastSim:
515 alg.efficiencyCorrectionTool.ForceDataType = (
516 PATCore.ParticleDataType.Full
if self.forceFullSimConfig
517 else PATCore.ParticleDataType.Fast)
518 elif config.dataType()
is DataType.FullSim:
519 alg.efficiencyCorrectionTool.ForceDataType = \
520 PATCore.ParticleDataType.Full
521 alg.outOfValidity = 2
522 alg.outOfValidityDeco =
'el_id_bad_eff' + selectionPostfix
523 alg.electrons = config.readName (self.containerName)
524 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
525 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
'id_effSF' + postfix)
528 if config.dataType()
is not DataType.Data
and self.isolationWP !=
'NonIso' and not self.noEffSF:
529 alg = config.createAlgorithm(
'CP::ElectronEfficiencyCorrectionAlg',
530 'ElectronEfficiencyCorrectionAlgIsol' + postfix )
531 config.addPrivateTool(
'efficiencyCorrectionTool',
532 'AsgElectronEfficiencyCorrectionTool' )
533 alg.scaleFactorDecoration =
'el_isol_effSF' + selectionPostfix +
'_%SYS%'
534 alg.efficiencyCorrectionTool.IdKey = self.identificationWP.
replace(
"LH",
"")
535 alg.efficiencyCorrectionTool.IsoKey = self.isolationWP
536 if self.correlationModelIso
not in correlationModels:
537 raise ValueError(
'Invalid correlation model for isolation efficiency, '
538 f
'has to be one of: {", ".join(correlationModels)}')
539 if config.geometry() >= LHCPeriod.Run3:
540 log.warning(
"Only TOTAL correlation model is currently supported "
541 "for isolation efficiency correction in Run 3.")
542 alg.efficiencyCorrectionTool.CorrelationModel =
"TOTAL"
544 alg.efficiencyCorrectionTool.CorrelationModel = self.correlationModelIso
545 if config.dataType()
is DataType.FastSim:
546 alg.efficiencyCorrectionTool.ForceDataType = (
547 PATCore.ParticleDataType.Full
if self.forceFullSimConfig
548 else PATCore.ParticleDataType.Fast)
549 elif config.dataType()
is DataType.FullSim:
550 alg.efficiencyCorrectionTool.ForceDataType = \
551 PATCore.ParticleDataType.Full
552 alg.outOfValidity = 2
553 alg.outOfValidityDeco =
'el_isol_bad_eff' + selectionPostfix
554 alg.electrons = config.readName (self.containerName)
555 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
556 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
'isol_effSF' + postfix)
560 if self.chargeIDSelectionRun2: