192 def makeAlgs (self, config) :
194 selectionPostfix = self.selectionName
195 if selectionPostfix !=
'' and selectionPostfix[0] !=
'_' :
196 selectionPostfix =
'_' + selectionPostfix
198 postfix = self.postfix
200 postfix = self.selectionName
201 if postfix !=
'' and postfix[0] !=
'_' :
202 postfix =
'_' + postfix
205 if self.useSelectionConfigFile:
206 nameFormat =
'TauAnalysisAlgorithms/tau_selection_'
208 nameFormat = nameFormat +
'nopt_'
210 nameFormat = nameFormat +
'lowpt_'
212 nameFormat = nameFormat +
'gntau_'
213 nameFormat = nameFormat +
'{}_'
215 nameFormat = nameFormat +
'eleid'
217 nameFormat = nameFormat +
'noeleid'
219 nameFormat = nameFormat +
'_muonolr'
220 nameFormat = nameFormat +
'.conf'
222 if self.quality
not in [
'Tight',
'Medium',
'Loose',
'VeryLoose',
'Baseline',
'BaselineForFakes'] :
223 raise ValueError (
"invalid tau quality: \"" + self.quality +
224 "\", allowed values are Tight, Medium, Loose, " +
225 "VeryLoose, Baseline, BaselineForFakes")
228 alg = config.createAlgorithm(
'CP::AsgSelectionAlg',
'TauSelectionAlg' )
229 config.addPrivateTool(
'selectionTool',
'TauAnalysisTools::TauSelectionTool' )
230 if self.useSelectionConfigFile:
231 inputfile = nameFormat.format(self.quality.lower())
232 alg.selectionTool.ConfigPath = inputfile
235 from ROOT
import TauAnalysisTools
236 selectioncuts = TauAnalysisTools.SelectionCuts
237 alg.selectionTool.ConfigPath =
""
238 alg.selectionTool.SelectionCuts =
int(selectioncuts.CutPt |
239 selectioncuts.CutAbsEta |
240 selectioncuts.CutAbsCharge |
241 selectioncuts.CutNTrack |
242 selectioncuts.CutJetRNNScoreSigTrans |
243 selectioncuts.CutGNTauScoreSigTrans |
244 selectioncuts.CutJetIDWP |
245 selectioncuts.CutEleIDWP |
246 selectioncuts.CutMuonOLR)
248 alg.selectionTool.PtMin = self.manual_sel_minpt
249 alg.selectionTool.AbsEtaRegion = self.manual_sel_absetaregion
250 alg.selectionTool.AbsCharges = self.manual_sel_abscharges
251 alg.selectionTool.NTracks = self.manual_sel_ntracks
252 alg.selectionTool.JetRNNSigTransMin = self.manual_sel_minrnnscore
253 alg.selectionTool.GNTauSigTransMin = self.manual_sel_mingntauscore
255 if self.manual_sel_minrnnscore != -1
and self.manual_sel_mingntauscore != -1:
256 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")
258 if self.manual_sel_rnnwp
is None:
259 alg.selectionTool.JetIDWP = 1
260 elif self.manual_sel_rnnwp ==
"veryloose":
261 alg.selectionTool.JetIDWP = 6
262 elif self.manual_sel_rnnwp ==
"loose":
263 alg.selectionTool.JetIDWP = 7
264 elif self.manual_sel_rnnwp ==
"medium":
265 alg.selectionTool.JetIDWP = 8
266 elif self.manual_sel_rnnwp ==
"tight":
267 alg.selectionTool.JetIDWP = 9
269 raise ValueError (
"invalid RNN TauID WP: \"" + self.manual_sel_rnnwp +
"\". Allowed values are None, veryloose, loose, medium, tight")
272 if self.manual_sel_minrnnscore != -1
and self.manual_sel_rnnwp
is not None:
273 raise RuntimeError(
"manual_sel_minrnnscore and manual_sel_rnnwp have been both set; please set only one of them")
276 if self.manual_sel_gntauwp
is None:
277 alg.selectionTool.JetIDWP = 1
278 elif self.manual_sel_gntauwp ==
"veryloose":
279 alg.selectionTool.JetIDWP = 10
280 elif self.manual_sel_gntauwp ==
"loose":
281 alg.selectionTool.JetIDWP = 11
282 elif self.manual_sel_gntauwp ==
"medium":
283 alg.selectionTool.JetIDWP = 12
284 elif self.manual_sel_gntauwp ==
"tight":
285 alg.selectionTool.JetIDWP = 13
287 raise ValueError (
"invalid GNN Tau ID WP: \"" + self.manual_sel_gntauwp +
"\". Allowed values are None, veryloose, loose, medium, tight")
290 if self.manual_sel_mingntauscore != -1
and self.manual_sel_gntauwp
is not None:
291 raise RuntimeError(
"manual_sel_mingntauscore and manual_sel_gntauwp have been both set; please set only one of them")
294 if self.manual_sel_evetowp
is None:
295 alg.selectionTool.EleIDWP = 1
296 elif self.manual_sel_evetowp ==
"loose":
297 alg.selectionTool.EleIDWP = 2
298 elif self.manual_sel_evetowp ==
"medium":
299 alg.selectionTool.EleIDWP = 3
300 elif self.manual_sel_evetowp ==
"tight":
301 alg.selectionTool.EleIDWP = 4
303 raise ValueError (
"invalid eVeto WP: \"" + self.manual_sel_evetowp +
"\". Allowed values are None, loose, medium, tight")
306 alg.selectionTool.MuonOLR = self.manual_sel_muonolr
308 alg.selectionDecoration =
'selected_tau' + selectionPostfix +
',as_char'
309 alg.particles = config.readName (self.containerName)
310 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
311 config.addSelection (self.containerName, self.selectionName, alg.selectionDecoration,
312 preselection=self.addSelectionToPreselection)
317 if config.dataType()
is not DataType.Data
and not self.noEffSF:
318 log = logging.getLogger(
'TauJetSFConfig')
324 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
325 'TauEfficiencyCorrectionsAlgReco' )
326 config.addPrivateTool(
'efficiencyCorrectionsTool',
327 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
328 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [0]
329 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
330 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
331 alg.scaleFactorDecoration =
'tau_Reco_effSF' + selectionPostfix +
'_%SYS%'
332 alg.outOfValidity = 2
333 alg.outOfValidityDeco =
'bad_Reco_eff' + selectionPostfix
334 alg.taus = config.readName (self.containerName)
335 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
336 if self.saveDetailedSF:
337 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
338 'Reco_effSF' + postfix)
339 sfList += [alg.scaleFactorDecoration]
342 if self.quality
not in (
'VeryLoose',
'Baseline',
'BaselineForFakes'):
343 if not self.useGNTau:
345 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
346 'TauEfficiencyCorrectionsAlgID' )
347 config.addPrivateTool(
'efficiencyCorrectionsTool',
348 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
349 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [4]
350 if self.quality==
"Loose":
352 elif self.quality==
"Medium":
354 elif self.quality==
"Tight":
357 raise ValueError (
"invalid tauID: \"" + self.quality +
"\". Allowed values are loose, medium, tight")
359 alg.efficiencyCorrectionsTool.JetIDLevel = JetIDLevel
360 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
361 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
362 alg.scaleFactorDecoration =
'tau_ID_effSF' + selectionPostfix +
'_%SYS%'
363 alg.outOfValidity = 2
364 alg.outOfValidityDeco =
'bad_ID_eff' + selectionPostfix
365 alg.taus = config.readName (self.containerName)
366 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
367 if self.saveDetailedSF:
368 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
369 'ID_effSF' + postfix)
370 sfList += [alg.scaleFactorDecoration]
374 if not self.useGNTau:
376 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
377 'TauEfficiencyCorrectionsAlgEvetoFakeTau' )
378 config.addPrivateTool(
'efficiencyCorrectionsTool',
379 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
380 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [10]
382 alg.efficiencyCorrectionsTool.EleIDLevel = 2
383 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
384 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
385 alg.scaleFactorDecoration =
'tau_EvetoFakeTau_effSF' + selectionPostfix +
'_%SYS%'
387 if self.quality==
"Loose":
389 elif self.quality==
"Medium":
391 elif self.quality==
"Tight":
392 log.warning(
"eVeto SFs are not available for Tight WP -> fallback to Medium WP")
394 alg.efficiencyCorrectionsTool.JetIDLevel = JetIDLevel
395 alg.outOfValidity = 2
396 alg.outOfValidityDeco =
'bad_EvetoFakeTau_eff' + selectionPostfix
397 alg.taus = config.readName (self.containerName)
398 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
399 if self.saveDetailedSF:
400 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
401 'EvetoFakeTau_effSF' + postfix)
402 sfList += [alg.scaleFactorDecoration]
405 alg = config.createAlgorithm(
'CP::TauEfficiencyCorrectionsAlg',
406 'TauEfficiencyCorrectionsAlgEvetoTrueTau' )
407 config.addPrivateTool(
'efficiencyCorrectionsTool',
408 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
409 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [8]
410 alg.efficiencyCorrectionsTool.useFastSim = config.dataType()
is DataType.FastSim
411 alg.efficiencyCorrectionsTool.Campaign =
"mc23" if config.geometry()
is LHCPeriod.Run3
else "mc20"
412 alg.scaleFactorDecoration =
'tau_EvetoTrueTau_effSF' + selectionPostfix +
'_%SYS%'
413 alg.outOfValidity = 2
414 alg.outOfValidityDeco =
'bad_EvetoTrueTau_eff' + selectionPostfix
415 alg.taus = config.readName (self.containerName)
416 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
417 if self.saveDetailedSF:
418 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
419 'EvetoTrueTau_effSF' + postfix)
420 sfList += [alg.scaleFactorDecoration]
422 if self.saveCombinedSF:
423 alg = config.createAlgorithm(
'CP::AsgObjectScaleFactorAlg',
424 'TauCombinedEfficiencyScaleFactorAlg' )
425 alg.particles = config.readName (self.containerName)
426 alg.inScaleFactors = sfList
427 alg.outScaleFactor =
'effSF' + postfix +
'_%SYS%'
428 config.addOutputVar (self.containerName, alg.outScaleFactor,