ATLAS Offline Software
Loading...
Searching...
No Matches
LeptonSFCalculatorConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3from AnalysisAlgorithmsConfig.ConfigBlock import ConfigBlock
4from AnalysisAlgorithmsConfig.ConfigAccumulator import DataType
5
6
7class LeptonSFCalculatorBlock(ConfigBlock):
8 """ConfigBlock for the common electron-muon-photon-tau 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.addDependency("ElectronWorkingPointEfficiency", required=False)
14 self.addDependency("PhotonWorkingPointEfficiency", required=False)
15 self.addDependency("MuonWorkingPointEfficiency", required=False)
16 self.addDependency("TauWorkingPointEfficiency", required=False)
17 self.addOption('electrons', None, type=str,
18 info='the input electron container, with a possible selection, in the format `container` or `container.selection`.')
19 self.addOption('electronSFs', None, type=list,
20 info='list of decorated electron SFs to use in the computation. If not set, will use reconstruction x ID x isolation, also ECIDS (charge ID) if available.')
21 self.addOption('muons', None, type=str,
22 info='the input muon container, with a possible selection, in the format `container` or `container.selection`.')
23 self.addOption('muonSFs', None, type=list,
24 info='list of decorated muon SFs to use in the computation. If not set, will use reconstruction x isolation x TTVA.')
25 self.addOption('photons', None, type=str,
26 info='the input photon container, with a possible selection, in the format `container` or `container.selection`.')
27 self.addOption('photonSFs', None, type=list,
28 info='list of decorated photon SFs to use in the computation. If not set, will use ID x isolation.')
29 self.addOption('taus', None, type=str,
30 info='the input tau-jet container, with a possible selection, in the format `container` or `container.selection`.')
31 self.addOption('tauSFs', None, type=list,
32 info='list of decorated tau-jet SFs to use in the computation. If not set, will use reconstruction x ID x eVeto.')
33 self.addOption('lepton_postfix', None, type=str,
34 info='the name of the common lepton SF, e.g. `tight`.')
35 self.addOption('includeElectronChargeMisID', False, type=str,
36 info='whether to include the electron charge mis-ID SFs in the computation. The user is responsible for determining whether these are available.')
37 self.addOption('includeMuonBadVeto', False, type=str,
38 info='whether to include the muon bad veto SFs in the computation. The user is responsible for determining whether these are available.')
39
40 def instanceName (self) :
41 """Return the instance name for this block"""
42 return self.lepton_postfix
43
44 def makeAlgs(self, config):
45 if config.dataType() is DataType.Data: return
46
47 alg = config.createAlgorithm('CP::LeptonSFCalculatorAlg',
48 'leptonSFCalculator')
49
50 if self.electrons:
51 electrons, electronSelection = config.readNameAndSelection(self.electrons)
52 alg.electrons = electrons
53 alg.electronSelection = electronSelection
54 if self.electronSFs:
55 alg.electronSFs = self.electronSFs
56 else:
57 alg.electronSFs = [ f'el_reco_effSF_{self.electrons.split(".")[1]}_%SYS%',
58 f'el_id_effSF_{self.electrons.split(".")[1]}_%SYS%' ]
59 if 'isolated' in alg.electronSelection:
60 alg.electronSFs += [ f'el_isol_effSF_{self.electrons.split(".")[1]}_%SYS%' ]
61 if 'chargeID' in alg.electronSelection:
62 alg.electronSFs += [ f'el_ecids_effSF_{self.electrons.split(".")[1]}_%SYS%' ]
63 if self.includeElectronChargeMisID:
64 alg.electronSFs += [ f'el_charge_misid_effSF_{self.electrons.split(".")[1]}_%SYS%' ]
65
66 if self.muons:
67 muons, muonSelection = config.readNameAndSelection(self.muons)
68 alg.muons = muons
69 alg.muonSelection = muonSelection
70 if self.muonSFs:
71 alg.muonSFs = self.muonSFs
72 else:
73 alg.muonSFs = [ f'muon_reco_effSF_{self.muons.split(".")[1]}_%SYS%']
74 if 'trackSelection' in alg.muonSelection:
75 alg.muonSFs += [ f'muon_TTVA_effSF_{self.muons.split(".")[1]}_%SYS%' ]
76 if 'isolated' in alg.muonSelection:
77 alg.muonSFs += [ f'muon_isol_effSF_{self.muons.split(".")[1]}_%SYS%' ]
78 if self.includeMuonBadVeto:
79 alg.muonSFs += [ f'muon_BadMuonVeto_effSF_{self.muons.split(".")[1]}_%SYS%' ]
80
81 if self.photons:
82 photons, photonSelection = config.readNameAndSelection(self.photons)
83 alg.photons = photons
84 alg.photonSelection = photonSelection
85 if self.photonSFs:
86 alg.photonSFs = self.photonSFs
87 else:
88 alg.photonSFs = [ f'ph_id_effSF_{self.photons.split(".")[1]}_%SYS%' ]
89 if 'isolated' in alg.photonSelection:
90 alg.photonSFs += [ f'ph_isol_effSF_{self.photons.split(".")[1]}_%SYS%' ]
91
92 if self.taus:
93 taus, tauSelection = config.readNameAndSelection(self.taus)
94 alg.taus = taus
95 alg.tauSelection = tauSelection
96 if self.tauSFs:
97 alg.tauSFs = self.tauSFs
98 else:
99 alg.tauSFs = [ f'tau_Reco_effSF_{self.taus.split(".")[1]}_%SYS%',
100 f'tau_ID_effSF_{self.taus.split(".")[1]}_%SYS%']
101 if 'eVeto' in alg.tauSelection:
102 alg.tauSFs += [ f'tau_EvetoFakeTau_effSF_{self.taus.split(".")[1]}_%SYS%',
103 f'tau_EvetoTrueTau_effSF_{self.taus.split(".")[1]}_%SYS%']
104
105 alg.event_leptonSF = f'leptonSF_{self.lepton_postfix}_%SYS%'
106
107 config.addOutputVar('EventInfo', alg.event_leptonSF, f'weight_leptonSF_{self.lepton_postfix}')