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