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