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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 216 of file ElectronAnalysisConfig.py.

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

Member Function Documentation

◆ makeAlgs()

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

Definition at line 283 of file ElectronAnalysisConfig.py.

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

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