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

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.__init__ ( self)

Definition at line 955 of file ElectronAnalysisConfig.py.

955 def __init__ (self) :
956 super (ElectronTriggerAnalysisSFBlock, self).__init__ ()
957 self.addDependency('EventSelection', required=False)
958 self.addDependency('EventSelectionMerger', required=False)
959 self.addOption ('triggerChainsPerYear', {}, type=dict,
960 info="a dictionary with key (string) the year and value (list of "
961 "strings) the trigger chains.")
962 self.addOption ('electronID', '', type=str,
963 info="the electron ID WP to use.")
964 self.addOption ('electronIsol', '', type=str,
965 info="the electron isolation WP to use.")
966 self.addOption ('saveEff', False, type=bool,
967 info="define whether we decorate also the trigger scale efficiency.")
968 self.addOption ('prefixSF', 'trigEffSF', type=str,
969 info="the decoration prefix for trigger scale factors.")
970 self.addOption ('prefixEff', 'trigEff', type=str,
971 info="the decoration prefix for MC trigger efficiencies.")
972 self.addOption ('includeAllYearsPerRun', False, type=bool,
973 info="all configured years in the LHC run will "
974 "be included in all jobs.")
975 self.addOption ('removeHLTPrefix', True, type=bool,
976 info="remove the HLT prefix from trigger chain names.")
977 self.addOption ('useToolKeyAsOutput', False, type=bool,
978 info="use the tool trigger key as output.")
979 self.addOption ('containerName', '', type=str,
980 info="the input electron container, with a possible selection, in "
981 "the format `container` or `container.selection`.",
982 meta={'role':'containerRef'})
983

Member Function Documentation

◆ instanceName()

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

Definition at line 984 of file ElectronAnalysisConfig.py.

984 def instanceName (self) :
985 """Return the instance name for this block"""
986 return self.containerName
987

◆ makeAlgs()

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

Definition at line 988 of file ElectronAnalysisConfig.py.

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

◆ includeAllYearsPerRun

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.includeAllYearsPerRun

Definition at line 1027 of file ElectronAnalysisConfig.py.

◆ saveEff

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.saveEff

Definition at line 1088 of file ElectronAnalysisConfig.py.

◆ useToolKeyAsOutput

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.useToolKeyAsOutput

Definition at line 993 of file ElectronAnalysisConfig.py.


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