ATLAS Offline Software
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 222 of file ElectronAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 227 of file ElectronAnalysisConfig.py.

227  def __init__ (self, containerName='', selectionName='') :
228  super (ElectronWorkingPointConfig, self).__init__ ()
229  self.addOption ('containerName', containerName, type=str,
230  noneAction='error',
231  info="the name of the input container.")
232  self.addOption ('selectionName', selectionName, type=str,
233  noneAction='error',
234  info="the name of the electron selection to define (e.g. tight or "
235  "loose).")
236  self.addOption ('postfix', None, type=str,
237  info="a postfix to apply to decorations and algorithm names. "
238  "Typically not needed here as selectionName is used internally.")
239  self.addOption ('trackSelection', True, type=bool,
240  info="whether or not to set up an instance of "
241  "CP::AsgLeptonTrackSelectionAlg, with the recommended d_0 and "
242  "z_0 sin(theta) cuts. The default is True.")
243  self.addOption ('maxD0Significance', 5, type=float,
244  info="maximum d0 significance used for the trackSelection"
245  "The default is 5")
246  self.addOption ('maxDeltaZ0SinTheta', 0.5, type=float,
247  info="maximum z0sinTheta in mm used for the trackSelection"
248  "The default is 0.5 mm")
249  self.addOption ('writeTrackD0Z0', False, type = bool,
250  info="save the d0 significance and z0sinTheta variables so they can be written out")
251  self.addOption ('identificationWP', None, type=str,
252  info="the ID WP (string) to use. Supported ID WPs: TightLH, "
253  "MediumLH, LooseBLayerLH, TightDNN, MediumDNN, LooseDNN, "
254  "TightDNNnoCF, MediumDNNnoCF, VeryLooseDNNnoCF97.")
255  self.addOption ('isolationWP', None, type=str,
256  info="the isolation WP (string) to use. Supported isolation WPs: "
257  "HighPtCaloOnly, Loose_VarRad, Tight_VarRad, TightTrackOnly_"
258  "VarRad, TightTrackOnly_FixedRad, NonIso.")
259  self.addOption ('closeByCorrection', False, type=bool,
260  info="whether to use close-by-corrected isolation working points")
261  self.addOption ('recomputeID', False, type=bool,
262  info="whether to rerun the ID LH/DNN. The default is False, i.e. to use "
263  "derivation flags.")
264  self.addOption ('chargeIDSelectionRun2', False, type=bool,
265  info="whether to run the ECIDS tool. Only available for run 2. "
266  "The default is False.")
267  self.addOption ('recomputeChargeID', False, type=bool,
268  info="whether to rerun the ECIDS. The default is False, i.e. to use "
269  "derivation flags.")
270  self.addOption ('doFSRSelection', False, type=bool,
271  info="whether to accept additional electrons close to muons for "
272  "the purpose of FSR corrections to these muons. Expert feature "
273  "requested by the H4l analysis running on PHYSLITE. "
274  "The default is False.")
275  self.addOption ('noEffSF', False, type=bool,
276  info="disables the calculation of efficiencies and scale factors. "
277  "Experimental! only useful to test a new WP for which scale "
278  "factors are not available. The default is False.")
279  self.addOption ('forceFullSimConfig', False, type=bool,
280  info="whether to force the tool to use the configuration meant for "
281  "full simulation samples. Only for testing purposes. "
282  "The default is False.")
283  self.addOption ('correlationModelId', 'SIMPLIFIED', type=str,
284  info="the correlation model (string) to use for ID scale factors "
285  "Supported models: SIMPLIFIED (default), FULL, TOTAL, TOYS")
286  self.addOption ('correlationModelIso', 'SIMPLIFIED', type=str,
287  info="the correlation model (string) to use for isolation scale factors "
288  "Supported models: SIMPLIFIED (default), FULL, TOTAL, TOYS")
289  self.addOption ('correlationModelReco', 'SIMPLIFIED', type=str,
290  info="the correlation model (string) to use for reconstruction scale factors "
291  "Supported models: SIMPLIFIED (default), FULL, TOTAL, TOYS")
292 
293 

Member Function Documentation

◆ makeAlgs()

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

Definition at line 294 of file ElectronAnalysisConfig.py.

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

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
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::split
@ split
Definition: LayerMaterialProperties.h:38