187 def makeAlgs (self, config) :
189 selectionPostfix = self.selectionName
190 if selectionPostfix !=
'' and selectionPostfix[0] !=
'_' :
191 selectionPostfix =
'_' + selectionPostfix
193 postfix = self.postfix
195 postfix = self.selectionName
196 if postfix !=
'' and postfix[0] !=
'_' :
197 postfix =
'_' + postfix
200 if self.useSelectionConfigFile:
201 nameFormat =
'TauAnalysisAlgorithms/tau_selection_'
203 nameFormat = nameFormat +
'nopt_'
205 nameFormat = nameFormat +
'lowpt_'
207 nameFormat = nameFormat +
'gntau_'
208 nameFormat = nameFormat +
'{}_'
210 nameFormat = nameFormat +
'eleid'
212 nameFormat = nameFormat +
'noeleid'
214 nameFormat = nameFormat +
'_muonolr'
215 nameFormat = nameFormat +
'.conf'
217 if self.quality
not in [
'Tight',
'Medium',
'Loose',
'VeryLoose',
'Baseline',
'BaselineForFakes'] :
218 raise ValueError (
"invalid tau quality: \"" + self.quality +
219 "\", allowed values are Tight, Medium, Loose, " +
220 "VeryLoose, Baseline, BaselineForFakes")
223 alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
'TauSelectionAlg' )
224 config.addPrivateTool(
'selectionTool',
'TauAnalysisTools::TauSelectionTool' )
225 if self.useSelectionConfigFile:
226 inputfile = nameFormat.format(self.quality.lower())
227 alg.selectionTool.ConfigPath = inputfile
230 from ROOT
import TauAnalysisTools
231 selectioncuts = TauAnalysisTools.SelectionCuts
232 alg.selectionTool.ConfigPath =
""
233 alg.selectionTool.SelectionCuts =
int(selectioncuts.CutPt |
234 selectioncuts.CutAbsEta |
235 selectioncuts.CutAbsCharge |
236 selectioncuts.CutNTrack |
237 selectioncuts.CutJetRNNScoreSigTrans |
238 selectioncuts.CutGNTauScoreSigTrans |
239 selectioncuts.CutJetIDWP |
240 selectioncuts.CutEleIDWP |
241 selectioncuts.CutMuonOLR)
243 alg.selectionTool.PtMin = self.manual_sel_minpt
244 alg.selectionTool.AbsEtaRegion = self.manual_sel_absetaregion
245 alg.selectionTool.AbsCharges = self.manual_sel_abscharges
246 alg.selectionTool.NTracks = self.manual_sel_ntracks
247 alg.selectionTool.JetRNNSigTransMin = self.manual_sel_minrnnscore
248 alg.selectionTool.GNTauSigTransMin = self.manual_sel_mingntauscore
250 if self.manual_sel_minrnnscore != -1
and self.manual_sel_mingntauscore != -1:
251 raise RuntimeError(
"manual_sel_minrnnscore and manual_sel_mingntauscore have been both set; please choose only one type of ID: RNN or GNTau, not both")
253 if self.manual_sel_rnnwp
is None:
254 alg.selectionTool.JetIDWP = 1
255 elif self.manual_sel_rnnwp ==
"veryloose":
256 alg.selectionTool.JetIDWP = 6
257 elif self.manual_sel_rnnwp ==
"loose":
258 alg.selectionTool.JetIDWP = 7
259 elif self.manual_sel_rnnwp ==
"medium":
260 alg.selectionTool.JetIDWP = 8
261 elif self.manual_sel_rnnwp ==
"tight":
262 alg.selectionTool.JetIDWP = 9
264 raise ValueError (
"invalid RNN TauID WP: \"" + self.manual_sel_rnnwp +
"\". Allowed values are None, veryloose, loose, medium, tight")
267 if self.manual_sel_minrnnscore != -1
and self.manual_sel_rnnwp
is not None:
268 raise RuntimeError(
"manual_sel_minrnnscore and manual_sel_rnnwp have been both set; please set only one of them")
271 if self.manual_sel_gntauwp
is None:
272 alg.selectionTool.JetIDWP = 1
273 elif self.manual_sel_gntauwp ==
"veryloose":
274 alg.selectionTool.JetIDWP = 10
275 elif self.manual_sel_gntauwp ==
"loose":
276 alg.selectionTool.JetIDWP = 11
277 elif self.manual_sel_gntauwp ==
"medium":
278 alg.selectionTool.JetIDWP = 12
279 elif self.manual_sel_gntauwp ==
"tight":
280 alg.selectionTool.JetIDWP = 13
282 raise ValueError (
"invalid GNN Tau ID WP: \"" + self.manual_sel_gntauwp +
"\". Allowed values are None, veryloose, loose, medium, tight")
285 if self.manual_sel_mingntauscore != -1
and self.manual_sel_gntauwp
is not None:
286 raise RuntimeError(
"manual_sel_mingntauscore and manual_sel_gntauwp have been both set; please set only one of them")
289 if self.manual_sel_evetowp
is None:
290 alg.selectionTool.EleIDWP = 1
291 elif self.manual_sel_evetowp ==
"loose":
292 alg.selectionTool.EleIDWP = 2
293 elif self.manual_sel_evetowp ==
"medium":
294 alg.selectionTool.EleIDWP = 3
295 elif self.manual_sel_evetowp ==
"tight":
296 alg.selectionTool.EleIDWP = 4
298 raise ValueError (
"invalid eVeto WP: \"" + self.manual_sel_evetowp +
"\". Allowed values are None, loose, medium, tight")
301 alg.selectionTool.MuonOLR = self.manual_sel_muonolr
303 alg.selectionDecoration =
'selected_tau' + selectionPostfix +
',as_char'
304 alg.particles = config.readName (self.containerName)
305 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
306 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
307 preselection=self.addSelectionToPreselection)
312 if config.dataType()
is not DataType.Data
and not self.noEffSF:
313 log = logging.getLogger(
'TauJetSFConfig')
319 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
320 'TauEfficiencyCorrectionsAlgReco' )
321 config.addPrivateTool(
'efficiencyCorrectionsTool',
322 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
323 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [0]
324 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
325 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
326 alg.scaleFactorDecoration =
'tau_Reco_effSF' + selectionPostfix +
'_%SYS%'
327 alg.outOfValidity = 2
328 alg.outOfValidityDeco =
'bad_Reco_eff' + selectionPostfix
329 alg.taus = config.readName (self.containerName)
330 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
331 if self.saveDetailedSF:
332 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
333 'Reco_effSF' + postfix)
334 sfList += [alg.scaleFactorDecoration]
337 if self.quality
not in (
'VeryLoose',
'Baseline',
'BaselineForFakes'):
338 if not self.useGNTau:
340 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
341 'TauEfficiencyCorrectionsAlgID' )
342 config.addPrivateTool(
'efficiencyCorrectionsTool',
343 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
344 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [4]
345 if self.quality==
"Loose":
347 elif self.quality==
"Medium":
349 elif self.quality==
"Tight":
352 raise ValueError (
"invalid tauID: \"" + self.quality +
"\". Allowed values are loose, medium, tight")
354 alg.efficiencyCorrectionsTool.JetIDLevel = JetIDLevel
355 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
356 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
357 alg.scaleFactorDecoration =
'tau_ID_effSF' + selectionPostfix +
'_%SYS%'
358 alg.outOfValidity = 2
359 alg.outOfValidityDeco =
'bad_ID_eff' + selectionPostfix
360 alg.taus = config.readName (self.containerName)
361 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
362 if self.saveDetailedSF:
363 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
364 'ID_effSF' + postfix)
365 sfList += [alg.scaleFactorDecoration]
369 if not self.useGNTau:
371 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
372 'TauEfficiencyCorrectionsAlgEvetoFakeTau' )
373 config.addPrivateTool(
'efficiencyCorrectionsTool',
374 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
375 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [10]
377 alg.efficiencyCorrectionsTool.EleIDLevel = 2
378 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
379 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
380 alg.scaleFactorDecoration =
'tau_EvetoFakeTau_effSF' + selectionPostfix +
'_%SYS%'
382 if self.quality==
"Loose":
384 elif self.quality==
"Medium":
386 elif self.quality==
"Tight":
387 log.warning(
"eVeto SFs are not available for Tight WP -> fallback to Medium WP")
389 alg.efficiencyCorrectionsTool.JetIDLevel = JetIDLevel
390 alg.outOfValidity = 2
391 alg.outOfValidityDeco =
'bad_EvetoFakeTau_eff' + selectionPostfix
392 alg.taus = config.readName (self.containerName)
393 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
394 if self.saveDetailedSF:
395 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
396 'EvetoFakeTau_effSF' + postfix)
397 sfList += [alg.scaleFactorDecoration]
400 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
401 'TauEfficiencyCorrectionsAlgEvetoTrueTau' )
402 config.addPrivateTool(
'efficiencyCorrectionsTool',
403 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
404 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [8]
405 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
406 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
407 alg.scaleFactorDecoration =
'tau_EvetoTrueTau_effSF' + selectionPostfix +
'_%SYS%'
408 alg.outOfValidity = 2
409 alg.outOfValidityDeco =
'bad_EvetoTrueTau_eff' + selectionPostfix
410 alg.taus = config.readName (self.containerName)
411 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
412 if self.saveDetailedSF:
413 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
414 'EvetoTrueTau_effSF' + postfix)
415 sfList += [alg.scaleFactorDecoration]
417 if self.saveCombinedSF:
418 alg = config.createAlgorithm(
'CP::AsgObjectScaleFactorAlg',
419 'TauCombinedEfficiencyScaleFactorAlg' )
420 alg.particles = config.readName (self.containerName)
421 alg.inScaleFactors = sfList
422 alg.outScaleFactor =
'effSF' + postfix +
'_%SYS%'
423 config.addOutputVar (self.containerName, alg.outScaleFactor,