ATLAS Offline Software
Loading...
Searching...
No Matches
python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig Class Reference
Inheritance diagram for python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig:
Collaboration diagram for python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig:

Public Member Functions

 __init__ (self)
 instanceName (self)
 makeAlgs (self, config)

Public Attributes

str identificationWP = 'NoID' and self.doFSRSelection:
 trackSelection
 containerName
 selectionName
 recomputeID
 chargeIDSelectionRun2
 doFSRSelection
str convSelection = "Veto":
 closeByCorrection
 recomputeChargeID

Detailed Description

the ConfigBlock for the electron working point selection

Definition at line 361 of file ElectronAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.__init__ ( self)

Definition at line 364 of file ElectronAnalysisConfig.py.

364 def __init__ (self) :
365 super (ElectronWorkingPointSelectionConfig, self).__init__ ()
366 self.setBlockName('ElectronWorkingPointSelection')
367 self.addOption ('containerName', '', type=str,
368 noneAction='error',
369 info="the name of the input container.",
370 meta={'role':'containerRef'})
371 self.addOption ('selectionName', '', type=str,
372 noneAction='error',
373 info="the name of the electron selection to define (e.g. `tight` or "
374 "`loose`).",
375 meta={'role':'selection'})
376 self.addOption ('postfix', None, type=str,
377 info="a postfix to apply to decorations and algorithm names. "
378 "Typically not needed here as `selectionName` is used internally.")
379 self.addOption ('trackSelection', True, type=bool,
380 info="whether or not to set up an instance of "
381 "`CP::AsgLeptonTrackSelectionAlg`, with the recommended $d_0$ and "
382 r"$z_0\sin\theta$ cuts.")
383 self.addOption ('maxD0Significance', 5, type=float,
384 info="maximum $d_0$ significance used for the track selection.")
385 self.addOption ('maxDeltaZ0SinTheta', 0.5, type=float,
386 info=r"maximum $z_0\sin\theta$ (in mm) used for the track selection.")
387 self.addOption ('identificationWP', None, type=str,
388 info="the ID WP to use. Supported ID WPs: `TightLH`, "
389 "`MediumLH`, `LooseBLayerLH`, `TightDNN`, `MediumDNN`, `LooseDNN`, "
390 "`TightNoCFDNN`, `MediumNoCFDNN`, `VeryLooseNoCF97DNN`, `NoID`.",
391 expertMode=["NoID"],
392 meta={'choices':(['MediumLH', 'LooseBLayerLH', 'TightDNN', 'MediumDNN', 'LooseDNN',
393 'TightNoCFDNN', 'MediumNoCFDNN', 'VeryLooseNoCF97DNN', 'NoID'],1)})
394 self.addOption ('isolationWP', None, type=str,
395 info="the isolation WP to use. Supported isolation WPs: "
396 "`HighPtCaloOnly`, `Loose_VarRad`, `Tight_VarRad`, `TightTrackOnly_"
397 "VarRad`, `TightTrackOnly_FixedRad`, `NonIso`.",
398 meta={'choices':(['HighPtCaloOnly', 'Loose_VarRad', 'Tight_VarRad', 'TightTrackOnly_VarRad',
399 'TightTrackOnly_FixedRad', 'NonIso'],1)})
400 self.addOption ('convSelection', None, type=str,
401 info="enter additional selection to use for conversions. To be used with "
402 "`TightLH` or will crash. Supported keywords:"
403 "`Veto`, `MatConv`, `GammaStar`.",
404 meta={'choices':(['Veto', 'MatConv', 'GammaStar'],1)})
405 self.addOption ('addSelectionToPreselection', True, type=bool,
406 info="whether to retain only electrons satisfying the working point "
407 "requirements.")
408 self.addOption ('closeByCorrection', False, type=bool,
409 info="whether to use close-by-corrected isolation working points.")
410 self.addOption ('recomputeID', False, type=bool,
411 info="whether to rerun the ID LH/DNN, or rely on derivation flags.")
412 self.addOption ('chargeIDSelectionRun2', False, type=bool,
413 info="whether to run the ECIDS tool. Only available for Run 2.")
414 self.addOption ('recomputeChargeID', False, type=bool,
415 info="whether to rerun the ECIDS, or rely on derivation flags.")
416 self.addOption ('doFSRSelection', False, type=bool,
417 info="whether to accept additional electrons close to muons for "
418 "the purpose of FSR corrections to these muons. Expert feature "
419 "requested by the H4l analysis running on PHYSLITE.",
420 expertMode=True)
421 self.addOption ('muonsForFSRSelection', None, type=str,
422 info="the name of the muon container to use for the FSR selection. "
423 "If not specified, AnalysisMuons is used.",
424 expertMode=True)
425 self.addOption ('mainElectronContainer', None, type=str,
426 info="the name of the main electron container to use for the SiHit selection. "
427 "If not specified, this defaults to AnalysisElectrons.",
428 expertMode=True)
429

Member Function Documentation

◆ instanceName()

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.instanceName ( self)
Return the instance name for this block

Definition at line 430 of file ElectronAnalysisConfig.py.

430 def instanceName (self) :
431 """Return the instance name for this block"""
432 if self.postfix is not None :
433 return self.containerName + '_' + self.selectionName + self.postfix
434 return self.containerName + '_' + self.selectionName
435

◆ makeAlgs()

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.makeAlgs ( self,
config )

Definition at line 436 of file ElectronAnalysisConfig.py.

