ATLAS Offline Software
Loading...
Searching...
No Matches
python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock Class Reference
Inheritance diagram for python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock:
Collaboration diagram for python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock:

Public Member Functions

 __init__ (self)
 instanceName (self)
 makeAlgs (self, config)

Public Attributes

 useToolKeyAsOutput
 includeAllYearsPerRun
 saveEff
 containerName

Detailed Description

Definition at line 974 of file ElectronAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.__init__ ( self)

Definition at line 976 of file ElectronAnalysisConfig.py.

976 def __init__ (self) :
977 super (ElectronTriggerAnalysisSFBlock, self).__init__ ()
978 self.addDependency('EventSelection', required=False)
979 self.addDependency('EventSelectionMerger', required=False)
980 self.addOption ('triggerChainsPerYear', {}, type=dict,
981 info="a dictionary with key (string) the year and value (list of "
982 "strings) the trigger chains.")
983 self.addOption ('electronID', '', type=str,
984 info="the electron ID WP to use.")
985 self.addOption ('electronIsol', '', type=str,
986 info="the electron isolation WP to use.")
987 self.addOption ('saveEff', False, type=bool,
988 info="define whether we decorate also the trigger scale efficiency.")
989 self.addOption ('prefixSF', 'trigEffSF', type=str,
990 info="the decoration prefix for trigger scale factors.")
991 self.addOption ('prefixEff', 'trigEff', type=str,
992 info="the decoration prefix for MC trigger efficiencies.")
993 self.addOption ('includeAllYearsPerRun', False, type=bool,
994 info="all configured years in the LHC run will "
995 "be included in all jobs.")
996 self.addOption ('removeHLTPrefix', True, type=bool,
997 info="remove the HLT prefix from trigger chain names.")
998 self.addOption ('useToolKeyAsOutput', False, type=bool,
999 info="use the tool trigger key as output.")
1000 self.addOption ('containerName', '', type=str,
1001 info="the input electron container, with a possible selection, in "
1002 "the format `container` or `container.selection`.",
1003 meta={'role':'containerRef'})
1004

Member Function Documentation

◆ instanceName()

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.instanceName ( self)
Return the instance name for this block

Definition at line 1005 of file ElectronAnalysisConfig.py.

1005 def instanceName (self) :
1006 """Return the instance name for this block"""
1007 return self.containerName
1008

◆ makeAlgs()

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.makeAlgs ( self,
config )

Definition at line 1009 of file ElectronAnalysisConfig.py.

