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

 trackSelection
 containerName
 selectionName
str identificationWP
 recomputeID
 chargeIDSelectionRun2
 doFSRSelection
str convSelection = "Veto":
 closeByCorrection
 recomputeChargeID

Detailed Description

the ConfigBlock for the electron working point selection

Definition at line 336 of file ElectronAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.__init__ ( self)

Definition at line 339 of file ElectronAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 405 of file ElectronAnalysisConfig.py.

405 def instanceName (self) :
406 """Return the instance name for this block"""
407 if self.postfix is not None :
408 return self.containerName + '_' + self.selectionName + self.postfix
409 return self.containerName + '_' + self.selectionName
410

◆ makeAlgs()

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

Definition at line 411 of file ElectronAnalysisConfig.py.

411 def makeAlgs (self, config) :
412
413 selectionPostfix = self.selectionName
414 if selectionPostfix != '' and selectionPostfix[0] != '_' :
415 selectionPostfix = '_' + selectionPostfix
416
417 # The setup below is inappropriate for Run 1
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 # Set up the track selection algorithm:
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 # Set up the likelihood ID selection algorithm
443 # It is safe to do this before calibration, as the cluster E is used
444 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' )
445 alg.selectionDecoration = 'selectLikelihood' + selectionPostfix + ',as_char'
446 if self.recomputeID:
447 # Rerun the likelihood ID
448 config.addPrivateTool( 'selectionTool', 'AsgElectronLikelihoodTool' )
449 alg.selectionTool.primaryVertexContainer = 'PrimaryVertices'
450 # Here we have to match the naming convention of EGSelectorConfigurationMapping.h
451 # which differ from the one used for scale factors
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 # Select from Derivation Framework flags
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 # Only want SiHit electrons, so veto loose LH electrons
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 # add the veto as a selection
475 config.addSelection (self.containerName, self.selectionName, algVeto.selectionDecoration,
476 preselection=self.addSelectionToPreselection)
477
478 # Select SiHit electrons using IsEM bits
479 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' )
480 alg.selectionDecoration = 'selectSiHit' + selectionPostfix + ',as_char'
481 # Select from Derivation Framework IsEM bits
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 # Set up the DNN ID selection algorithm
493 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronDNNAlg' )
494 alg.selectionDecoration = 'selectDNN' + selectionPostfix + ',as_char'
495 if self.recomputeID:
496 # Rerun the DNN ID
497 config.addPrivateTool( 'selectionTool', 'AsgElectronSelectorTool' )
498 # Here we have to match the naming convention of ElectronPhotonSelectorTools/Root/EGSelectorConfigurationMapping.h
499 alg.selectionTool.WorkingPoint = self.identificationWP + 'Electron'
500 else:
501 # Select from Derivation Framework flags
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 # Don't register WP selection here if FSR enabled - FSR algorithm will create combined selection
514 if not self.doFSRSelection:
515 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
516 preselection=self.addSelectionToPreselection)
517
518 # maintain order of selections
519 if 'SiHit' in self.identificationWP:
520 # Set up the ElectronSiHitDecAlg algorithm to decorate SiHit electrons with a minimal amount of information:
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 # Set flag to only collect SiHit electrons for events with an electron or muon pair to minimize size increase from SiHit electrons
530 algDec.RequireTwoLeptons = True
531 config.addSelection (self.containerName, self.selectionName, selDec,
532 preselection=self.addSelectionToPreselection)
533
534 # Additional selection for conversions and gamma*
535 if self.convSelection is not None:
536 # skip if not applied together with TightLH
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 # check if allowed value
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 # ambiguityType == 0
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 # DFCommonAddAmbiguity selection
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 # Set up the FSR selection
578 if self.doFSRSelection :
579 # wpSelection needs the type suffix so SysReadSelectionHandle knows the type
580 # selectionDecoration needs name only for SysWriteDecorHandle
581 wpDecoration = alg.selectionDecoration
582 wpDecorationName = wpDecoration.split(',')[0]
583 # Insert FSR before the postfix (e.g., selectSiHit_SiHits -> selectSiHitFSR_SiHits)
584 underscorePos = wpDecorationName.index('_')
585 outputDecorationName = wpDecorationName[:underscorePos] + 'FSR' + wpDecorationName[underscorePos:]
586 alg = config.createAlgorithm( 'CP::EgammaFSRForMuonsCollectorAlg', 'EgammaFSRForMuonsCollectorAlg' )
587 alg.wpSelection = wpDecoration # Input: read the WP selection (with type suffix)
588 alg.selectionDecoration = outputDecorationName # Output: combined WP||FSR (or WP&&!FSR for vetoFSR) (name only)
589 alg.ElectronOrPhotonContKey = config.readName (self.containerName)
590 if self.muonsForFSRSelection is not None:
591 alg.MuonContKey = config.readName (self.muonsForFSRSelection)
592 # For SiHit electrons, set flag to remove FSR electrons.
593 # For standard electrons, FSR electrons need to be added as they may be missed by the standard selection.
594 # For SiHit electrons FSR electrons are generally always selected, so they should be removed since they will be in the standard electron container.
595 if 'SiHit' in self.identificationWP:
596 alg.vetoFSR = True
597
598 # Register the FSR COMBINED selection
599 config.addSelection (self.containerName, self.selectionName,
600 alg.selectionDecoration + ',as_char',
601 preselection=self.addSelectionToPreselection)
602
603 # Set up the isolation selection algorithm:
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 # Select electrons only if they don't appear to have flipped their charge.
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 # Rerun the ECIDS BDT
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 # Loose 97%
636 else:
637 # Select from Derivation Framework flags
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)
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 488 of file ElectronAnalysisConfig.py.

◆ closeByCorrection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.closeByCorrection

Definition at line 610 of file ElectronAnalysisConfig.py.

◆ containerName

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.containerName

Definition at line 438 of file ElectronAnalysisConfig.py.

◆ convSelection

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

Definition at line 563 of file ElectronAnalysisConfig.py.

◆ doFSRSelection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.doFSRSelection

Definition at line 514 of file ElectronAnalysisConfig.py.

◆ identificationWP

str python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.identificationWP

Definition at line 441 of file ElectronAnalysisConfig.py.

◆ recomputeChargeID

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.recomputeChargeID

Definition at line 628 of file ElectronAnalysisConfig.py.

◆ recomputeID

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.recomputeID

Definition at line 446 of file ElectronAnalysisConfig.py.

◆ selectionName

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.selectionName

Definition at line 438 of file ElectronAnalysisConfig.py.

◆ trackSelection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.trackSelection

Definition at line 428 of file ElectronAnalysisConfig.py.


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