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 938 of file ElectronAnalysisConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.__init__ ( self)

Definition at line 940 of file ElectronAnalysisConfig.py.

940 def __init__ (self) :
941 super (ElectronTriggerAnalysisSFBlock, self).__init__ ()
942 self.addDependency('EventSelection', required=False)
943 self.addDependency('EventSelectionMerger', required=False)
944 self.addOption ('triggerChainsPerYear', {}, type=dict,
945 info="a dictionary with key (string) the year and value (list of "
946 "strings) the trigger chains.")
947 self.addOption ('electronID', '', type=str,
948 info="the electron ID WP to use.")
949 self.addOption ('electronIsol', '', type=str,
950 info="the electron isolation WP to use.")
951 self.addOption ('saveEff', False, type=bool,
952 info="define whether we decorate also the trigger scale efficiency.")
953 self.addOption ('prefixSF', 'trigEffSF', type=str,
954 info="the decoration prefix for trigger scale factors.")
955 self.addOption ('prefixEff', 'trigEff', type=str,
956 info="the decoration prefix for MC trigger efficiencies.")
957 self.addOption ('includeAllYearsPerRun', False, type=bool,
958 info="all configured years in the LHC run will "
959 "be included in all jobs.")
960 self.addOption ('removeHLTPrefix', True, type=bool,
961 info="remove the HLT prefix from trigger chain names.")
962 self.addOption ('useToolKeyAsOutput', False, type=bool,
963 info="use the tool trigger key as output.")
964 self.addOption ('containerName', '', type=str,
965 info="the input electron container, with a possible selection, in "
966 "the format `container` or `container.selection`.",
967 meta={'role':'containerRef'})
968

Member Function Documentation

◆ instanceName()

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

Definition at line 969 of file ElectronAnalysisConfig.py.

969 def instanceName (self) :
970 """Return the instance name for this block"""
971 return self.containerName
972

◆ makeAlgs()

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

Definition at line 973 of file ElectronAnalysisConfig.py.

