436 def makeAlgs (self, config) :
437
438 selectionPostfix = self.selectionName
439 if selectionPostfix != '' and selectionPostfix[0] != '_' :
440 selectionPostfix = '_' + selectionPostfix
441
442
443 if config.geometry() is LHCPeriod.Run1:
444 raise ValueError ("Can't set up the ElectronWorkingPointSelectionConfig with %s, there must be something wrong!" % config.geometry().value)
445
446 if self.identificationWP is None:
447 raise ValueError ("ElectronWorkingPointSelectionConfig: the identificationWP option must be set")
448 if self.identificationWP == 'NoID' and self.doFSRSelection:
449 raise ValueError ("ElectronWorkingPointSelectionConfig: doFSRSelection requires an ID working point, "
450 "it can't be used with identificationWP='NoID'")
451
452 postfix = self.postfix
453 if postfix is None :
454 postfix = self.selectionName
455 if postfix != '' and postfix[0] != '_' :
456 postfix = '_' + postfix
457
458
459 if self.trackSelection :
460 alg = config.createAlgorithm( 'CP::AsgLeptonTrackSelectionAlg',
461 'ElectronTrackSelectionAlg',
462 reentrant=True )
463 alg.selectionDecoration = 'trackSelection' + postfix + ',as_bits'
464 alg.maxD0Significance = self.maxD0Significance
465 alg.maxDeltaZ0SinTheta = self.maxDeltaZ0SinTheta
466 alg.particles = config.readName (self.containerName)
467 alg.preselection = config.getPreselection (self.containerName, '')
468 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
469 preselection=self.addSelectionToPreselection)
470
471 if 'LH' in self.identificationWP:
472
473
474 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' )
475 alg.selectionDecoration = 'selectLikelihood' + selectionPostfix + ',as_char'
476 if self.recomputeID:
477
478 config.addPrivateTool( 'selectionTool', 'AsgElectronLikelihoodTool' )
479 alg.selectionTool.primaryVertexContainer = 'PrimaryVertices'
480
481
482 if config.geometry() >= LHCPeriod.Run3:
483 if 'HI' not in self.identificationWP:
484 alg.selectionTool.WorkingPoint = self.identificationWP.
replace(
"BLayer",
"BL") +
'Electron'
485 else:
486 alg.selectionTool.WorkingPoint = self.identificationWP.
replace(
'_HI',
'Electron_HI')
487 elif config.geometry() is LHCPeriod.Run2:
488 alg.selectionTool.WorkingPoint = self.identificationWP.
replace(
"BLayer",
"BL") +
'Electron_Run2'
489 else:
490
491 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
492 dfFlag =
"DFCommonElectronsLH" + self.identificationWP.
split(
'LH')[0]
493 dfFlag = dfFlag.replace("BLayer","BL")
494 alg.selectionTool.selectionFlags = [dfFlag]
495 elif 'SiHit' in self.identificationWP:
496
497 algVeto = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlgVeto')
498 algVeto.selectionDecoration = 'selectLikelihoodVeto' + postfix + ',as_char'
499 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
500 algVeto.selectionTool.selectionFlags = ["DFCommonElectronsLHLoose"]
501 algVeto.selectionTool.invertFlags = [True]
502 algVeto.particles = config.readName (self.containerName)
503 algVeto.preselection = config.getPreselection (self.containerName, self.selectionName)
504
505 config.addSelection (self.containerName, self.selectionName, algVeto.selectionDecoration,
506 preselection=self.addSelectionToPreselection)
507
508
509 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' )
510 alg.selectionDecoration = 'selectSiHit' + selectionPostfix + ',as_char'
511
512 config.addPrivateTool( 'selectionTool', 'CP::AsgMaskSelectionTool' )
513 dfVar = "DFCommonElectronsLHLooseBLIsEMValue"
514 alg.selectionTool.selectionVars = [dfVar]
515 mask = 0x6
516 alg.selectionTool.selectionMasks = [mask]
517 elif 'DNN' in self.identificationWP:
518 if self.chargeIDSelectionRun2:
519 raise ValueError('DNN is not intended to be used with '
520 '`chargeIDSelectionRun2` option as there are '
521 'DNN WPs containing charge flip rejection.')
522
523 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronDNNAlg' )
524 alg.selectionDecoration = 'selectDNN' + selectionPostfix + ',as_char'
525 if self.recomputeID:
526
527 config.addPrivateTool( 'selectionTool', 'AsgElectronSelectorTool' )
528
529 alg.selectionTool.WorkingPoint = self.identificationWP + 'Electron'
530 else:
531
532 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
533 dfFlag =
"DFCommonElectronsDNN" + self.identificationWP.
split(
'DNN')[0]
534 alg.selectionTool.selectionFlags = [dfFlag]
535 elif self.identificationWP == 'NoID':
536 alg = None
537 else:
538 raise ValueError (f"Electron ID working point '{self.identificationWP}' is not recognised!")
539
540 wpDecoration = None
541 if alg is not None:
542 wpDecoration = alg.selectionDecoration
543 alg.particles = config.readName (self.containerName)
544 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
545
546 if not self.doFSRSelection:
547 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
548 preselection=self.addSelectionToPreselection)
549
550
551 if 'SiHit' in self.identificationWP:
552
553 algDec = config.createAlgorithm( 'CP::ElectronSiHitDecAlg', 'ElectronSiHitDecAlg' )
554 selDec = 'siHitEvtHasLeptonPair' + selectionPostfix + ',as_char'
555 algDec.selectionName = selDec.split(",")[0]
556 algDec.ElectronContainer = config.readName (self.containerName)
557 if self.muonsForFSRSelection is not None:
558 algDec.AnalMuonContKey = config.readName (self.muonsForFSRSelection)
559 if self.mainElectronContainer is not None:
560 algDec.AnalElectronContKey = config.readName (self.mainElectronContainer)
561
562 algDec.RequireTwoLeptons = True
563 config.addSelection (self.containerName, self.selectionName, selDec,
564 preselection=self.addSelectionToPreselection)
565
566
567 if self.convSelection is not None:
568
569 if self.identificationWP != 'TightLH':
570 raise ValueError(f"convSelection can only be used with TightLH ID, "
571 f"whereas {self.identificationWP} has been selected. convSelection option will be ignored.")
572
573 allowedValues = ["Veto", "GammaStar", "MatConv"]
574 if self.convSelection not in allowedValues:
575 raise ValueError(f"convSelection has been set to {self.convSelection}, which is not a valid option. "
576 f"convSelection option must be one of {allowedValues}.")
577
578
579 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronAmbiguityTypeAlg' )
580 alg.selectionDecoration = 'selectAmbiguityType' + selectionPostfix + ',as_char'
581 config.addPrivateTool( 'selectionTool', 'CP::AsgNumDecorationSelectionToolUInt8' )
582 alg.selectionTool.decorationName = "ambiguityType"
583 alg.selectionTool.doEqual = True
584 alg.selectionTool.equal = 0
585 alg.particles = config.readName (self.containerName)
586 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
587 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
588 preselection=self.addSelectionToPreselection)
589
590
591 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronDFCommonAddAmbiguityAlg' )
592 alg.selectionDecoration = 'selectDFCommonAddAmbiguity' + selectionPostfix + ',as_char'
593 config.addPrivateTool( 'selectionTool', 'CP::AsgNumDecorationSelectionToolInt' )
594 alg.selectionTool.decorationName = "DFCommonAddAmbiguity"
595 if self.convSelection == "Veto":
596 alg.selectionTool.doMax = True
597 alg.selectionTool.max = 1
598 elif self.convSelection == "GammaStar":
599 alg.selectionTool.doEqual = True
600 alg.selectionTool.equal = 1
601 elif self.convSelection == "MatConv":
602 alg.selectionTool.doEqual = True
603 alg.selectionTool.equal = 2
604 alg.particles = config.readName (self.containerName)
605 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
606 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
607 preselection=self.addSelectionToPreselection)
608
609
610 if self.doFSRSelection :
611
612
613 wpDecorationName = wpDecoration.split(',')[0]
614
615 underscorePos = wpDecorationName.find('_')
616 if underscorePos < 0:
617 underscorePos = len(wpDecorationName)
618 outputDecorationName = wpDecorationName[:underscorePos] + 'FSR' + wpDecorationName[underscorePos:]
619 alg = config.createAlgorithm( 'CP::EgammaFSRForMuonsCollectorAlg', 'EgammaFSRForMuonsCollectorAlg' )
620 alg.wpSelection = wpDecoration
621 alg.selectionDecoration = outputDecorationName
622 alg.ElectronOrPhotonContKey = config.readName (self.containerName)
623 if self.muonsForFSRSelection is not None:
624 alg.MuonContKey = config.readName (self.muonsForFSRSelection)
625
626
627
628 if 'SiHit' in self.identificationWP:
629 alg.vetoFSR = True
630
631
632 config.addSelection (self.containerName, self.selectionName,
633 alg.selectionDecoration + ',as_char',
634 preselection=self.addSelectionToPreselection)
635
636
637 if self.isolationWP != 'NonIso' :
638 alg = config.createAlgorithm( 'CP::EgammaIsolationSelectionAlg',
639 'ElectronIsolationSelectionAlg' )
640 alg.selectionDecoration = 'isolated' + selectionPostfix + ',as_char'
641 config.addPrivateTool( 'selectionTool', 'CP::IsolationSelectionTool' )
642 alg.selectionTool.ElectronWP = self.isolationWP
643 if self.closeByCorrection:
644 alg.selectionTool.IsoDecSuffix = "CloseByCorr"
645 alg.egammas = config.readName (self.containerName)
646 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
647 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
648 preselection=self.addSelectionToPreselection)
649
650 if self.chargeIDSelectionRun2 and config.geometry() >= LHCPeriod.Run3:
651 warnings.warn_explicit(
652 "ECIDS is only available for Run 2 and will not have any"
653 " effect in Run 3.",
654 Run2OnlyFeatureWarning, filename='', lineno=0)
655
656
657 if self.chargeIDSelectionRun2 and config.geometry() < LHCPeriod.Run3:
658 alg = config.createAlgorithm( 'CP::AsgSelectionAlg',
659 'ElectronChargeIDSelectionAlg' )
660 alg.selectionDecoration = 'chargeID' + selectionPostfix + ',as_char'
661 if self.recomputeChargeID:
662
663 config.addPrivateTool( 'selectionTool',
664 'AsgElectronChargeIDSelectorTool' )
665 alg.selectionTool.TrainingFile = \
666 'ElectronPhotonSelectorTools/ChargeID/ECIDS_20180731rel21Summer2018.root'
667 alg.selectionTool.WorkingPoint = 'Loose'
668 alg.selectionTool.CutOnBDT = -0.337671
669 else:
670
671 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
672 alg.selectionTool.selectionFlags = ["DFCommonElectronsECIDS"]
673
674 alg.particles = config.readName (self.containerName)
675 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
676 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
677 preselection=self.addSelectionToPreselection)
678
679
std::string replace(std::string s, const std::string &s2, const std::string &s3)
std::vector< std::string > split(const std::string &s, const std::string &t=":")