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

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.__init__ ( self)

Definition at line 328 of file ElectronAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 387 of file ElectronAnalysisConfig.py.

387 def instanceName (self) :
388 """Return the instance name for this block"""
389 if self.postfix is not None :
390 return self.containerName + '_' + self.selectionName + self.postfix
391 return self.containerName + '_' + self.selectionName
392

◆ makeAlgs()

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

Definition at line 393 of file ElectronAnalysisConfig.py.

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

Member Data Documentation

◆ chargeIDSelectionRun2

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.chargeIDSelectionRun2

Definition at line 470 of file ElectronAnalysisConfig.py.

◆ closeByCorrection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.closeByCorrection

Definition at line 595 of file ElectronAnalysisConfig.py.

◆ containerName

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.containerName

Definition at line 420 of file ElectronAnalysisConfig.py.

◆ convSelection

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

Definition at line 548 of file ElectronAnalysisConfig.py.

◆ doFSRSelection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.doFSRSelection

Definition at line 499 of file ElectronAnalysisConfig.py.

◆ identificationWP

str python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.identificationWP

Definition at line 423 of file ElectronAnalysisConfig.py.

◆ recomputeChargeID

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.recomputeChargeID

Definition at line 613 of file ElectronAnalysisConfig.py.

◆ recomputeID

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.recomputeID

Definition at line 428 of file ElectronAnalysisConfig.py.

◆ selectionName

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.selectionName

Definition at line 420 of file ElectronAnalysisConfig.py.

◆ trackSelection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.trackSelection

Definition at line 410 of file ElectronAnalysisConfig.py.


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