1009 def makeAlgs (self, config) :
1010
1011 if config.dataType() is not DataType.Data:
1012 log = logging.getLogger('ElectronTriggerSFConfig')
1013
1014 if self.includeAllYearsPerRun and not self.useToolKeyAsOutput:
1015 log.warning('`includeAllYearsPerRun` is set to True, but `useToolKeyAsOutput` is set to False. '
1016 'This will cause multiple branches to be written out with the same content.')
1017
1018 # Dictionary from TrigGlobalEfficiencyCorrection/Triggers.cfg
1019 # Key is trigger chain (w/o HLT prefix)
1020 # Value is empty for single leg trigger or list of legs
1021 triggerDict = TriggerDict()
1022
1023 # currently recommended versions
1024 version_Run2 = "2015_2025/rel22.2/2025_Run2Rel22_Recommendation_v3"
1025 map_Run2 = f"ElectronEfficiencyCorrection/{version_Run2}/map1.txt"
1026 version_Run3 = "2015_2025/rel22.2/2026_Run3_Consolidated_Trigger_Recommendation_v1"
1027 map_Run3 = f"ElectronEfficiencyCorrection/{version_Run3}/map1.txt"
1028
1029 version = version_Run2 if config.geometry() is LHCPeriod.Run2 else version_Run3
1030 # Dictionary from TrigGlobalEfficiencyCorrection/MapKeys.cfg
1031 # Key is year_leg
1032 # Value is list of configs available, first one will be used
1033 mapKeysDict = MapKeysDict(version)
1034
1035 # helper function for leg filtering, very hardcoded but allows autoconfiguration
1036 def filterConfFromMap(conf, electronMapKeys):
1037 if not conf:
1038 raise ValueError("No configuration found for trigger chain.")
1039 if len(conf) == 1:
1040 return conf[0]
1041
1042 for c in conf:
1043 if c in electronMapKeys:
1044 return c
1045
1046 return conf[0]
1047
1048 if self.includeAllYearsPerRun:
1049 years = [int(year) for year in self.triggerChainsPerYear.keys()]
1050 else:
1051 from TriggerAnalysisAlgorithms.TriggerAnalysisSFConfig import (
1052 get_input_years)
1053 years = get_input_years(config)
1054
1055 # prepare keys
1056 import ROOT
1057 triggerChainsPerYear_Run2 = {}
1058 triggerChainsPerYear_Run3 = {}
1059 for year, chains in self.triggerChainsPerYear.items():
1060 if not chains:
1061 warnings.warn_explicit(
1062 f"No trigger chains configured for year {year}."
1063 " Assuming this is intended, no Electron trigger SF"
1064 " will be computed.",
1065 TriggerSFWarning, filename='', lineno=0)
1066 continue
1067
1068 chains_split = [chain.replace("HLT_", "").replace(" || ", "_OR_") for chain in chains]
1069 if int(year) >= 2022:
1070 triggerChainsPerYear_Run3[str(year)] = ' || '.join(chains_split)
1071 else:
1072 triggerChainsPerYear_Run2[str(year)] = ' || '.join(chains_split)
1073 electronMapKeys_Run2 = ROOT.std.map("string", "string")()
1074 electronMapKeys_Run3 = ROOT.std.map("string", "string")()
1075
1076 sc_Run2 = ROOT.TrigGlobalEfficiencyCorrectionTool.suggestElectronMapKeys(triggerChainsPerYear_Run2, version_Run2, electronMapKeys_Run2)
1077 sc_Run3 = ROOT.TrigGlobalEfficiencyCorrectionTool.suggestElectronMapKeys(triggerChainsPerYear_Run3, version_Run3, electronMapKeys_Run3)
1078 if sc_Run2.code() != 2 or sc_Run3.code() != 2:
1079 raise RuntimeError("Failed to suggest electron map keys")
1080 electronMapKeys = dict(electronMapKeys_Run2) | dict(electronMapKeys_Run3)
1081
1082 # collect configurations
1083 from TriggerAnalysisAlgorithms.TriggerAnalysisConfig import is_year_in_current_period
1084 triggerConfigs = {}
1085 for year in years:
1086 if not is_year_in_current_period(config, year):
1087 continue
1088
1089 triggerChains = self.triggerChainsPerYear.get(int(year), self.triggerChainsPerYear.get(str(year), []))
1090 for chain in triggerChains:
1091 chain = chain.replace(" || ", "_OR_")
1092 chain_noHLT = chain.replace("HLT_", "")
1093 chain_out = chain_noHLT if self.removeHLTPrefix else chain
1094 legs = triggerDict[chain_noHLT]
1095 if not legs:
1096 if chain_noHLT[0] == 'e' and chain_noHLT[1].isdigit():
1097 chain_key = f"{year}_{chain_noHLT}"
1098 chain_conf = mapKeysDict[chain_key][0]
1099 triggerConfigs[chain_conf if self.useToolKeyAsOutput else chain_out] = chain_conf
1100 else:
1101 for leg in legs:
1102 if leg[0] == 'e' and leg[1].isdigit():
1103 leg_out = leg if self.removeHLTPrefix else f"HLT_{leg}"
1104 leg_key = f"{year}_{leg}"
1105 leg_conf = filterConfFromMap(mapKeysDict[leg_key], electronMapKeys)
1106 triggerConfigs[leg_conf if self.useToolKeyAsOutput else leg_out] = leg_conf
1107
1108 decorations = [self.prefixSF]
1109 if self.saveEff:
1110 decorations += [self.prefixEff]
1111
1112 for label, conf in triggerConfigs.items():
1113 for deco in decorations:
1114 alg = config.createAlgorithm('CP::ElectronEfficiencyCorrectionAlg',
1115 'EleTrigEfficiencyCorrectionsAlg' + deco +
1116 '_' + label)
1117 config.addPrivateTool( 'efficiencyCorrectionTool',
1118 'CP::AsgElectronEfficiencyCorrectionTool' )
1119
1120 # Reproduce config from TrigGlobalEfficiencyAlg
1121 alg.efficiencyCorrectionTool.MapFilePath = map_Run3 if config.geometry() is LHCPeriod.Run3 else map_Run2
1122 alg.efficiencyCorrectionTool.IdKey = self.electronID.replace("LH","") if config.geometry() is LHCPeriod.Run2 else self.electronID
1123 alg.efficiencyCorrectionTool.IsoKey = self.electronIsol
1124 alg.efficiencyCorrectionTool.TriggerKey = (
1125 ("Eff_" if deco == self.prefixEff else "") + conf)
1126 alg.efficiencyCorrectionTool.CorrelationModel = "TOTAL"
1127 alg.efficiencyCorrectionTool.ForceDataType = \
1128 PATCore.ParticleDataType.Full
1129
1130 alg.scaleFactorDecoration = f"el_{deco}_{label}_%SYS%"
1131
1132 alg.outOfValidity = 2 #silent
1133 alg.outOfValidityDeco = f"bad_eff_ele{deco}_{label}"
1134 alg.electrons = config.readName (self.containerName)
1135 alg.preselection = config.getPreselection (self.containerName, "")
1136 config.addOutputVar (self.containerName, alg.scaleFactorDecoration, f"{deco}_{label}", auxType='float')
1137
1138
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:312
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:132

Member Data Documentation

◆ containerName

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.containerName

Definition at line 1136 of file ElectronAnalysisConfig.py.

◆ includeAllYearsPerRun

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.includeAllYearsPerRun

Definition at line 1048 of file ElectronAnalysisConfig.py.

◆ saveEff

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.saveEff

Definition at line 1109 of file ElectronAnalysisConfig.py.

◆ useToolKeyAsOutput

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.useToolKeyAsOutput

Definition at line 1014 of file ElectronAnalysisConfig.py.


The documentation for this class was generated from the following file: