203 def makeAlgs (self, config) :
205 selectionPostfix = self.selectionName
206 if selectionPostfix !=
'' and selectionPostfix[0] !=
'_' :
207 selectionPostfix =
'_' + selectionPostfix
209 postfix = self.postfix
211 postfix = self.selectionName
212 if postfix !=
'' and postfix[0] !=
'_' :
213 postfix =
'_' + postfix
216 if self.useSelectionConfigFile:
217 nameFormat =
'TauAnalysisAlgorithms/tau_selection_'
219 nameFormat = nameFormat +
'nopt_'
221 nameFormat = nameFormat +
'lowpt_'
223 nameFormat = nameFormat +
'gntau_'
224 nameFormat = nameFormat +
'{}_'
226 nameFormat = nameFormat +
'eleid'
228 nameFormat = nameFormat +
'noeleid'
230 nameFormat = nameFormat +
'_muonolr'
231 nameFormat = nameFormat +
'.conf'
233 if self.quality
not in [
'Tight',
'Medium',
'Loose',
'VeryLoose',
'Baseline',
'BaselineForFakes'] :
234 raise ValueError (
"invalid tau quality: \"" + self.quality +
235 "\", allowed values are Tight, Medium, Loose, " +
236 "VeryLoose, Baseline, BaselineForFakes")
239 alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
'TauSelectionAlg' )
240 config.addPrivateTool(
'selectionTool',
'TauAnalysisTools::TauSelectionTool' )
241 if self.useSelectionConfigFile:
242 inputfile = nameFormat.format(self.quality.lower())
243 alg.selectionTool.ConfigPath = inputfile
246 from ROOT
import TauAnalysisTools
247 selectioncuts = TauAnalysisTools.SelectionCuts
248 alg.selectionTool.ConfigPath =
""
249 alg.selectionTool.SelectionCuts =
int(selectioncuts.CutPt |
250 selectioncuts.CutAbsEta |
251 selectioncuts.CutAbsCharge |
252 selectioncuts.CutNTrack |
253 selectioncuts.CutJetRNNScoreSigTrans |
254 selectioncuts.CutGNTauScoreSigTrans |
255 selectioncuts.CutJetIDWP |
256 selectioncuts.CutEleIDWP |
257 selectioncuts.CutMuonOLR)
259 alg.selectionTool.PtMin = self.manual_sel_minpt
260 alg.selectionTool.AbsEtaRegion = self.manual_sel_absetaregion
261 alg.selectionTool.AbsCharges = self.manual_sel_abscharges
262 alg.selectionTool.NTracks = self.manual_sel_ntracks
263 alg.selectionTool.JetRNNSigTransMin = self.manual_sel_minrnnscore
264 alg.selectionTool.GNTauSigTransMin = self.manual_sel_mingntauscore
266 if self.manual_sel_minrnnscore != -1
and self.manual_sel_mingntauscore != -1:
267 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")
269 if self.manual_sel_rnnwp
is None:
270 alg.selectionTool.JetIDWP = 1
271 elif self.manual_sel_rnnwp ==
"veryloose":
272 alg.selectionTool.JetIDWP = 6
273 elif self.manual_sel_rnnwp ==
"loose":
274 alg.selectionTool.JetIDWP = 7
275 elif self.manual_sel_rnnwp ==
"medium":
276 alg.selectionTool.JetIDWP = 8
277 elif self.manual_sel_rnnwp ==
"tight":
278 alg.selectionTool.JetIDWP = 9
280 raise ValueError (
"invalid RNN TauID WP: \"" + self.manual_sel_rnnwp +
"\". Allowed values are None, veryloose, loose, medium, tight")
283 if self.manual_sel_minrnnscore != -1
and self.manual_sel_rnnwp
is not None:
284 raise RuntimeError(
"manual_sel_minrnnscore and manual_sel_rnnwp have been both set; please set only one of them")
287 if self.manual_sel_gntauwp
is None:
288 alg.selectionTool.JetIDWP = 1
289 elif self.manual_sel_gntauwp ==
"veryloose":
290 alg.selectionTool.JetIDWP = 10
291 elif self.manual_sel_gntauwp ==
"loose":
292 alg.selectionTool.JetIDWP = 11
293 elif self.manual_sel_gntauwp ==
"medium":
294 alg.selectionTool.JetIDWP = 12
295 elif self.manual_sel_gntauwp ==
"tight":
296 alg.selectionTool.JetIDWP = 13
298 raise ValueError (
"invalid GNN Tau ID WP: \"" + self.manual_sel_gntauwp +
"\". Allowed values are None, veryloose, loose, medium, tight")
301 if self.manual_sel_mingntauscore != -1
and self.manual_sel_gntauwp
is not None:
302 raise RuntimeError(
"manual_sel_mingntauscore and manual_sel_gntauwp have been both set; please set only one of them")
305 if self.manual_sel_evetowp
is None:
306 alg.selectionTool.EleIDWP = 1
307 elif self.manual_sel_evetowp ==
"loose":
308 alg.selectionTool.EleIDWP = 2
309 elif self.manual_sel_evetowp ==
"medium":
310 alg.selectionTool.EleIDWP = 3
311 elif self.manual_sel_evetowp ==
"tight":
312 alg.selectionTool.EleIDWP = 4
314 raise ValueError (
"invalid eVeto WP: \"" + self.manual_sel_evetowp +
"\". Allowed values are None, loose, medium, tight")
317 alg.selectionTool.MuonOLR = self.manual_sel_muonolr
319 alg.selectionDecoration =
'selected_tau' + selectionPostfix +
',as_char'
320 alg.particles = config.readName (self.containerName)
321 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
322 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
323 preselection=self.addSelectionToPreselection)
328 if config.dataType()
is not DataType.Data
and not self.noEffSF:
329 log = logging.getLogger(
'TauJetSFConfig')
335 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
336 'TauEfficiencyCorrectionsAlgReco' )
337 config.addPrivateTool(
'efficiencyCorrectionsTool',
338 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
339 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [0]
340 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
341 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
342 alg.scaleFactorDecoration =
'tau_Reco_effSF' + selectionPostfix +
'_%SYS%'
343 alg.outOfValidity = 2
344 alg.outOfValidityDeco =
'bad_Reco_eff' + selectionPostfix
345 alg.taus = config.readName (self.containerName)
346 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
347 if self.saveDetailedSF:
348 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
349 'Reco_effSF' + postfix)
350 sfList += [alg.scaleFactorDecoration]
353 if self.quality
not in (
'VeryLoose',
'Baseline',
'BaselineForFakes'):
354 if not self.useGNTau:
356 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
357 'TauEfficiencyCorrectionsAlgID' )
358 config.addPrivateTool(
'efficiencyCorrectionsTool',
359 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
360 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [4]
361 if self.quality==
"Loose":
363 elif self.quality==
"Medium":
365 elif self.quality==
"Tight":
368 raise ValueError (
"invalid tauID: \"" + self.quality +
"\". Allowed values are loose, medium, tight")
370 alg.efficiencyCorrectionsTool.JetIDLevel = JetIDLevel
371 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
372 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
373 alg.scaleFactorDecoration =
'tau_ID_effSF' + selectionPostfix +
'_%SYS%'
374 alg.outOfValidity = 2
375 alg.outOfValidityDeco =
'bad_ID_eff' + selectionPostfix
376 alg.taus = config.readName (self.containerName)
377 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
378 if self.saveDetailedSF:
379 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
380 'ID_effSF' + postfix)
381 sfList += [alg.scaleFactorDecoration]
385 if not self.useGNTau:
387 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
388 'TauEfficiencyCorrectionsAlgEvetoFakeTau' )
389 config.addPrivateTool(
'efficiencyCorrectionsTool',
390 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
391 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [10]
393 alg.efficiencyCorrectionsTool.EleIDLevel = 2
394 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
395 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
396 alg.scaleFactorDecoration =
'tau_EvetoFakeTau_effSF' + selectionPostfix +
'_%SYS%'
398 if self.quality==
"Loose":
400 elif self.quality==
"Medium":
402 elif self.quality==
"Tight":
403 log.warning(
"eVeto SFs are not available for Tight WP -> fallback to Medium WP")
405 alg.efficiencyCorrectionsTool.JetIDLevel = JetIDLevel
406 alg.outOfValidity = 2
407 alg.outOfValidityDeco =
'bad_EvetoFakeTau_eff' + selectionPostfix
408 alg.taus = config.readName (self.containerName)
409 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
410 if self.saveDetailedSF:
411 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
412 'EvetoFakeTau_effSF' + postfix)
413 sfList += [alg.scaleFactorDecoration]
416 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
417 'TauEfficiencyCorrectionsAlgEvetoTrueTau' )
418 config.addPrivateTool(
'efficiencyCorrectionsTool',
419 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
420 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [8]
421 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
422 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
423 alg.scaleFactorDecoration =
'tau_EvetoTrueTau_effSF' + selectionPostfix +
'_%SYS%'
424 alg.outOfValidity = 2
425 alg.outOfValidityDeco =
'bad_EvetoTrueTau_eff' + selectionPostfix
426 alg.taus = config.readName (self.containerName)
427 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
428 if self.saveDetailedSF:
429 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
430 'EvetoTrueTau_effSF' + postfix)
431 sfList += [alg.scaleFactorDecoration]
433 if self.saveCombinedSF:
434 alg = config.createAlgorithm(
'CP::AsgObjectScaleFactorAlg',
435 'TauCombinedEfficiencyScaleFactorAlg' )
436 alg.particles = config.readName (self.containerName)
437 alg.inScaleFactors = sfList
438 alg.outScaleFactor =
'effSF' + postfix +
'_%SYS%'
439 config.addOutputVar (self.containerName, alg.outScaleFactor,