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

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.__init__ ( self)

Definition at line 899 of file ElectronAnalysisConfig.py.

899 def __init__ (self) :
900 super (ElectronTriggerAnalysisSFBlock, self).__init__ ()
901 self.addDependency('EventSelection', required=False)
902 self.addDependency('EventSelectionMerger', required=False)
903 self.addOption ('triggerChainsPerYear', {}, type=dict,
904 info="a dictionary with key (string) the year and value (list of "
905 "strings) the trigger chains.")
906 self.addOption ('electronID', '', type=str,
907 info="the electron ID WP to use.")
908 self.addOption ('electronIsol', '', type=str,
909 info="the electron isolation WP to use.")
910 self.addOption ('saveEff', False, type=bool,
911 info="define whether we decorate also the trigger scale efficiency.")
912 self.addOption ('prefixSF', 'trigEffSF', type=str,
913 info="the decoration prefix for trigger scale factors.")
914 self.addOption ('prefixEff', 'trigEff', type=str,
915 info="the decoration prefix for MC trigger efficiencies.")
916 self.addOption ('includeAllYearsPerRun', False, type=bool,
917 info="all configured years in the LHC run will "
918 "be included in all jobs.")
919 self.addOption ('removeHLTPrefix', True, type=bool,
920 info="remove the HLT prefix from trigger chain names.")
921 self.addOption ('useToolKeyAsOutput', False, type=bool,
922 info="use the tool trigger key as output.")
923 self.addOption ('containerName', '', type=str,
924 info="the input electron container, with a possible selection, in "
925 "the format `container` or `container.selection`.")
926

Member Function Documentation

◆ instanceName()

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

Definition at line 927 of file ElectronAnalysisConfig.py.

927 def instanceName (self) :
928 """Return the instance name for this block"""
929 return self.containerName
930

◆ makeAlgs()

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

Definition at line 931 of file ElectronAnalysisConfig.py.

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

Member Data Documentation

◆ containerName

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.containerName

Definition at line 1055 of file ElectronAnalysisConfig.py.

◆ includeAllYearsPerRun

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.includeAllYearsPerRun

Definition at line 970 of file ElectronAnalysisConfig.py.

◆ saveEff

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.saveEff

Definition at line 1028 of file ElectronAnalysisConfig.py.

◆ useToolKeyAsOutput

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.useToolKeyAsOutput

Definition at line 936 of file ElectronAnalysisConfig.py.


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