401 def makeAlgs (self, config) :
402
403 selectionPostfix = self.selectionName
404 if selectionPostfix != '' and selectionPostfix[0] != '_' :
405 selectionPostfix = '_' + selectionPostfix
406
407 postfix = self.postfix
408 if postfix is None :
409 postfix = self.selectionName
410 if postfix != '' and postfix[0] != '_' :
411 postfix = '_' + postfix
412
413 if self.quality is not None and self.quality not in ['Tight', 'Medium', 'Loose', 'VeryLoose', 'Baseline', 'BaselineForFakes'] :
414 raise ValueError ("invalid tau quality: \"" + self.quality +
415 "\", allowed values are Tight, Medium, Loose, " +
416 "VeryLoose, Baseline, BaselineForFakes")
417
418 sfList = []
419
420
421 if config.dataType() is not DataType.Data and not self.noEffSF:
422 log = logging.getLogger('TauJetSFConfig')
423
424
425
426
427
428 alg = config.createAlgorithm( 'CP::TauEfficiencyCorrectionsAlg',
429 'TauEfficiencyCorrectionsAlgReco' )
430 config.addPrivateTool( 'efficiencyCorrectionsTool',
431 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
432 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [0]
433 alg.efficiencyCorrectionsTool.Campaign = "mc23" if config.geometry() is LHCPeriod.Run3 else "mc20"
434 alg.efficiencyCorrectionsTool.useFastSim = config.dataType() is DataType.FastSim
435 alg.scaleFactorDecoration = 'tau_Reco_effSF' + selectionPostfix + '_%SYS%'
436 alg.outOfValidity = 2
437 alg.outOfValidityDeco = 'bad_Reco_eff' + selectionPostfix
438 alg.taus = config.readName (self.containerName)
439 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
440 if self.saveDetailedSF:
441 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
442 'Reco_effSF' + postfix)
443 sfList += [alg.scaleFactorDecoration]
444
445
446 campaign = "mc23" if config.geometry() is LHCPeriod.Run3 else "mc20"
447
448
449 if self.quality not in ('VeryLoose','Baseline','BaselineForFakes'):
450 alg = config.createAlgorithm( 'CP::TauEfficiencyCorrectionsAlg',
451 'TauEfficiencyCorrectionsAlgID' )
452 config.addPrivateTool( 'efficiencyCorrectionsTool',
453 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
454 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [4]
455
456 jetIDLevels = (
457 {"Loose": 11, "Medium": 12, "Tight": 13}
458 if self.useGNTau
459 else {"Loose": 7, "Medium": 8, "Tight": 9}
460 )
461 wp = self.quality
462 if not self.useGNTau and self.manual_sel_rnnwp is not None:
463 wp = self.manual_sel_rnnwp.capitalize()
464 if wp not in jetIDLevels:
465 raise ValueError(
466 'Invalid tauID: "'
467 + str(wp)
468 + '". Allowed values are Loose, Medium, Tight'
469 )
470
471 alg.efficiencyCorrectionsTool.JetIDLevel = jetIDLevels[wp]
472 alg.efficiencyCorrectionsTool.useFastSim = config.dataType() is DataType.FastSim
473 alg.efficiencyCorrectionsTool.Campaign = campaign
474 alg.efficiencyCorrectionsTool.useGNTau = self.useGNTau
475 alg.scaleFactorDecoration = 'tau_ID_effSF' + selectionPostfix + '_%SYS%'
476 alg.outOfValidity = 2
477 alg.outOfValidityDeco = 'bad_ID_eff' + selectionPostfix
478 alg.taus = config.readName (self.containerName)
479 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
480 if self.saveDetailedSF:
481 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
482 'ID_effSF' + postfix)
483 sfList += [alg.scaleFactorDecoration]
484
485
486 if self.use_eVeto:
487
488 if self.quality not in ('VeryLoose','Baseline','BaselineForFakes'):
489
490 alg = config.createAlgorithm( 'CP::TauEfficiencyCorrectionsAlg',
491 'TauEfficiencyCorrectionsAlgEvetoFakeTau' )
492 config.addPrivateTool( 'efficiencyCorrectionsTool',
493 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
494 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [10]
495
496 alg.efficiencyCorrectionsTool.EleIDLevel = 2
497
498 if self.manual_sel_evetowp == "medium":
499 alg.efficiencyCorrectionsTool.EleIDLevel = 3
500
501 alg.efficiencyCorrectionsTool.useFastSim = config.dataType() is DataType.FastSim
502 alg.efficiencyCorrectionsTool.Campaign = campaign
503 alg.efficiencyCorrectionsTool.useGNTau = self.useGNTau
504 alg.scaleFactorDecoration = 'tau_EvetoFakeTau_effSF' + selectionPostfix + '_%SYS%'
505
506
507 jetIDLevels = (
508 {"Loose": 11, "Medium": 12, "Tight": 13}
509 if self.useGNTau
510 else {"Loose": 7, "Medium": 8, "Tight": 9}
511 )
512 wp = self.quality
513 if not self.useGNTau and self.manual_sel_rnnwp is not None:
514 wp = self.manual_sel_rnnwp.capitalize()
515 if wp not in jetIDLevels:
516 raise ValueError(
517 'Invalid tauID: "'
518 + str(wp)
519 + '". Allowed values are Loose, Medium, Tight'
520 )
521 if wp == "Tight":
522 log.warning(
523 "eVeto SFs are not available for Tight WP -> fallback to Medium WP"
524 )
525 wp = "Medium"
526
527 alg.efficiencyCorrectionsTool.JetIDLevel = jetIDLevels[wp]
528 alg.outOfValidity = 2
529 alg.outOfValidityDeco = 'bad_EvetoFakeTau_eff' + selectionPostfix
530 alg.taus = config.readName (self.containerName)
531 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
532 if self.saveDetailedSF:
533 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
534 'EvetoFakeTau_effSF' + postfix)
535 sfList += [alg.scaleFactorDecoration]
536
537
538 alg = config.createAlgorithm( 'CP::TauEfficiencyCorrectionsAlg',
539 'TauEfficiencyCorrectionsAlgEvetoTrueTau' )
540 config.addPrivateTool( 'efficiencyCorrectionsTool',
541 'TauAnalysisTools::TauEfficiencyCorrectionsTool' )
542 alg.efficiencyCorrectionsTool.EfficiencyCorrectionTypes = [8]
543 alg.efficiencyCorrectionsTool.useFastSim = config.dataType() is DataType.FastSim
544 alg.efficiencyCorrectionsTool.Campaign = "mc23" if config.geometry() is LHCPeriod.Run3 else "mc20"
545 alg.scaleFactorDecoration = 'tau_EvetoTrueTau_effSF' + selectionPostfix + '_%SYS%'
546
547 alg.efficiencyCorrectionsTool.EleIDLevel = 2
548
549 if self.manual_sel_evetowp == "medium":
550 alg.efficiencyCorrectionsTool.EleIDLevel = 3
551 alg.outOfValidity = 2
552 alg.outOfValidityDeco = 'bad_EvetoTrueTau_eff' + selectionPostfix
553 alg.taus = config.readName (self.containerName)
554 alg.preselection = config.getPreselection (self.containerName, self.selectionName)
555 if self.saveDetailedSF:
556 config.addOutputVar (self.containerName, alg.scaleFactorDecoration,
557 'EvetoTrueTau_effSF' + postfix)
558 sfList += [alg.scaleFactorDecoration]
559
560 if self.saveCombinedSF:
561 alg = config.createAlgorithm( 'CP::AsgObjectScaleFactorAlg',
562 'TauCombinedEfficiencyScaleFactorAlg' )
563 alg.particles = config.readName (self.containerName)
564 alg.inScaleFactors = sfList
565 alg.outScaleFactor = 'effSF' + postfix + '_%SYS%'
566 config.addOutputVar (self.containerName, alg.outScaleFactor,
567 'effSF' + postfix)
568
569