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

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.__init__ ( self)

Definition at line 918 of file ElectronAnalysisConfig.py.

918 def __init__ (self) :
919 super (ElectronTriggerAnalysisSFBlock, self).__init__ ()
920 self.addDependency('EventSelection', required=False)
921 self.addDependency('EventSelectionMerger', required=False)
922 self.addOption ('triggerChainsPerYear', {}, type=dict,
923 info="a dictionary with key (string) the year and value (list of "
924 "strings) the trigger chains.")
925 self.addOption ('electronID', '', type=str,
926 info="the electron ID WP to use.")
927 self.addOption ('electronIsol', '', type=str,
928 info="the electron isolation WP to use.")
929 self.addOption ('saveEff', False, type=bool,
930 info="define whether we decorate also the trigger scale efficiency.")
931 self.addOption ('prefixSF', 'trigEffSF', type=str,
932 info="the decoration prefix for trigger scale factors.")
933 self.addOption ('prefixEff', 'trigEff', type=str,
934 info="the decoration prefix for MC trigger efficiencies.")
935 self.addOption ('includeAllYearsPerRun', False, type=bool,
936 info="all configured years in the LHC run will "
937 "be included in all jobs.")
938 self.addOption ('removeHLTPrefix', True, type=bool,
939 info="remove the HLT prefix from trigger chain names.")
940 self.addOption ('useToolKeyAsOutput', False, type=bool,
941 info="use the tool trigger key as output.")
942 self.addOption ('containerName', '', type=str,
943 info="the input electron container, with a possible selection, in "
944 "the format `container` or `container.selection`.")
945

Member Function Documentation

◆ instanceName()

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

Definition at line 946 of file ElectronAnalysisConfig.py.

946 def instanceName (self) :
947 """Return the instance name for this block"""
948 return self.containerName
949

◆ makeAlgs()

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

Definition at line 950 of file ElectronAnalysisConfig.py.

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

◆ includeAllYearsPerRun

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.includeAllYearsPerRun

Definition at line 989 of file ElectronAnalysisConfig.py.

◆ saveEff

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.saveEff

Definition at line 1050 of file ElectronAnalysisConfig.py.

◆ useToolKeyAsOutput

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.useToolKeyAsOutput

Definition at line 955 of file ElectronAnalysisConfig.py.


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