ATLAS Offline Software
LeptonSFCalculatorConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from AnalysisAlgorithmsConfig.ConfigBlock import ConfigBlock
4 from AnalysisAlgorithmsConfig.ConfigAccumulator import DataType
5 
6 
7 class LeptonSFCalculatorBlock(ConfigBlock):
8  """ConfigBlock for the common electron-muon-photon SF calculator"""
9  """--> combine all the per-object SFs into a single per-event SF"""
10 
11  def __init__(self):
12  super(LeptonSFCalculatorBlock, self).__init__()
13  self.addOption('electrons', None, type=str,
14  info='the input electron container, with a possible selection, in the format `container` or `container.selection`.')
15  self.addOption('electronSFs', None, type=list,
16  info='list of decorated electron SFs to use in the computation. If not set, will use reconstruction x ID x isolation.')
17  self.addOption('muons', None, type=str,
18  info='the input muon container, with a possible selection, in the format `container` or `container.selection`.')
19  self.addOption('muonSFs', None, type=list,
20  info='list of decorated muon SFs to use in the computation. If not set, will use reconstruction x isolation x TTVA.')
21  self.addOption('photons', None, type=str,
22  info='the input photon container, with a possible selection, in the format `container` or `container.selection`.')
23  self.addOption('photonSFs', None, type=list,
24  info='list of decorated photon SFs to use in the computation. If not set, will use ID x isolation.')
25  self.addOption('lepton_postfix', None, type=str,
26  info='the name of the common lepton SF, e.g. `tight`.')
27 
28  def makeAlgs(self, config):
29  if config.dataType() is DataType.Data: return
30 
31  alg = config.createAlgorithm('CP::LeptonSFCalculatorAlg',
32  f'leptonSFCalculator_{self.lepton_postfix}')
33 
34  if self.electrons:
35  electrons, electronSelection = config.readNameAndSelection(self.electrons)
36  alg.electrons = electrons
37  alg.electronSelection = electronSelection
38  if self.electronSFs:
39  alg.electronSFs = self.electronSFs
40  else:
41  alg.electronSFs = [ f'el_reco_effSF_{self.electrons.split(".")[1]}_%SYS%',
42  f'el_id_effSF_{self.electrons.split(".")[1]}_%SYS%' ]
43  if 'isolated' in alg.electronSelection:
44  alg.electronSFs += [ f'el_isol_effSF_{self.electrons.split(".")[1]}_%SYS%' ]
45 
46  if self.muons:
47  muons, muonSelection = config.readNameAndSelection(self.muons)
48  alg.muons = muons
49  alg.muonSelection = muonSelection
50  if self.muonSFs:
51  alg.muonSFs = self.muonSFs
52  else:
53  alg.muonSFs = [ f'muon_reco_effSF_{self.muons.split(".")[1]}_%SYS%',
54  f'muon_TTVA_effSF_{self.muons.split(".")[1]}_%SYS%' ]
55  if 'isolated' in alg.muonSelection:
56  alg.muonSFs += [ f'muon_isol_effSF_{self.muons.split(".")[1]}_%SYS%' ]
57 
58  if self.photons:
59  photons, photonSelection = config.readNameAndSelection(self.photons)
60  alg.photons = photons
61  alg.photonSelection = photonSelection
62  if self.photonSFs:
63  alg.photonSFs = self.photonSFs
64  else:
65  alg.photonSFs = [ f'ph_id_effSF_{self.photons.split(".")[1]}_%SYS%' ]
66  if 'isolated' in alg.photonSelection:
67  alg.photonSFs += [ f'ph_isol_effSF_{self.photons.split(".")[1]}_%SYS%' ]
68 
69  alg.event_leptonSF = f'leptonSF_{self.lepton_postfix}_%SYS%'
70 
71  config.addOutputVar('EventInfo', alg.event_leptonSF, f'weight_leptonSF_{self.lepton_postfix}')
python.LeptonSFCalculatorConfig.LeptonSFCalculatorBlock
Definition: LeptonSFCalculatorConfig.py:7
python.LeptonSFCalculatorConfig.LeptonSFCalculatorBlock.makeAlgs
def makeAlgs(self, config)
Definition: LeptonSFCalculatorConfig.py:28
python.LeptonSFCalculatorConfig.LeptonSFCalculatorBlock.__init__
def __init__(self)
Definition: LeptonSFCalculatorConfig.py:11