436 def makeAlgs (self, config) :
437
438 selectionPostfix = self.selectionName
439 if selectionPostfix != '' and selectionPostfix[0] != '_' :
440 selectionPostfix = '_' + selectionPostfix
441
442 # The setup below is inappropriate for Run 1
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 # Set up the track selection algorithm:
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 # Set up the likelihood ID selection algorithm
473 # It is safe to do this before calibration, as the cluster E is used
474 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' )
475 alg.selectionDecoration = 'selectLikelihood' + selectionPostfix + ',as_char'
476 if self.recomputeID:
477 # Rerun the likelihood ID
478 config.addPrivateTool( 'selectionTool', 'AsgElectronLikelihoodTool' )
479 alg.selectionTool.primaryVertexContainer = 'PrimaryVertices'
480 # Here we have to match the naming convention of EGSelectorConfigurationMapping.h
481 # which differ from the one used for scale factors
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 # Select from Derivation Framework flags
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 # Only want SiHit electrons, so veto loose LH electrons
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 # add the veto as a selection
505 config.addSelection (self.containerName, self.selectionName, algVeto.selectionDecoration,
506 preselection=self.addSelectionToPreselection)
507
508 # Select SiHit electrons using IsEM bits
509 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' )
510 alg.selectionDecoration = 'selectSiHit' + selectionPostfix + ',as_char'
511 # Select from Derivation Framework IsEM bits
512 config.addPrivateTool( 'selectionTool', 'CP::AsgMaskSelectionTool' )
513 dfVar = "DFCommonElectronsLHLooseBLIsEMValue"
514 alg.selectionTool.selectionVars = [dfVar]
515 mask = 0x6 # IsEM bits 1 and 2
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 # Set up the DNN ID selection algorithm
523 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronDNNAlg' )
524 alg.selectionDecoration = 'selectDNN' + selectionPostfix + ',as_char'
525 if self.recomputeID:
526 # Rerun the DNN ID
527 config.addPrivateTool( 'selectionTool', 'AsgElectronSelectorTool' )
528 # Here we have to match the naming convention of ElectronPhotonSelectorTools/Root/EGSelectorConfigurationMapping.h
529 alg.selectionTool.WorkingPoint = self.identificationWP + 'Electron'
530 else:
531 # Select from Derivation Framework flags
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 # Don't register WP selection here if FSR enabled - FSR algorithm will create combined selection
546 if not self.doFSRSelection:
547 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
548 preselection=self.addSelectionToPreselection)
549
550 # maintain order of selections
551 if 'SiHit' in self.identificationWP:
552 # Set up the ElectronSiHitDecAlg algorithm to decorate SiHit electrons with a minimal amount of information:
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 # Set flag to only collect SiHit electrons for events with an electron or muon pair to minimize size increase from SiHit electrons
562 algDec.RequireTwoLeptons = True
563 config.addSelection (self.containerName, self.selectionName, selDec,
564 preselection=self.addSelectionToPreselection)
565
566 # Additional selection for conversions and gamma*
567 if self.convSelection is not None:
568 # skip if not applied together with TightLH
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 # check if allowed value
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 # ambiguityType == 0
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 # DFCommonAddAmbiguity selection
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 # Set up the FSR selection
610 if self.doFSRSelection :
611 # wpSelection needs the type suffix so SysReadSelectionHandle knows the type
612 # selectionDecoration needs name only for SysWriteDecorHandle
613 wpDecorationName = wpDecoration.split(',')[0]
614 # Insert FSR before the postfix (e.g., selectSiHit_SiHits -> selectSiHitFSR_SiHits)
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 # Input: read the WP selection (with type suffix)
621 alg.selectionDecoration = outputDecorationName # Output: combined WP||FSR (or WP&&!FSR for vetoFSR) (name only)
622 alg.ElectronOrPhotonContKey = config.readName (self.containerName)
623 if self.muonsForFSRSelection is not None:
624 alg.MuonContKey = config.readName (self.muonsForFSRSelection)
625 # For SiHit electrons, set flag to remove FSR electrons.
626 # For standard electrons, FSR electrons need to be added as they may be missed by the standard selection.
627 # For SiHit electrons FSR electrons are generally always selected, so they should be removed since they will be in the standard electron container.
628 if 'SiHit' in self.identificationWP:
629 alg.vetoFSR = True
630
631 # Register the FSR COMBINED selection
632 config.addSelection (self.containerName, self.selectionName,
633 alg.selectionDecoration + ',as_char',
634 preselection=self.addSelectionToPreselection)
635
636 # Set up the isolation selection algorithm:
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 # Select electrons only if they don't appear to have flipped their charge.
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 # Rerun the ECIDS BDT
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 # Loose 97%
669 else:
670 # Select from Derivation Framework flags
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)
Definition hcg.cxx:312
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

Member Data Documentation

◆ chargeIDSelectionRun2

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.chargeIDSelectionRun2

Definition at line 518 of file ElectronAnalysisConfig.py.

◆ closeByCorrection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.closeByCorrection

Definition at line 643 of file ElectronAnalysisConfig.py.

◆ containerName

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.containerName

Definition at line 468 of file ElectronAnalysisConfig.py.

◆ convSelection

str python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.convSelection = "Veto":

Definition at line 595 of file ElectronAnalysisConfig.py.

◆ doFSRSelection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.doFSRSelection

Definition at line 546 of file ElectronAnalysisConfig.py.

◆ identificationWP

str python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.identificationWP = 'NoID' and self.doFSRSelection:

Definition at line 448 of file ElectronAnalysisConfig.py.

◆ recomputeChargeID

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.recomputeChargeID

Definition at line 661 of file ElectronAnalysisConfig.py.

◆ recomputeID

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.recomputeID

Definition at line 476 of file ElectronAnalysisConfig.py.

◆ selectionName

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.selectionName

Definition at line 468 of file ElectronAnalysisConfig.py.

◆ trackSelection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.trackSelection

Definition at line 459 of file ElectronAnalysisConfig.py.


The documentation for this class was generated from the following file: