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

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.__init__ ( self)

Definition at line 322 of file ElectronAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 381 of file ElectronAnalysisConfig.py.

381 def instanceName (self) :
382 """Return the instance name for this block"""
383 if self.postfix is not None :
384 return self.containerName + '_' + self.selectionName + self.postfix
385 return self.containerName + '_' + self.selectionName
386

◆ makeAlgs()

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

Definition at line 387 of file ElectronAnalysisConfig.py.

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

◆ closeByCorrection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.closeByCorrection

Definition at line 591 of file ElectronAnalysisConfig.py.

◆ containerName

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.containerName

Definition at line 416 of file ElectronAnalysisConfig.py.

◆ convSelection

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

Definition at line 544 of file ElectronAnalysisConfig.py.

◆ doFSRSelection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.doFSRSelection

Definition at line 495 of file ElectronAnalysisConfig.py.

◆ identificationWP

str python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.identificationWP

Definition at line 419 of file ElectronAnalysisConfig.py.

◆ recomputeChargeID

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.recomputeChargeID

Definition at line 606 of file ElectronAnalysisConfig.py.

◆ recomputeID

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.recomputeID

Definition at line 424 of file ElectronAnalysisConfig.py.

◆ selectionName

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.selectionName

Definition at line 416 of file ElectronAnalysisConfig.py.

◆ trackSelection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.trackSelection

Definition at line 406 of file ElectronAnalysisConfig.py.


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