973 def makeAlgs (self, config) :
974
975 if config.dataType() is not DataType.Data:
976 log = logging.getLogger('ElectronTriggerSFConfig')
977
978 if self.includeAllYearsPerRun and not self.useToolKeyAsOutput:
979 log.warning('`includeAllYearsPerRun` is set to True, but `useToolKeyAsOutput` is set to False. '
980 'This will cause multiple branches to be written out with the same content.')
981
982 # Dictionary from TrigGlobalEfficiencyCorrection/Triggers.cfg
983 # Key is trigger chain (w/o HLT prefix)
984 # Value is empty for single leg trigger or list of legs
985 triggerDict = TriggerDict()
986
987 # currently recommended versions
988 version_Run2 = "2015_2025/rel22.2/2025_Run2Rel22_Recommendation_v3"
989 map_Run2 = f"ElectronEfficiencyCorrection/{version_Run2}/map1.txt"
990 version_Run3 = "2015_2025/rel22.2/2025_Run3_Consolidated_Recommendation_v4"
991 map_Run3 = f"ElectronEfficiencyCorrection/{version_Run3}/map2.txt"
992
993 version = version_Run2 if config.geometry() is LHCPeriod.Run2 else version_Run3
994 # Dictionary from TrigGlobalEfficiencyCorrection/MapKeys.cfg
995 # Key is year_leg
996 # Value is list of configs available, first one will be used
997 mapKeysDict = MapKeysDict(version)
998
999 # helper function for leg filtering, very hardcoded but allows autoconfiguration
1000 def filterConfFromMap(conf, electronMapKeys):
1001 if not conf:
1002 raise ValueError("No configuration found for trigger chain.")
1003 if len(conf) == 1:
1004 return conf[0]
1005
1006 for c in conf:
1007 if c in electronMapKeys:
1008 return c
1009
1010 return conf[0]
1011
1012 if self.includeAllYearsPerRun:
1013 years = [int(year) for year in self.triggerChainsPerYear.keys()]
1014 else:
1015 from TriggerAnalysisAlgorithms.TriggerAnalysisSFConfig import (
1016 get_input_years)
1017 years = get_input_years(config)
1018
1019 # prepare keys
1020 import ROOT
1021 triggerChainsPerYear_Run2 = {}
1022 triggerChainsPerYear_Run3 = {}
1023 for year, chains in self.triggerChainsPerYear.items():
1024 if not chains:
1025 warnings.warn_explicit(
1026 f"No trigger chains configured for year {year}."
1027 " Assuming this is intended, no Electron trigger SF"
1028 " will be computed.",
1029 TriggerSFWarning, filename='', lineno=0)
1030 continue
1031
1032 chains_split = [chain.replace("HLT_", "").replace(" || ", "_OR_") for chain in chains]
1033 if int(year) >= 2022:
1034 triggerChainsPerYear_Run3[str(year)] = ' || '.join(chains_split)
1035 else:
1036 triggerChainsPerYear_Run2[str(year)] = ' || '.join(chains_split)
1037 electronMapKeys_Run2 = ROOT.std.map("string", "string")()
1038 electronMapKeys_Run3 = ROOT.std.map("string", "string")()
1039
1040 sc_Run2 = ROOT.TrigGlobalEfficiencyCorrectionTool.suggestElectronMapKeys(triggerChainsPerYear_Run2, version_Run2, electronMapKeys_Run2)
1041 sc_Run3 = ROOT.TrigGlobalEfficiencyCorrectionTool.suggestElectronMapKeys(triggerChainsPerYear_Run3, version_Run3, electronMapKeys_Run3)
1042 if sc_Run2.code() != 2 or sc_Run3.code() != 2:
1043 raise RuntimeError("Failed to suggest electron map keys")
1044 electronMapKeys = dict(electronMapKeys_Run2) | dict(electronMapKeys_Run3)
1045
1046 # collect configurations
1047 from TriggerAnalysisAlgorithms.TriggerAnalysisConfig import is_year_in_current_period
1048 triggerConfigs = {}
1049 for year in years:
1050 if not is_year_in_current_period(config, year):
1051 continue
1052
1053 triggerChains = self.triggerChainsPerYear.get(int(year), self.triggerChainsPerYear.get(str(year), []))
1054 for chain in triggerChains:
1055 chain = chain.replace(" || ", "_OR_")
1056 chain_noHLT = chain.replace("HLT_", "")
1057 chain_out = chain_noHLT if self.removeHLTPrefix else chain
1058 legs = triggerDict[chain_noHLT]
1059 if not legs:
1060 if chain_noHLT[0] == 'e' and chain_noHLT[1].isdigit:
1061 chain_key = f"{year}_{chain_noHLT}"
1062 chain_conf = mapKeysDict[chain_key][0]
1063 triggerConfigs[chain_conf if self.useToolKeyAsOutput else chain_out] = chain_conf
1064 else:
1065 for leg in legs:
1066 if leg[0] == 'e' and leg[1].isdigit:
1067 leg_out = leg if self.removeHLTPrefix else f"HLT_{leg}"
1068 leg_key = f"{year}_{leg}"
1069 leg_conf = filterConfFromMap(mapKeysDict[leg_key], electronMapKeys)
1070 triggerConfigs[leg_conf if self.useToolKeyAsOutput else leg_out] = leg_conf
1071
1072 decorations = [self.prefixSF]
1073 if self.saveEff:
1074 decorations += [self.prefixEff]
1075
1076 for label, conf in triggerConfigs.items():
1077 for deco in decorations:
1078 alg = config.createAlgorithm('CP::ElectronEfficiencyCorrectionAlg',
1079 'EleTrigEfficiencyCorrectionsAlg' + deco +
1080 '_' + label)
1081 config.addPrivateTool( 'efficiencyCorrectionTool',
1082 'AsgElectronEfficiencyCorrectionTool' )
1083
1084 # Reproduce config from TrigGlobalEfficiencyAlg
1085 alg.efficiencyCorrectionTool.MapFilePath = map_Run3 if config.geometry() is LHCPeriod.Run3 else map_Run2
1086 alg.efficiencyCorrectionTool.IdKey = self.electronID.replace("LH","")
1087 alg.efficiencyCorrectionTool.IsoKey = self.electronIsol
1088 alg.efficiencyCorrectionTool.TriggerKey = (
1089 ("Eff_" if deco == self.prefixEff else "") + conf)
1090 alg.efficiencyCorrectionTool.CorrelationModel = "TOTAL"
1091 alg.efficiencyCorrectionTool.ForceDataType = \
1092 PATCore.ParticleDataType.Full
1093
1094 alg.scaleFactorDecoration = f"el_{deco}_{label}_%SYS%"
1095
1096 alg.outOfValidity = 2 #silent
1097 alg.outOfValidityDeco = f"bad_eff_ele{deco}_{label}"
1098 alg.electrons = config.readName (self.containerName)
1099 alg.preselection = config.getPreselection (self.containerName, "")
1100 config.addOutputVar (self.containerName, alg.scaleFactorDecoration, f"{deco}_{label}")
1101
1102
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 1100 of file ElectronAnalysisConfig.py.

◆ includeAllYearsPerRun

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.includeAllYearsPerRun

Definition at line 1012 of file ElectronAnalysisConfig.py.

◆ saveEff

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.saveEff

Definition at line 1073 of file ElectronAnalysisConfig.py.

◆ useToolKeyAsOutput

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.useToolKeyAsOutput

Definition at line 978 of file ElectronAnalysisConfig.py.


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