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

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.__init__ ( self)

Definition at line 857 of file ElectronAnalysisConfig.py.

857 def __init__ (self) :
858 super (ElectronTriggerAnalysisSFBlock, self).__init__ ()
859 self.addDependency('EventSelection', required=False)
860 self.addDependency('EventSelectionMerger', required=False)
861 self.addOption ('triggerChainsPerYear', {}, type=dict,
862 info="a dictionary with key (string) the year and value (list of "
863 "strings) the trigger chains.")
864 self.addOption ('electronID', '', type=str,
865 info="the electron ID WP to use.")
866 self.addOption ('electronIsol', '', type=str,
867 info="the electron isolation WP to use.")
868 self.addOption ('saveEff', False, type=bool,
869 info="define whether we decorate also the trigger scale efficiency.")
870 self.addOption ('prefixSF', 'trigEffSF', type=str,
871 info="the decoration prefix for trigger scale factors.")
872 self.addOption ('prefixEff', 'trigEff', type=str,
873 info="the decoration prefix for MC trigger efficiencies.")
874 self.addOption ('includeAllYearsPerRun', False, type=bool,
875 info="all configured years in the LHC run will "
876 "be included in all jobs.")
877 self.addOption ('removeHLTPrefix', True, type=bool,
878 info="remove the HLT prefix from trigger chain names.")
879 self.addOption ('useToolKeyAsOutput', False, type=bool,
880 info="use the tool trigger key as output.")
881 self.addOption ('containerName', '', type=str,
882 info="the input electron container, with a possible selection, in "
883 "the format `container` or `container.selection`.")
884

Member Function Documentation

◆ instanceName()

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

Definition at line 885 of file ElectronAnalysisConfig.py.

885 def instanceName (self) :
886 """Return the instance name for this block"""
887 return self.containerName
888

◆ makeAlgs()

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

Definition at line 889 of file ElectronAnalysisConfig.py.

