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
str convSelection = "Veto":
 doFSRSelection
 closeByCorrection
 recomputeChargeID

Detailed Description

the ConfigBlock for the electron working point selection

Definition at line 283 of file ElectronAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.__init__ ( self)

Definition at line 286 of file ElectronAnalysisConfig.py.

286 def __init__ (self) :
287 super (ElectronWorkingPointSelectionConfig, self).__init__ ()
288 self.setBlockName('ElectronWorkingPointSelection')
289 self.addOption ('containerName', '', type=str,
290 noneAction='error',
291 info="the name of the input container.")
292 self.addOption ('selectionName', '', type=str,
293 noneAction='error',
294 info="the name of the electron selection to define (e.g. `tight` or "
295 "`loose`).")
296 self.addOption ('postfix', None, type=str,
297 info="a postfix to apply to decorations and algorithm names. "
298 "Typically not needed here as `selectionName` is used internally.")
299 self.addOption ('trackSelection', True, type=bool,
300 info="whether or not to set up an instance of "
301 "`CP::AsgLeptonTrackSelectionAlg`, with the recommended $d_0$ and "
302 r"$z_0\sin\theta$ cuts.")
303 self.addOption ('maxD0Significance', 5, type=float,
304 info="maximum $d_0$ significance used for the track selection.")
305 self.addOption ('maxDeltaZ0SinTheta', 0.5, type=float,
306 info=r"maximum $z_0\sin\theta$ (in mm) used for the track selection.")
307 self.addOption ('identificationWP', None, type=str,
308 info="the ID WP to use. Supported ID WPs: `TightLH`, "
309 "`MediumLH`, `LooseBLayerLH`, `TightDNN`, `MediumDNN`, `LooseDNN`, "
310 "`TightNoCFDNN`, `MediumNoCFDNN`, `VeryLooseNoCF97DNN`, `NoID`.",
311 expertMode=["NoID"])
312 self.addOption ('isolationWP', None, type=str,
313 info="the isolation WP to use. Supported isolation WPs: "
314 "`HighPtCaloOnly`, `Loose_VarRad`, `Tight_VarRad`, `TightTrackOnly_"
315 "VarRad`, `TightTrackOnly_FixedRad`, `NonIso`.")
316 self.addOption ('convSelection', None, type=str,
317 info="enter additional selection to use for conversions. To be used with "
318 "`TightLH` or will crash. Supported keywords:"
319 "`Veto`, `MatConv`, `GammaStar`.")
320 self.addOption ('addSelectionToPreselection', True, type=bool,
321 info="whether to retain only electrons satisfying the working point "
322 "requirements.")
323 self.addOption ('closeByCorrection', False, type=bool,
324 info="whether to use close-by-corrected isolation working points.")
325 self.addOption ('recomputeID', False, type=bool,
326 info="whether to rerun the ID LH/DNN, or rely on derivation flags.")
327 self.addOption ('chargeIDSelectionRun2', False, type=bool,
328 info="whether to run the ECIDS tool. Only available for Run 2.")
329 self.addOption ('recomputeChargeID', False, type=bool,
330 info="whether to rerun the ECIDS, or rely on derivation flags.")
331 self.addOption ('doFSRSelection', False, type=bool,
332 info="whether to accept additional electrons close to muons for "
333 "the purpose of FSR corrections to these muons. Expert feature "
334 "requested by the H4l analysis running on PHYSLITE.",
335 expertMode=True)
336 self.addOption ('muonsForFSRSelection', None, type=str,
337 info="the name of the muon container to use for the FSR selection. "
338 "If not specified, AnalysisMuons is used.",
339 expertMode=True)
340 self.addOption ('mainElectronContainer', None, type=str,
341 info="the name of the main electron container to use for the SiHit selection. "
342 "If not specified, this defaults to AnalysisElectrons.",
343 expertMode=True)
344

Member Function Documentation

◆ instanceName()

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

Definition at line 345 of file ElectronAnalysisConfig.py.

345 def instanceName (self) :
346 """Return the instance name for this block"""
347 if self.postfix is not None :
348 return self.containerName + '_' + self.selectionName + self.postfix
349 return self.containerName + '_' + self.selectionName
350

◆ makeAlgs()

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

Definition at line 351 of file ElectronAnalysisConfig.py.

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

◆ closeByCorrection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.closeByCorrection

Definition at line 542 of file ElectronAnalysisConfig.py.

◆ containerName

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.containerName

Definition at line 380 of file ElectronAnalysisConfig.py.

◆ convSelection

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

Definition at line 506 of file ElectronAnalysisConfig.py.

◆ doFSRSelection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.doFSRSelection

Definition at line 521 of file ElectronAnalysisConfig.py.

◆ identificationWP

str python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.identificationWP

Definition at line 383 of file ElectronAnalysisConfig.py.

◆ recomputeChargeID

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.recomputeChargeID

Definition at line 557 of file ElectronAnalysisConfig.py.

◆ recomputeID

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.recomputeID

Definition at line 388 of file ElectronAnalysisConfig.py.

◆ selectionName

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.selectionName

Definition at line 380 of file ElectronAnalysisConfig.py.

◆ trackSelection

python.ElectronAnalysisConfig.ElectronWorkingPointSelectionConfig.trackSelection

Definition at line 370 of file ElectronAnalysisConfig.py.


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