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 329 of file ElectronAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.__init__ ( self)

Definition at line 332 of file ElectronAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 391 of file ElectronAnalysisConfig.py.

391 def instanceName (self) :
392 """Return the instance name for this block"""
393 if self.postfix is not None :
394 return self.containerName + '_' + self.selectionName + self.postfix
395 return self.containerName + '_' + self.selectionName
396

◆ makeAlgs()

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

Definition at line 397 of file ElectronAnalysisConfig.py.

397 def makeAlgs (self, config) :
398
399 selectionPostfix = self.selectionName
400 if selectionPostfix != '' and selectionPostfix[0] != '_' :
401 selectionPostfix = '_' + selectionPostfix
402
403 # The setup below is inappropriate for Run 1
404 if config.geometry() is LHCPeriod.Run1:
405 raise ValueError ("Can't set up the ElectronWorkingPointSelectionConfig with %s, there must be something wrong!" % config.geometry().value)
406
407 postfix = self.postfix
408 if postfix is None :
409 postfix = self.selectionName
410 if postfix != '' and postfix[0] != '_' :
411 postfix = '_' + postfix
412
413 # Set up the track selection algorithm:
414 if self.trackSelection :
415 alg = config.createAlgorithm( 'CP::AsgLeptonTrackSelectionAlg',
416 'ElectronTrackSelectionAlg',
417 reentrant=True )
418 alg.selectionDecoration = 'trackSelection' + postfix + ',as_bits'
419 alg.maxD0Significance = self.maxD0Significance
420 alg.maxDeltaZ0SinTheta = self.maxDeltaZ0SinTheta
421 alg.particles = config.readName (self.containerName)
422 alg.preselection = config.getPreselection (self.containerName, '')
423 if self.trackSelection :
424 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
425 preselection=self.addSelectionToPreselection)
426
427 if 'LH' in self.identificationWP:
428 # Set up the likelihood ID selection algorithm
429 # It is safe to do this before calibration, as the cluster E is used
430 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' )
431 alg.selectionDecoration = 'selectLikelihood' + selectionPostfix + ',as_char'
432 if self.recomputeID:
433 # Rerun the likelihood ID
434 config.addPrivateTool( 'selectionTool', 'AsgElectronLikelihoodTool' )
435 alg.selectionTool.primaryVertexContainer = 'PrimaryVertices'
436 # Here we have to match the naming convention of EGSelectorConfigurationMapping.h
437 # which differ from the one used for scale factors
438 if config.geometry() >= LHCPeriod.Run3:
439 if 'HI' not in self.identificationWP:
440 alg.selectionTool.WorkingPoint = self.identificationWP.replace("BLayer","BL") + 'Electron'
441 else:
442 alg.selectionTool.WorkingPoint = self.identificationWP.replace('_HI', 'Electron_HI')
443 elif config.geometry() is LHCPeriod.Run2:
444 alg.selectionTool.WorkingPoint = self.identificationWP.replace("BLayer","BL") + 'Electron_Run2'
445 else:
446 # Select from Derivation Framework flags
447 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
448 dfFlag = "DFCommonElectronsLH" + self.identificationWP.split('LH')[0]
449 dfFlag = dfFlag.replace("BLayer","BL")
450 alg.selectionTool.selectionFlags = [dfFlag]
451 elif 'SiHit' in self.identificationWP:
452 # Only want SiHit electrons, so veto loose LH electrons
453 algVeto = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlgVeto')
454 algVeto.selectionDecoration = 'selectLikelihoodVeto' + postfix + ',as_char'
455 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
456 algVeto.selectionTool.selectionFlags = ["DFCommonElectronsLHLoose"]
457 algVeto.selectionTool.invertFlags = [True]
458 algVeto.particles = config.readName (self.containerName)
459 algVeto.preselection = config.getPreselection (self.containerName, self.selectionName)
460 # add the veto as a selection
461 config.addSelection (self.containerName, self.selectionName, algVeto.selectionDecoration,
462 preselection=self.addSelectionToPreselection)
463
464 # Select SiHit electrons using IsEM bits
465 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' )
466 alg.selectionDecoration = 'selectSiHit' + selectionPostfix + ',as_char'
467 # Select from Derivation Framework IsEM bits
468 config.addPrivateTool( 'selectionTool', 'CP::AsgMaskSelectionTool' )
469 dfVar = "DFCommonElectronsLHLooseBLIsEMValue"
470 alg.selectionTool.selectionVars = [dfVar]
471 mask = int( 0 | 0x1 << 1 | 0x1 << 2)
472 alg.selectionTool.selectionMasks = [mask]
473 elif 'DNN' in self.identificationWP:
474 if self.chargeIDSelectionRun2:
475 raise ValueError('DNN is not intended to be used with '
476 '`chargeIDSelectionRun2` option as there are '
477 'DNN WPs containing charge flip rejection.')
478 # Set up the DNN ID selection algorithm
479 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronDNNAlg' )
480 alg.selectionDecoration = 'selectDNN' + selectionPostfix + ',as_char'
481 if self.recomputeID:
482 # Rerun the DNN ID
483 config.addPrivateTool( 'selectionTool', 'AsgElectronSelectorTool' )
484 # Here we have to match the naming convention of EGSelectorConfigurationMapping.h
485 if config.geometry() is LHCPeriod.Run3:
486 raise ValueError ( "DNN working points are not available for Run 3 yet.")
487 else:
488 alg.selectionTool.WorkingPoint = self.identificationWP + 'Electron'
489 else:
490 # Select from Derivation Framework flags
491 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
492 dfFlag = "DFCommonElectronsDNN" + self.identificationWP.split('DNN')[0]
493 alg.selectionTool.selectionFlags = [dfFlag]
494 elif self.identificationWP == 'NoID':
495 alg = None
496 else:
497 raise ValueError (f"Electron ID working point '{self.identificationWP}' is not recognised!")
498
499 if alg is not None:
500 alg.particles = config.readName (self.containerName)
501 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
502 # Don't register WP selection here if FSR enabled - FSR algorithm will create combined selection
503 if not self.doFSRSelection:
504 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
505 preselection=self.addSelectionToPreselection)
506
507 # maintain order of selections
508 if 'SiHit' in self.identificationWP:
509 # Set up the ElectronSiHitDecAlg algorithm to decorate SiHit electrons with a minimal amount of information:
510 algDec = config.createAlgorithm( 'CP::ElectronSiHitDecAlg', 'ElectronSiHitDecAlg' )
511 selDec = 'siHitEvtHasLeptonPair' + selectionPostfix + ',as_char'
512 algDec.selectionName = selDec.split(",")[0]
513 algDec.ElectronContainer = config.readName (self.containerName)
514 if self.muonsForFSRSelection is not None:
515 algDec.AnalMuonContKey = config.readName (self.muonsForFSRSelection)
516 if self.mainElectronContainer is not None:
517 algDec.AnalElectronContKey = config.readName (self.mainElectronContainer)
518 # Set flag to only collect SiHit electrons for events with an electron or muon pair to minimize size increase from SiHit electrons
519 algDec.RequireTwoLeptons = True
520 config.addSelection (self.containerName, self.selectionName, selDec,
521 preselection=self.addSelectionToPreselection)
522
523 # Additional selection for conversions and gamma*
524 if self.convSelection is not None:
525 # skip if not applied together with TightLH
526 if self.identificationWP != 'TightLH':
527 raise ValueError(f"convSelection can only be used with TightLH ID, "
528 f"whereas {self.identificationWP} has been selected. convSelection option will be ignored.")
529 # check if allowed value
530 allowedValues = ["Veto", "GammaStar", "MatConv"]
531 if self.convSelection not in allowedValues:
532 raise ValueError(f"convSelection has been set to {self.convSelection}, which is not a valid option. "
533 f"convSelection option must be one of {allowedValues}.")
534
535 # ambiguityType == 0
536 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronAmbiguityTypeAlg' )
537 alg.selectionDecoration = 'selectAmbiguityType' + selectionPostfix + ',as_char'
538 config.addPrivateTool( 'selectionTool', 'CP::AsgNumDecorationSelectionToolUInt8' )
539 alg.selectionTool.decorationName = "ambiguityType"
540 alg.selectionTool.doEqual = True
541 alg.selectionTool.equal = 0
542 alg.particles = config.readName (self.containerName)
543 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
544 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
545 preselection=self.addSelectionToPreselection)
546
547 # DFCommonAddAmbiguity selection
548 alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronDFCommonAddAmbiguityAlg' )
549 alg.selectionDecoration = 'selectDFCommonAddAmbiguity' + selectionPostfix + ',as_char'
550 config.addPrivateTool( 'selectionTool', 'CP::AsgNumDecorationSelectionToolInt' )
551 alg.selectionTool.decorationName = "DFCommonAddAmbiguity"
552 if self.convSelection == "Veto":
553 alg.selectionTool.doMax = True
554 alg.selectionTool.max = 1
555 elif self.convSelection == "GammaStar":
556 alg.selectionTool.doEqual = True
557 alg.selectionTool.equal = 1
558 elif self.convSelection == "MatConv":
559 alg.selectionTool.doEqual = True
560 alg.selectionTool.equal = 2
561 alg.particles = config.readName (self.containerName)
562 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
563 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
564 preselection=self.addSelectionToPreselection)
565
566 # Set up the FSR selection
567 if self.doFSRSelection :
568 # wpSelection needs the type suffix so SysReadSelectionHandle knows the type
569 # selectionDecoration needs name only for SysWriteDecorHandle
570 wpDecoration = alg.selectionDecoration
571 wpDecorationName = wpDecoration.split(',')[0]
572 # Insert FSR before the postfix (e.g., selectSiHit_SiHits -> selectSiHitFSR_SiHits)
573 underscorePos = wpDecorationName.index('_')
574 outputDecorationName = wpDecorationName[:underscorePos] + 'FSR' + wpDecorationName[underscorePos:]
575 alg = config.createAlgorithm( 'CP::EgammaFSRForMuonsCollectorAlg', 'EgammaFSRForMuonsCollectorAlg' )
576 alg.wpSelection = wpDecoration # Input: read the WP selection (with type suffix)
577 alg.selectionDecoration = outputDecorationName # Output: combined WP||FSR (or WP&&!FSR for vetoFSR) (name only)
578 alg.ElectronOrPhotonContKey = config.readName (self.containerName)
579 if self.muonsForFSRSelection is not None:
580 alg.MuonContKey = config.readName (self.muonsForFSRSelection)
581 # For SiHit electrons, set flag to remove FSR electrons.
582 # For standard electrons, FSR electrons need to be added as they may be missed by the standard selection.
583 # For SiHit electrons FSR electrons are generally always selected, so they should be removed since they will be in the standard electron container.
584 if 'SiHit' in self.identificationWP:
585 alg.vetoFSR = True
586
587 # Register the FSR COMBINED selection
588 config.addSelection (self.containerName, self.selectionName,
589 alg.selectionDecoration + ',as_char',
590 preselection=self.addSelectionToPreselection)
591
592 # Set up the isolation selection algorithm:
593 if self.isolationWP != 'NonIso' :
594 alg = config.createAlgorithm( 'CP::EgammaIsolationSelectionAlg',
595 'ElectronIsolationSelectionAlg' )
596 alg.selectionDecoration = 'isolated' + selectionPostfix + ',as_char'
597 config.addPrivateTool( 'selectionTool', 'CP::IsolationSelectionTool' )
598 alg.selectionTool.ElectronWP = self.isolationWP
599 if self.closeByCorrection:
600 alg.selectionTool.IsoDecSuffix = "CloseByCorr"
601 alg.egammas = config.readName (self.containerName)
602 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
603 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
604 preselection=self.addSelectionToPreselection)
605
606 if self.chargeIDSelectionRun2 and config.geometry() >= LHCPeriod.Run3:
607 warnings.warn_explicit(
608 "ECIDS is only available for Run 2 and will not have any"
609 " effect in Run 3.",
610 Run2OnlyFeatureWarning, filename='', lineno=0)
611
612 # Select electrons only if they don't appear to have flipped their charge.
613 if self.chargeIDSelectionRun2 and config.geometry() < LHCPeriod.Run3:
614 alg = config.createAlgorithm( 'CP::AsgSelectionAlg',
615 'ElectronChargeIDSelectionAlg' )
616 alg.selectionDecoration = 'chargeID' + selectionPostfix + ',as_char'
617 if self.recomputeChargeID:
618 # Rerun the ECIDS BDT
619 config.addPrivateTool( 'selectionTool',
620 'AsgElectronChargeIDSelectorTool' )
621 alg.selectionTool.TrainingFile = \
622 'ElectronPhotonSelectorTools/ChargeID/ECIDS_20180731rel21Summer2018.root'
623 alg.selectionTool.WorkingPoint = 'Loose'
624 alg.selectionTool.CutOnBDT = -0.337671 # Loose 97%
625 else:
626 # Select from Derivation Framework flags
627 config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
628 alg.selectionTool.selectionFlags = ["DFCommonElectronsECIDS"]
629
630 alg.particles = config.readName (self.containerName)
631 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
632 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
633 preselection=self.addSelectionToPreselection)
634
635
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 474 of file ElectronAnalysisConfig.py.

◆ closeByCorrection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.closeByCorrection

Definition at line 599 of file ElectronAnalysisConfig.py.

◆ containerName

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.containerName

Definition at line 424 of file ElectronAnalysisConfig.py.

◆ convSelection

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

Definition at line 552 of file ElectronAnalysisConfig.py.

◆ doFSRSelection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.doFSRSelection

Definition at line 503 of file ElectronAnalysisConfig.py.

◆ identificationWP

str python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.identificationWP

Definition at line 427 of file ElectronAnalysisConfig.py.

◆ recomputeChargeID

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.recomputeChargeID

Definition at line 617 of file ElectronAnalysisConfig.py.

◆ recomputeID

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.recomputeID

Definition at line 432 of file ElectronAnalysisConfig.py.

◆ selectionName

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.selectionName

Definition at line 424 of file ElectronAnalysisConfig.py.

◆ trackSelection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.trackSelection

Definition at line 414 of file ElectronAnalysisConfig.py.


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