Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions | List of all members
python.ElectronAnalysisConfig.ElectronWorkingPointConfig Class Reference
Inheritance diagram for python.ElectronAnalysisConfig.ElectronWorkingPointConfig:
Collaboration diagram for python.ElectronAnalysisConfig.ElectronWorkingPointConfig:

Public Member Functions

def __init__ (self, containerName='', selectionName='')
 
def makeAlgs (self, config)
 

Detailed Description

the ConfigBlock for the electron working point

This may at some point be split into multiple blocks (29 Aug 22).

Definition at line 261 of file ElectronAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

def python.ElectronAnalysisConfig.ElectronWorkingPointConfig.__init__ (   self,
  containerName = '',
  selectionName = '' 
)

Definition at line 266 of file ElectronAnalysisConfig.py.

266  def __init__ (self, containerName='', selectionName='') :
267  super (ElectronWorkingPointConfig, self).__init__ ()
268  self.addOption ('containerName', containerName, type=str,
269  noneAction='error',
270  info="the name of the input container.")
271  self.addOption ('selectionName', selectionName, type=str,
272  noneAction='error',
273  info="the name of the electron selection to define (e.g. tight or "
274  "loose).")
275  self.addOption ('postfix', None, type=str,
276  info="a postfix to apply to decorations and algorithm names. "
277  "Typically not needed here as selectionName is used internally.")
278  self.addOption ('trackSelection', True, type=bool,
279  info="whether or not to set up an instance of "
280  "CP::AsgLeptonTrackSelectionAlg, with the recommended d_0 and "
281  "z_0 sin(theta) cuts. The default is True.")
282  self.addOption ('maxD0Significance', 5, type=float,
283  info="maximum d0 significance used for the trackSelection"
284  "The default is 5")
285  self.addOption ('maxDeltaZ0SinTheta', 0.5, type=float,
286  info="maximum z0sinTheta in mm used for the trackSelection"
287  "The default is 0.5 mm")
288  self.addOption ('identificationWP', None, type=str,
289  info="the ID WP (string) to use. Supported ID WPs: TightLH, "
290  "MediumLH, LooseBLayerLH, TightDNN, MediumDNN, LooseDNN, "
291  "TightNoCFDNN, MediumNoCFDNN, VeryLooseNoCF97DNN.")
292  self.addOption ('isolationWP', None, type=str,
293  info="the isolation WP (string) to use. Supported isolation WPs: "
294  "HighPtCaloOnly, Loose_VarRad, Tight_VarRad, TightTrackOnly_"
295  "VarRad, TightTrackOnly_FixedRad, NonIso.")
296  self.addOption ('addSelectionToPreselection', True, type=bool,
297  info="whether to retain only electrons satisfying the working point "
298  "requirements. The default is True.")
299  self.addOption ('closeByCorrection', False, type=bool,
300  info="whether to use close-by-corrected isolation working points")
301  self.addOption ('recomputeID', False, type=bool,
302  info="whether to rerun the ID LH/DNN. The default is False, i.e. to use "
303  "derivation flags.")
304  self.addOption ('chargeIDSelectionRun2', False, type=bool,
305  info="whether to run the ECIDS tool. Only available for run 2. "
306  "The default is False.")
307  self.addOption ('recomputeChargeID', False, type=bool,
308  info="whether to rerun the ECIDS. The default is False, i.e. to use "
309  "derivation flags.")
310  self.addOption ('doFSRSelection', False, type=bool,
311  info="whether to accept additional electrons close to muons for "
312  "the purpose of FSR corrections to these muons. Expert feature "
313  "requested by the H4l analysis running on PHYSLITE. "
314  "The default is False.")
315  self.addOption ('noEffSF', False, type=bool,
316  info="disables the calculation of efficiencies and scale factors. "
317  "Experimental! only useful to test a new WP for which scale "
318  "factors are not available. The default is False.")
319  self.addOption ('saveDetailedSF', True, type=bool,
320  info="save all the independent detailed object scale factors. "
321  "The default is True.")
322  self.addOption ('saveCombinedSF', False, type=bool,
323  info="save the combined object scale factor. "
324  "The default is False.")
325  self.addOption ('forceFullSimConfig', False, type=bool,
326  info="whether to force the tool to use the configuration meant for "
327  "full simulation samples. Only for testing purposes. "
328  "The default is False.")
329  self.addOption ('correlationModelId', 'SIMPLIFIED', type=str,
330  info="the correlation model (string) to use for ID scale factors "
331  "Supported models: SIMPLIFIED (default), FULL, TOTAL, TOYS")
332  self.addOption ('correlationModelIso', 'SIMPLIFIED', type=str,
333  info="the correlation model (string) to use for isolation scale factors "
334  "Supported models: SIMPLIFIED (default), FULL, TOTAL, TOYS")
335  self.addOption ('correlationModelReco', 'SIMPLIFIED', type=str,
336  info="the correlation model (string) to use for reconstruction scale factors "
337  "Supported models: SIMPLIFIED (default), FULL, TOTAL, TOYS")
338 
339 