889 def makeAlgs (self, config) :
890
891 if config.dataType() is not DataType.Data:
892 log = logging.getLogger('ElectronTriggerSFConfig')
893
894 if self.includeAllYearsPerRun and not self.useToolKeyAsOutput:
895 log.warning('`includeAllYearsPerRun` is set to True, but `useToolKeyAsOutput` is set to False. '
896 'This will cause multiple branches to be written out with the same content.')
897
898 # Dictionary from TrigGlobalEfficiencyCorrection/Triggers.cfg
899 # Key is trigger chain (w/o HLT prefix)
900 # Value is empty for single leg trigger or list of legs
901 triggerDict = TriggerDict()
902
903 # currently recommended versions
904 version_Run2 = "2015_2025/rel22.2/2025_Run2Rel22_Recommendation_v3"
905 map_Run2 = f"ElectronEfficiencyCorrection/{version_Run2}/map1.txt"
906 version_Run3 = "2015_2025/rel22.2/2025_Run3_Consolidated_Recommendation_v4"
907 map_Run3 = f"ElectronEfficiencyCorrection/{version_Run3}/map2.txt"
908
909 version = version_Run2 if config.geometry() is LHCPeriod.Run2 else version_Run3
910 # Dictionary from TrigGlobalEfficiencyCorrection/MapKeys.cfg
911 # Key is year_leg
912 # Value is list of configs available, first one will be used
913 mapKeysDict = MapKeysDict(version)
914
915 # helper function for leg filtering, very hardcoded but allows autoconfiguration
916 def filterConfFromMap(conf, electronMapKeys):
917 if not conf:
918 raise ValueError("No configuration found for trigger chain.")
919 if len(conf) == 1:
920 return conf[0]
921
922 for c in conf:
923 if c in electronMapKeys:
924 return c
925
926 return conf[0]
927
928 if self.includeAllYearsPerRun:
929 years = [int(year) for year in self.triggerChainsPerYear.keys()]
930 else:
931 from TriggerAnalysisAlgorithms.TriggerAnalysisSFConfig import (
932 get_input_years)
933 years = get_input_years(config)
934
935 # prepare keys
936 import ROOT
937 triggerChainsPerYear_Run2 = {}
938 triggerChainsPerYear_Run3 = {}
939 for year, chains in self.triggerChainsPerYear.items():
940 if not chains:
941 log.warning("No trigger chains configured for year %s. "
942 "Assuming this is intended, no Electron trigger SF will be computed.", year)
943 continue
944
945 chains_split = [chain.replace("HLT_", "").replace(" || ", "_OR_") for chain in chains]
946 if int(year) >= 2022:
947 triggerChainsPerYear_Run3[str(year)] = ' || '.join(chains_split)
948 else:
949 triggerChainsPerYear_Run2[str(year)] = ' || '.join(chains_split)
950 electronMapKeys_Run2 = ROOT.std.map("string", "string")()
951 electronMapKeys_Run3 = ROOT.std.map("string", "string")()
952
953 sc_Run2 = ROOT.TrigGlobalEfficiencyCorrectionTool.suggestElectronMapKeys(triggerChainsPerYear_Run2, version_Run2, electronMapKeys_Run2)
954 sc_Run3 = ROOT.TrigGlobalEfficiencyCorrectionTool.suggestElectronMapKeys(triggerChainsPerYear_Run3, version_Run3, electronMapKeys_Run3)
955 if sc_Run2.code() != 2 or sc_Run3.code() != 2:
956 raise RuntimeError("Failed to suggest electron map keys")
957 electronMapKeys = dict(electronMapKeys_Run2) | dict(electronMapKeys_Run3)
958
959 # collect configurations
960 from TriggerAnalysisAlgorithms.TriggerAnalysisConfig import is_year_in_current_period
961 triggerConfigs = {}
962 for year in years:
963 if not is_year_in_current_period(config, year):
964 continue
965
966 triggerChains = self.triggerChainsPerYear.get(int(year), self.triggerChainsPerYear.get(str(year), []))
967 for chain in triggerChains:
968 chain = chain.replace(" || ", "_OR_")
969 chain_noHLT = chain.replace("HLT_", "")
970 chain_out = chain_noHLT if self.removeHLTPrefix else chain
971 legs = triggerDict[chain_noHLT]
972 if not legs:
973 if chain_noHLT[0] == 'e' and chain_noHLT[1].isdigit:
974 chain_key = f"{year}_{chain_noHLT}"
975 chain_conf = mapKeysDict[chain_key][0]
976 triggerConfigs[chain_conf if self.useToolKeyAsOutput else chain_out] = chain_conf
977 else:
978 for leg in legs:
979 if leg[0] == 'e' and leg[1].isdigit:
980 leg_out = leg if self.removeHLTPrefix else f"HLT_{leg}"
981 leg_key = f"{year}_{leg}"
982 leg_conf = filterConfFromMap(mapKeysDict[leg_key], electronMapKeys)
983 triggerConfigs[leg_conf if self.useToolKeyAsOutput else leg_out] = leg_conf
984
985 decorations = [self.prefixSF]
986 if self.saveEff:
987 decorations += [self.prefixEff]
988
989 for label, conf in triggerConfigs.items():
990 for deco in decorations:
991 alg = config.createAlgorithm('CP::ElectronEfficiencyCorrectionAlg',
992 'EleTrigEfficiencyCorrectionsAlg' + deco +
993 '_' + label)
994 config.addPrivateTool( 'efficiencyCorrectionTool',
995 'AsgElectronEfficiencyCorrectionTool' )
996
997 # Reproduce config from TrigGlobalEfficiencyAlg
998 alg.efficiencyCorrectionTool.MapFilePath = map_Run3 if config.geometry() is LHCPeriod.Run3 else map_Run2
999 alg.efficiencyCorrectionTool.IdKey = self.electronID.replace("LH","")
1000 alg.efficiencyCorrectionTool.IsoKey = self.electronIsol
1001 alg.efficiencyCorrectionTool.TriggerKey = (
1002 ("Eff_" if deco == self.prefixEff else "") + conf)
1003 alg.efficiencyCorrectionTool.CorrelationModel = "TOTAL"
1004 alg.efficiencyCorrectionTool.ForceDataType = \
1005 PATCore.ParticleDataType.Full
1006
1007 alg.scaleFactorDecoration = f"el_{deco}_{label}_%SYS%"
1008
1009 alg.outOfValidity = 2 #silent
1010 alg.outOfValidityDeco = f"bad_eff_ele{deco}_{label}"
1011 alg.electrons = config.readName (self.containerName)
1012 alg.preselection = config.getPreselection (self.containerName, "")
1013 config.addOutputVar (self.containerName, alg.scaleFactorDecoration, f"{deco}_{label}")
1014
1015
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 1013 of file ElectronAnalysisConfig.py.

◆ includeAllYearsPerRun

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.includeAllYearsPerRun

Definition at line 928 of file ElectronAnalysisConfig.py.

◆ saveEff

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.saveEff

Definition at line 986 of file ElectronAnalysisConfig.py.

◆ useToolKeyAsOutput

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.useToolKeyAsOutput

Definition at line 894 of file ElectronAnalysisConfig.py.


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