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

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.__init__ ( self)

Definition at line 913 of file ElectronAnalysisConfig.py.

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

Member Function Documentation

◆ instanceName()

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

Definition at line 941 of file ElectronAnalysisConfig.py.

941 def instanceName (self) :
942 """Return the instance name for this block"""
943 return self.containerName
944

◆ makeAlgs()

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

Definition at line 945 of file ElectronAnalysisConfig.py.

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

◆ includeAllYearsPerRun

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.includeAllYearsPerRun

Definition at line 984 of file ElectronAnalysisConfig.py.

◆ saveEff

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.saveEff

Definition at line 1045 of file ElectronAnalysisConfig.py.

◆ useToolKeyAsOutput

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.useToolKeyAsOutput

Definition at line 950 of file ElectronAnalysisConfig.py.


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