Member Function Documentation

◆ makeAlgs()

def python.ElectronAnalysisConfig.ElectronWorkingPointConfig.makeAlgs (   self,
  config 
)

Definition at line 340 of file ElectronAnalysisConfig.py.

340  def makeAlgs (self, config) :
341 
342  log = logging.getLogger('ElectronWorkingPointConfig')
343 
344  if self.forceFullSimConfig:
345  log.warning("You are running ElectronWorkingPointConfig forcing full sim config")
346  log.warning("This is only intended to be used for testing purposes")
347 
348  selectionPostfix = self.selectionName
349  if selectionPostfix != '' and selectionPostfix[0] != '_' :
350  selectionPostfix = '_' + selectionPostfix
351 
352  # The setup below is inappropriate for Run 1
353  if config.geometry() is LHCPeriod.Run1:
354  raise ValueError ("Can't set up the ElectronWorkingPointConfig with %s, there must be something wrong!" % config.geometry().value)
355 
356  postfix = self.postfix
357  if postfix is None :
358  postfix = self.selectionName
359  if postfix != '' and postfix[0] != '_' :
360  postfix = '_' + postfix
361 
362  # Set up the track selection algorithm:
363  if self.trackSelection :
364  alg = config.createAlgorithm( 'CP::AsgLeptonTrackSelectionAlg',
365  'ElectronTrackSelectionAlg' + postfix,
366  reentrant=True )
367  alg.selectionDecoration = 'trackSelection' + postfix + ',as_bits'
368  alg.maxD0Significance = self.maxD0Significance
369  alg.maxDeltaZ0SinTheta = self.maxDeltaZ0SinTheta
370  alg.particles = config.readName (self.containerName)
371  alg.preselection = config.getPreselection (self.containerName, '')
372  if self.trackSelection :
373  config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
374  preselection=self.addSelectionToPreselection)
375 
376  if 'LH' in self.identificationWP:
377  # Set up the likelihood ID selection algorithm
378  # It is safe to do this before calibration, as the cluster E is used
379  alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' + postfix )
380  alg.selectionDecoration = 'selectLikelihood' + selectionPostfix + ',as_char'
381  if self.recomputeID:
382  # Rerun the likelihood ID
383  config.addPrivateTool( 'selectionTool', 'AsgElectronLikelihoodTool' )
384  alg.selectionTool.primaryVertexContainer = 'PrimaryVertices'
385  # Here we have to match the naming convention of EGSelectorConfigurationMapping.h
386  # which differ from the one used for scale factors
387  if config.geometry() >= LHCPeriod.Run3:
388  alg.selectionTool.WorkingPoint = self.identificationWP.replace("BLayer","BL") + 'Electron'
389  elif config.geometry() is LHCPeriod.Run2:
390  alg.selectionTool.WorkingPoint = self.identificationWP.replace("BLayer","BL") + 'Electron_Run2'
391  else:
392  # Select from Derivation Framework flags
393  config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
394  dfFlag = "DFCommonElectronsLH" + self.identificationWP.split('LH')[0]
395  dfFlag = dfFlag.replace("BLayer","BL")
396  alg.selectionTool.selectionFlags = [dfFlag]
397  elif 'SiHit' in self.identificationWP:
398  # Only want SiHit electrons, so veto loose LH electrons
399  algVeto = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlgVeto' + postfix + 'Veto')
400  algVeto.selectionDecoration = 'selectLikelihoodVeto' + postfix + ',as_char'
401  config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
402  algVeto.selectionTool.selectionFlags = ["DFCommonElectronsLHLoose"]
403  algVeto.selectionTool.invertFlags = [True]
404  algVeto.particles = config.readName (self.containerName)
405  algVeto.preselection = config.getPreselection (self.containerName, self.selectionName)
406  # add the veto as a selection
407  config.addSelection (self.containerName, self.selectionName, algVeto.selectionDecoration,
408  preselection=self.addSelectionToPreselection)
409 
410  # Select SiHit electrons using IsEM bits
411  alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronLikelihoodAlg' + postfix )
412  alg.selectionDecoration = 'selectSiHit' + selectionPostfix + ',as_char'
413  # Select from Derivation Framework IsEM bits
414  config.addPrivateTool( 'selectionTool', 'CP::AsgMaskSelectionTool' )
415  dfVar = "DFCommonElectronsLHLooseBLIsEMValue"
416  alg.selectionTool.selectionVars = [dfVar]
417  mask = int( 0 | 0x1 << 1 | 0x1 << 2)
418  alg.selectionTool.selectionMasks = [mask]
419  elif 'DNN' in self.identificationWP:
420  if self.chargeIDSelectionRun2:
421  raise ValueError('DNN is not intended to be used with '
422  '`chargeIDSelectionRun2` option as there are '
423  'DNN WPs containing charge flip rejection.')
424  # Set up the DNN ID selection algorithm
425  alg = config.createAlgorithm( 'CP::AsgSelectionAlg', 'ElectronDNNAlg' + postfix )
426  alg.selectionDecoration = 'selectDNN' + selectionPostfix + ',as_char'
427  if self.recomputeID:
428  # Rerun the DNN ID
429  config.addPrivateTool( 'selectionTool', 'AsgElectronSelectorTool' )
430  # Here we have to match the naming convention of EGSelectorConfigurationMapping.h
431  if config.geometry() is LHCPeriod.Run3:
432  raise ValueError ( "DNN working points are not available for Run 3 yet.")
433  else:
434  alg.selectionTool.WorkingPoint = self.identificationWP + 'Electron'
435  else:
436  # Select from Derivation Framework flags
437  config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
438  dfFlag = "DFCommonElectronsDNN" + self.identificationWP.split('DNN')[0]
439  alg.selectionTool.selectionFlags = [dfFlag]
440 
441  alg.particles = config.readName (self.containerName)
442  alg.preselection = config.getPreselection (self.containerName, self.selectionName)
443  config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
444  preselection=self.addSelectionToPreselection)
445 
446  # maintain order of selections
447  if 'SiHit' in self.identificationWP:
448  # Set up the ElectronSiHitDecAlg algorithm to decorate SiHit electrons with a minimal amount of information:
449  algDec = config.createAlgorithm( 'CP::ElectronSiHitDecAlg', 'ElectronSiHitDecAlg' + postfix )
450  selDec = 'siHitEvtHasLeptonPair' + selectionPostfix + ',as_char'
451  algDec.selectionName = selDec.split(",")[0]
452  algDec.ElectronContainer = config.readName (self.containerName)
453  # Set flag to only collect SiHit electrons for events with an electron or muon pair to minimize size increase from SiHit electrons
454  algDec.RequireTwoLeptons = True
455  config.addSelection (self.containerName, self.selectionName, selDec,
456  preselection=self.addSelectionToPreselection)
457 
458  # Set up the FSR selection
459  if self.doFSRSelection :
460  # save the flag set for the WP
461  wpFlag = alg.selectionDecoration.split(",")[0]
462  alg = config.createAlgorithm( 'CP::EgammaFSRForMuonsCollectorAlg', 'EgammaFSRForMuonsCollectorAlg' + postfix )
463  alg.selectionDecoration = wpFlag
464  alg.ElectronOrPhotonContKey = config.readName (self.containerName)
465  # For SiHit electrons, set flag to remove FSR electrons.
466  # For standard electrons, FSR electrons need to be added as they may be missed by the standard selection.
467  # For SiHit electrons FSR electrons are generally always selected, so they should be removed since they will be in the standard electron container.
468  if 'SiHit' in self.identificationWP:
469  alg.vetoFSR = True
470 
471  # Set up the isolation selection algorithm:
472  if self.isolationWP != 'NonIso' :
473  alg = config.createAlgorithm( 'CP::EgammaIsolationSelectionAlg',
474  'ElectronIsolationSelectionAlg' + postfix )
475  alg.selectionDecoration = 'isolated' + selectionPostfix + ',as_char'
476  config.addPrivateTool( 'selectionTool', 'CP::IsolationSelectionTool' )
477  alg.selectionTool.ElectronWP = self.isolationWP
478  if self.closeByCorrection:
479  alg.selectionTool.IsoDecSuffix = "CloseByCorr"
480  alg.egammas = config.readName (self.containerName)
481  alg.preselection = config.getPreselection (self.containerName, self.selectionName)
482  config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
483  preselection=self.addSelectionToPreselection)
484 
485  if self.chargeIDSelectionRun2 and config.geometry() >= LHCPeriod.Run3:
486  log.warning("ECIDS is only available for Run 2 and will not have effect in run 3.")
487 
488  # Select electrons only if they don't appear to have flipped their charge.
489  if self.chargeIDSelectionRun2 and config.geometry() < LHCPeriod.Run3:
490  alg = config.createAlgorithm( 'CP::AsgSelectionAlg',
491  'ElectronChargeIDSelectionAlg' + postfix )
492  alg.selectionDecoration = 'chargeID' + selectionPostfix + ',as_char'
493  if self.recomputeChargeID:
494  # Rerun the ECIDS BDT
495  config.addPrivateTool( 'selectionTool',
496  'AsgElectronChargeIDSelectorTool' )
497  alg.selectionTool.TrainingFile = \
498  'ElectronPhotonSelectorTools/ChargeID/ECIDS_20180731rel21Summer2018.root'
499  alg.selectionTool.WorkingPoint = 'Loose'
500  alg.selectionTool.CutOnBDT = -0.337671 # Loose 97%
501  else:
502  # Select from Derivation Framework flags
503  config.addPrivateTool( 'selectionTool', 'CP::AsgFlagSelectionTool' )
504  alg.selectionTool.selectionFlags = ["DFCommonElectronsECIDS"]
505 
506  alg.particles = config.readName (self.containerName)
507  alg.preselection = config.getPreselection (self.containerName, self.selectionName)
508  config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
509  preselection=self.addSelectionToPreselection)
510 
511  correlationModels = ["SIMPLIFIED", "FULL", "TOTAL", "TOYS"]
512 
513  sfList = []
514  # Set up the RECO electron efficiency correction algorithm:
515  if config.dataType() is not DataType.Data and not self.noEffSF:
516 
517  if config.geometry() is LHCPeriod.Run2:
518  raise ValueError('Run 2 does not yet have efficiency correction, '
519  'please disable it by setting `noEffSF` to True.')
520  if 'DNN' in self.identificationWP:
521  raise ValueError('DNN does not yet have efficiency correction, '
522  'please disable it by setting `noEffSF` to True.')
523 
524  alg = config.createAlgorithm( 'CP::ElectronEfficiencyCorrectionAlg',
525  'ElectronEfficiencyCorrectionAlgReco' + postfix )
526  config.addPrivateTool( 'efficiencyCorrectionTool',
527  'AsgElectronEfficiencyCorrectionTool' )
528  alg.scaleFactorDecoration = 'el_reco_effSF' + selectionPostfix + '_%SYS%'
529  alg.efficiencyCorrectionTool.RecoKey = "Reconstruction"
530  if self.correlationModelReco not in correlationModels:
531  raise ValueError('Invalid correlation model for reconstruction efficiency, '
532  f'has to be one of: {", ".join(correlationModels)}')
533  if config.geometry() >= LHCPeriod.Run3 and self.correlationModelReco != "TOTAL":
534  log.warning("Only TOTAL correlation model is currently supported "
535  "for reconstruction efficiency correction in Run 3.")
536  alg.efficiencyCorrectionTool.CorrelationModel = "TOTAL"
537  else:
538  alg.efficiencyCorrectionTool.CorrelationModel = self.correlationModelReco
539  if config.dataType() is DataType.FastSim:
540  alg.efficiencyCorrectionTool.ForceDataType = (
541  PATCore.ParticleDataType.Full if self.forceFullSimConfig
542  else PATCore.ParticleDataType.Fast)
543  elif config.dataType() is DataType.FullSim:
544  alg.efficiencyCorrectionTool.ForceDataType = \
545  PATCore.ParticleDataType.Full
546  alg.outOfValidity = 2 #silent
547  alg.outOfValidityDeco = 'el_reco_bad_eff' + selectionPostfix
548  alg.electrons = config.readName (self.containerName)
549  alg.preselection = config.getPreselection (self.containerName, self.selectionName)
550  if self.saveDetailedSF:
551  config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
552  'reco_effSF' + postfix)
553  sfList += [alg.scaleFactorDecoration]
554 
555  # Set up the ID electron efficiency correction algorithm:
556  if config.dataType() is not DataType.Data and not self.noEffSF:
557  alg = config.createAlgorithm( 'CP::ElectronEfficiencyCorrectionAlg',
558  'ElectronEfficiencyCorrectionAlgID' + postfix )
559  config.addPrivateTool( 'efficiencyCorrectionTool',
560  'AsgElectronEfficiencyCorrectionTool' )
561  alg.scaleFactorDecoration = 'el_id_effSF' + selectionPostfix + '_%SYS%'
562  alg.efficiencyCorrectionTool.IdKey = self.identificationWP.replace("LH","")
563  if self.correlationModelId not in correlationModels:
564  raise ValueError('Invalid correlation model for identification efficiency, '
565  f'has to be one of: {", ".join(correlationModels)}')
566  alg.efficiencyCorrectionTool.CorrelationModel = self.correlationModelId
567  if config.dataType() is DataType.FastSim:
568  alg.efficiencyCorrectionTool.ForceDataType = (
569  PATCore.ParticleDataType.Full if self.forceFullSimConfig
570  else PATCore.ParticleDataType.Fast)
571  elif config.dataType() is DataType.FullSim:
572  alg.efficiencyCorrectionTool.ForceDataType = \
573  PATCore.ParticleDataType.Full
574  alg.outOfValidity = 2 #silent
575  alg.outOfValidityDeco = 'el_id_bad_eff' + selectionPostfix
576  alg.electrons = config.readName (self.containerName)
577  alg.preselection = config.getPreselection (self.containerName, self.selectionName)
578  if self.saveDetailedSF:
579  config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
580  'id_effSF' + postfix)
581  sfList += [alg.scaleFactorDecoration]
582 
583  # Set up the ISO electron efficiency correction algorithm:
584  if config.dataType() is not DataType.Data and self.isolationWP != 'NonIso' and not self.noEffSF:
585  alg = config.createAlgorithm( 'CP::ElectronEfficiencyCorrectionAlg',
586  'ElectronEfficiencyCorrectionAlgIsol' + postfix )
587  config.addPrivateTool( 'efficiencyCorrectionTool',
588  'AsgElectronEfficiencyCorrectionTool' )
589  alg.scaleFactorDecoration = 'el_isol_effSF' + selectionPostfix + '_%SYS%'
590  alg.efficiencyCorrectionTool.IdKey = self.identificationWP.replace("LH","")
591  alg.efficiencyCorrectionTool.IsoKey = self.isolationWP
592  if self.correlationModelIso not in correlationModels:
593  raise ValueError('Invalid correlation model for isolation efficiency, '
594  f'has to be one of: {", ".join(correlationModels)}')
595  if config.geometry() >= LHCPeriod.Run3:
596  log.warning("Only TOTAL correlation model is currently supported "
597  "for isolation efficiency correction in Run 3.")
598  alg.efficiencyCorrectionTool.CorrelationModel = "TOTAL"
599  else:
600  alg.efficiencyCorrectionTool.CorrelationModel = self.correlationModelIso
601  if config.dataType() is DataType.FastSim:
602  alg.efficiencyCorrectionTool.ForceDataType = (
603  PATCore.ParticleDataType.Full if self.forceFullSimConfig
604  else PATCore.ParticleDataType.Fast)
605  elif config.dataType() is DataType.FullSim:
606  alg.efficiencyCorrectionTool.ForceDataType = \
607  PATCore.ParticleDataType.Full
608  alg.outOfValidity = 2 #silent
609  alg.outOfValidityDeco = 'el_isol_bad_eff' + selectionPostfix
610  alg.electrons = config.readName (self.containerName)
611  alg.preselection = config.getPreselection (self.containerName, self.selectionName)
612  if self.saveDetailedSF:
613  config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
614  'isol_effSF' + postfix)
615  sfList += [alg.scaleFactorDecoration]
616 
617  # TO-DO: add trigger SFs, for which we need ID key + ISO key + Trigger key !
618 
619  if self.chargeIDSelectionRun2:
620  # ECIDS is currently not supported in R22.
621  # SFs might become available or it will be part of the DNN ID.
622  pass
623 
624  if config.dataType() is not DataType.Data and not self.noEffSF and self.saveCombinedSF:
625  alg = config.createAlgorithm( 'CP::AsgObjectScaleFactorAlg',
626  'ElectronCombinedEfficiencyScaleFactorAlg' + postfix )
627  alg.particles = config.readName (self.containerName)
628  alg.inScaleFactors = sfList
629  alg.outScaleFactor = 'effSF' + postfix + '_%SYS%'
630  config.addOutputVar (self.containerName, alg.outScaleFactor, 'effSF' + postfix)
631 
632 

The documentation for this class was generated from the following file:
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
Trk::split
@ split
Definition: LayerMaterialProperties.h:38