4 from AnalysisAlgorithmsConfig.ConfigAccumulator
import DataType
5 from AnalysisAlgorithmsConfig.ConfigBlock
import ConfigBlock
6 from AthenaCommon.Logging
import logging
7 from AthenaConfiguration.Enums
import LHCPeriod
8 from Campaigns.Utils
import Campaign
12 """the ConfigBlock for the tau four-momentum correction"""
15 super (TauCalibrationConfig, self).__init__ ()
16 self.setBlockName(
'Taus')
18 self.addOption (
'inputContainer',
'', type=str,
19 info=
"select tau input container, by default set to TauJets")
20 self.addOption (
'containerName', containerName, type=str,
22 info=
"the name of the output container after calibration.")
23 self.addOption (
'postfix',
'', type=str,
24 info=
"a postfix to apply to decorations and algorithm names. "
25 "Typically not needed here since the calibration is common to "
27 self.addOption (
'rerunTruthMatching',
True, type=bool,
28 info=
"whether to rerun truth matching (sets up an instance of "
29 "CP::TauTruthMatchingAlg). The default is True.")
30 self.addOption (
'decorateTruth',
False, type=bool,
31 info=
"decorate truth particle information on the reconstructed one")
36 postfix = self.postfix
37 if postfix !=
'' and postfix[0] !=
'_' :
38 postfix =
'_' + postfix
40 inputContainer =
"AnalysisTauJets" if config.isPhyslite()
else "TauJets"
41 if self.inputContainer:
42 inputContainer = self.inputContainer
46 if self.rerunTruthMatching
and config.dataType()
is not DataType.Data:
47 alg = config.createAlgorithm(
'CP::TauTruthMatchingAlg',
48 'TauTruthMatchingAlg' + postfix )
49 config.addPrivateTool(
'matchingTool',
50 'TauAnalysisTools::TauTruthMatchingTool' )
51 alg.matchingTool.TruthJetContainerName =
'AntiKt4TruthDressedWZJets'
53 alg.preselection = config.getPreselection (self.
containerName,
'')
56 if self.decorateTruth
and config.dataType()
is not DataType.Data:
57 alg = config.createAlgorithm(
'CP::TauTruthDecorationsAlg',
58 'TauTruthDecorationsAlg' + postfix,
61 alg.doubleDecorations = [
'pt_vis',
'eta_vis',
'phi_vis',
'm_vis']
62 alg.floatDecorations = []
63 alg.intDecorations = [
'pdgId']
64 alg.unsignedIntDecorations = [
'classifierParticleOrigin',
'classifierParticleType']
65 alg.charDecorations = [
'IsHadronicTau']
69 for var
in [
'DecayMode',
'ParticleType',
'PartonTruthLabelID'] + alg.doubleDecorations[:] + alg.floatDecorations[:] + alg.intDecorations[:] + alg.unsignedIntDecorations[:] + alg.charDecorations[:]:
70 branchName = alg.prefix + var
71 if 'classifierParticle' in var:
72 branchOutput = alg.prefix + var.replace(
'classifierParticle',
'').lower()
74 branchOutput = branchName
75 config.addOutputVar (self.
containerName, branchName, branchOutput, noSys=
True)
78 alg = config.createAlgorithm(
'CP::TauExtraVariablesAlg',
84 alg = config.createAlgorithm(
'CP::TauSmearingAlg',
'TauSmearingAlg' + postfix )
85 config.addPrivateTool(
'smearingTool',
'TauAnalysisTools::TauSmearingTool' )
86 alg.smearingTool.useFastSim = config.dataType()
is DataType.FastSim
87 alg.smearingTool.Campaign =
"mc21" if config.geometry()
is LHCPeriod.Run3
else "mc20"
90 alg.preselection = config.getPreselection (self.
containerName,
'')
93 alg = config.createAlgorithm(
'CP::AsgEnergyDecoratorAlg',
'EnergyDecorator' + self.
containerName + self.postfix )
97 config.addOutputVar (self.
containerName,
'eta',
'eta', noSys=
True)
98 config.addOutputVar (self.
containerName,
'phi',
'phi', noSys=
True)
100 config.addOutputVar (self.
containerName,
'charge',
'charge', noSys=
True)
101 config.addOutputVar (self.
containerName,
'NNDecayMode',
'NNDecayMode', noSys=
True)
102 config.addOutputVar (self.
containerName,
'nTracks',
'nTracks', noSys=
True)
106 """the ConfigBlock for the tau working point
108 This may at some point be split into multiple blocks (16 Mar 22)."""
110 def __init__ (self, containerName='', selectionName='') :
111 super (TauWorkingPointConfig, self).__init__ ()
112 self.addOption (
'containerName', containerName, type=str,
114 info=
"the name of the input container.")
115 self.addOption (
'selectionName', selectionName, type=str,
117 info=
"the name of the tau-jet selection to define (e.g. tight or "
119 self.addOption (
'postfix',
None, type=str,
120 info=
"a postfix to apply to decorations and algorithm names. "
121 "Typically not needed here as selectionName is used internally.")
122 self.addOption (
'quality',
None, type=str,
123 info=
"the ID WP (string) to use. Supported ID WPs: Tight, Medium, "
124 "Loose, VeryLoose, Baseline, BaselineForFakes.")
125 self.addOption (
'use_eVeto',
False, type=bool,
126 info=
"use selection with or without eVeto combined with tauID "
127 "recommendations: set it to True if electron mis-reconstructed as tau is a large background for your analysis")
128 self.addOption (
'useGNTau',
False, type=bool,
129 info=
"use GNTau based ID instead of RNNTau ID "
130 "recommendations: that's new experimental feature and might come default soon")
131 self.addOption (
'noEffSF',
False, type=bool,
132 info=
"disables the calculation of efficiencies and scale factors. "
133 "Experimental! only useful to test a new WP for which scale "
134 "factors are not available. The default is False.")
135 self.addOption (
'saveDetailedSF',
True, type=bool,
136 info=
"save all the independent detailed object scale factors. "
137 "The default is True.")
138 self.addOption (
'saveCombinedSF',
False, type=bool,
139 info=
"save the combined object scale factor. "
140 "The default is False.")
141 self.addOption (
'addSelectionToPreselection',
True, type=bool,
142 info=
"whether to retain only tau-jets satisfying the working point "
143 "requirements. The default is True.")
147 selectionPostfix = self.selectionName
148 if selectionPostfix !=
'' and selectionPostfix[0] !=
'_' :
149 selectionPostfix =
'_' + selectionPostfix
151 postfix = self.postfix
153 postfix = self.selectionName
154 if postfix !=
'' and postfix[0] !=
'_' :
155 postfix =
'_' + postfix
158 nameFormat =
'TauAnalysisAlgorithms/tau_selection_gntau_{}_eleid.conf'
159 if not self.use_eVeto:
160 nameFormat =
'TauAnalysisAlgorithms/tau_selection_gntau_{}_noeleid.conf'
162 nameFormat =
'TauAnalysisAlgorithms/tau_selection_{}_eleid.conf'
163 if not self.use_eVeto:
164 nameFormat =
'TauAnalysisAlgorithms/tau_selection_{}_noeleid.conf'
166 if self.
quality not in [
'Tight',
'Medium',
'Loose',
'VeryLoose',
'Baseline',
'BaselineForFakes'] :
167 raise ValueError (
"invalid tau quality: \"" + self.
quality +
168 "\", allowed values are Tight, Medium, Loose, " +
169 "VeryLoose, Baseline, BaselineForFakes")
170 inputfile = nameFormat.format(self.
quality.lower())
173 alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
'TauSelectionAlg' + postfix )
174 config.addPrivateTool(
'selectionTool',
'TauAnalysisTools::TauSelectionTool' )
175 alg.selectionTool.ConfigPath = inputfile
176 alg.selectionDecoration =
'selected_tau' + selectionPostfix +
',as_char'
177 alg.particles = config.readName (self.containerName)
178 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
179 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
180 preselection=self.addSelectionToPreselection)
185 if config.dataType()
is not DataType.Data
and not self.noEffSF
and not self.useGNTau:
191 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
192 'TauEfficiencyCorrectionsAlgReco' + postfix )
193 config.addPrivateTool(
'efficiencyCorrectionsTool',
194 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
195 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [0]
196 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
197 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
198 alg.scaleFactorDecoration =
'tau_Reco_effSF' + selectionPostfix +
'_%SYS%'
199 alg.outOfValidity = 2
200 alg.outOfValidityDeco =
'bad_Reco_eff' + selectionPostfix
201 alg.taus = config.readName (self.containerName)
202 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
203 if self.saveDetailedSF:
204 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
205 'Reco_effSF' + postfix)
206 sfList += [alg.scaleFactorDecoration]
209 if self.
quality not in (
'VeryLoose',
'Baseline',
'BaselineForFakes'):
211 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
212 'TauEfficiencyCorrectionsAlgID' + postfix )
213 config.addPrivateTool(
'efficiencyCorrectionsTool',
214 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
215 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [4]
223 raise ValueError (
"invalid tauID: \"" + self.
quality +
"\". Allowed values are loose, medium, tight")
225 alg.efficiencyCorrectionsTool.JetIDLevel = JetIDLevel
226 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
227 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
228 alg.scaleFactorDecoration =
'tau_ID_effSF' + selectionPostfix +
'_%SYS%'
229 alg.outOfValidity = 2
230 alg.outOfValidityDeco =
'bad_ID_eff' + selectionPostfix
231 alg.taus = config.readName (self.containerName)
232 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
233 if self.saveDetailedSF:
234 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
235 'ID_effSF' + postfix)
236 sfList += [alg.scaleFactorDecoration]
242 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
243 'TauEfficiencyCorrectionsAlgEvetoFakeTau' + postfix )
244 config.addPrivateTool(
'efficiencyCorrectionsTool',
245 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
247 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [10]
249 alg.efficiencyCorrectionsTool.EleIDLevel = 2
250 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
251 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
252 alg.scaleFactorDecoration =
'tau_EvetoFakeTau_effSF' + selectionPostfix +
'_%SYS%'
253 alg.outOfValidity = 2
254 alg.outOfValidityDeco =
'bad_EvetoFakeTau_eff' + selectionPostfix
255 alg.taus = config.readName (self.containerName)
256 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
257 if self.saveDetailedSF:
258 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
259 'EvetoFakeTau_effSF' + postfix)
260 sfList += [alg.scaleFactorDecoration]
263 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
264 'TauEfficiencyCorrectionsAlgEvetoTrueTau' + postfix )
265 config.addPrivateTool(
'efficiencyCorrectionsTool',
266 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
268 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [8]
269 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
270 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
271 alg.scaleFactorDecoration =
'tau_EvetoTrueTau_effSF' + selectionPostfix +
'_%SYS%'
272 alg.outOfValidity = 2
273 alg.outOfValidityDeco =
'bad_EvetoTrueTau_eff' + selectionPostfix
274 alg.taus = config.readName (self.containerName)
275 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
276 if self.saveDetailedSF:
277 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
278 'EvetoTrueTau_effSF' + postfix)
279 sfList += [alg.scaleFactorDecoration]
281 if self.saveCombinedSF:
282 alg = config.createAlgorithm(
'CP::AsgObjectScaleFactorAlg',
283 'TauCombinedEfficiencyScaleFactorAlg' + postfix )
284 alg.particles = config.readName (self.containerName)
285 alg.inScaleFactors = sfList
286 alg.outScaleFactor =
'effSF' + postfix +
'_%SYS%'
287 config.addOutputVar (self.containerName, alg.outScaleFactor,
293 super (EXPERIMENTAL_TauCombineMuonRemovalConfig, self).__init__ ()
295 'inputTaus',
'TauJets', type=str,
297 info=
"the name of the input tau container."
300 'inputTausMuRM',
'TauJets_MuonRM', type=str,
302 info=
"the name of the input tau container with muon removal applied."
305 'outputTaus',
'TauJets_MuonRmCombined', type=str,
307 info=
"the name of the output tau container."
312 if config.isPhyslite() :
313 raise(RuntimeError(
"Muon removal taus is not available in Physlite mode"))
315 alg = config.createAlgorithm(
'CP::TauCombineMuonRMTausAlg',
'TauCombineMuonRMTausAlg' + self.outputTaus )
316 alg.taus = self.inputTaus
317 alg.muonrm_taus = self.inputTausMuRM
318 alg.combined_taus = self.outputTaus
323 super (TauTriggerAnalysisSFBlock, self).__init__ ()
325 self.addOption (
'triggerChainsPerYear', {}, type=
None,
326 info=
"a dictionary with key (string) the year and value (list of "
327 "strings) the trigger chains. The default is {} (empty dictionary).")
328 self.addOption (
'tauID',
'', type=str,
329 info=
"the tau quality WP (string) to use.")
330 self.addOption (
'prefixSF',
'trigEffSF', type=str,
331 info=
"the decoration prefix for trigger scale factors, "
332 "the default is 'trigEffSF'")
333 self.addOption (
'includeAllYears',
False, type=bool,
334 info=
"if True, all configured years will be included in all jobs. "
335 "The default is False.")
336 self.addOption (
'removeHLTPrefix',
True, type=bool,
337 info=
"remove the HLT prefix from trigger chain names, "
338 "The default is True.")
339 self.addOption (
'containerName',
'', type=str,
340 info=
"the input tau container, with a possible selection, in "
341 "the format container or container.selection.")
344 return dictionary.get(
int(year), dictionary.get(
str(year), []))
348 if config.dataType()
is not DataType.Data:
349 log = logging.getLogger(
'TauJetTriggerSFConfig')
352 if self.includeAllYears:
353 for year
in self.triggerChainsPerYear:
354 triggers.update(self.
get_year_data(self.triggerChainsPerYear, year))
355 elif config.campaign()
is Campaign.MC20a:
356 triggers.update(self.
get_year_data(self.triggerChainsPerYear, 2015))
357 triggers.update(self.
get_year_data(self.triggerChainsPerYear, 2016))
358 elif config.campaign()
is Campaign.MC20d:
359 triggers.update(self.
get_year_data(self.triggerChainsPerYear, 2017))
360 elif config.campaign()
is Campaign.MC20e:
361 triggers.update(self.
get_year_data(self.triggerChainsPerYear, 2018))
362 elif config.campaign()
in [Campaign.MC21a, Campaign.MC23a]:
363 triggers.update(self.
get_year_data(self.triggerChainsPerYear, 2022))
364 elif config.campaign()
in [Campaign.MC23c, Campaign.MC23d]:
365 triggers.update(self.
get_year_data(self.triggerChainsPerYear, 2023))
367 log.warning(
"unknown campaign, skipping triggers: %s",
str(config.campaign()))
369 for chain
in triggers:
370 chain_noHLT = chain.replace(
"HLT_",
"")
371 chain_out = chain_noHLT
if self.removeHLTPrefix
else chain
372 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
373 'TauTrigEfficiencyCorrectionsAlg_' + self.
tauID +
'_' + chain )
374 config.addPrivateTool(
'efficiencyCorrectionsTool',
375 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
378 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [12]
379 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
380 alg.efficiencyCorrectionsTool.TriggerName = chain
386 elif self.
tauID==
"Medium":
388 elif self.
tauID==
"Tight":
391 raise ValueError (
"invalid tauID: \"" + self.
tauID +
"\". Allowed values are loose, medium, tight")
392 alg.efficiencyCorrectionsTool.JetIDLevel = JetIDLevel
393 alg.efficiencyCorrectionsTool.TriggerSFMeasurement =
"combined"
394 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
396 alg.scaleFactorDecoration = f
"tau_{self.prefixSF}_{chain_out}_%SYS%"
397 alg.outOfValidity = 2
398 alg.outOfValidityDeco = f
"bad_eff_tautrig_{chain_out}"
399 alg.taus = config.readName (self.containerName)
400 alg.preselection = config.getPreselection (self.containerName, self.
tauID)
401 config.addOutputVar (self.containerName, alg.scaleFactorDecoration, f
"{self.prefixSF}_{chain_out}")