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