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

Constructor & Destructor Documentation

◆ __init__()

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.__init__ ( self)

Definition at line 794 of file ElectronAnalysisConfig.py.

794 def __init__ (self) :
795 super (ElectronTriggerAnalysisSFBlock, self).__init__ ()
796
797 self.addOption ('triggerChainsPerYear', {}, type=None,
798 info="a dictionary with key (string) the year and value (list of "
799 "strings) the trigger chains. The default is {} (empty dictionary).")
800 self.addOption ('electronID', '', type=str,
801 info="the electron ID WP (string) to use.")
802 self.addOption ('electronIsol', '', type=str,
803 info="the electron isolation WP (string) to use.")
804 self.addOption ('saveEff', False, type=bool,
805 info="define whether we decorate also the trigger scale efficiency "
806 "The default is false.")
807 self.addOption ('prefixSF', 'trigEffSF', type=str,
808 info="the decoration prefix for trigger scale factors, "
809 "the default is 'trigEffSF'")
810 self.addOption ('prefixEff', 'trigEff', type=str,
811 info="the decoration prefix for MC trigger efficiencies, "
812 "the default is 'trigEff'")
813 self.addOption ('includeAllYearsPerRun', False, type=bool,
814 info="if True, all configured years in the LHC run will "
815 "be included in all jobs. The default is False.")
816 self.addOption ('removeHLTPrefix', True, type=bool,
817 info="remove the HLT prefix from trigger chain names, "
818 "The default is True.")
819 self.addOption ('useToolKeyAsOutput', False, type=bool,
820 info="use tool trigger key as output, "
821 "The default is False.")
822 self.addOption ('containerName', '', type=str,
823 info="the input electron container, with a possible selection, in "
824 "the format container or container.selection.")
825

Member Function Documentation

◆ instanceName()

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

Definition at line 826 of file ElectronAnalysisConfig.py.

826 def instanceName (self) :
827 """Return the instance name for this block"""
828 return self.containerName
829

◆ makeAlgs()

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

Definition at line 830 of file ElectronAnalysisConfig.py.

830 def makeAlgs (self, config) :
831
832 if config.dataType() is not DataType.Data:
833 log = logging.getLogger('ElectronTriggerSFConfig')
834
835 if self.includeAllYearsPerRun and not self.useToolKeyAsOutput:
836 log.warning('`includeAllYearsPerRun` is set to True, but `useToolKeyAsOutput` is set to False. '
837 'This will cause multiple branches to be written out with the same content.')
838
839 # Dictionary from TrigGlobalEfficiencyCorrection/Triggers.cfg
840 # Key is trigger chain (w/o HLT prefix)
841 # Value is empty for single leg trigger or list of legs
842 triggerDict = TriggerDict()
843
844 # currently recommended versions
845 version_Run2 = "2015_2025/rel22.2/2025_Run2Rel22_Recommendation_v3"
846 map_Run2 = f"ElectronEfficiencyCorrection/{version_Run2}/map1.txt"
847 version_Run3 = "2015_2025/rel22.2/2025_Run3_Consolidated_Recommendation_v4"
848 map_Run3 = f"ElectronEfficiencyCorrection/{version_Run3}/map2.txt"
849
850 version = version_Run2 if config.geometry() is LHCPeriod.Run2 else version_Run3
851 # Dictionary from TrigGlobalEfficiencyCorrection/MapKeys.cfg
852 # Key is year_leg
853 # Value is list of configs available, first one will be used
854 mapKeysDict = MapKeysDict(version)
855
856 # helper function for leg filtering, very hardcoded but allows autoconfiguration
857 def filterConfFromMap(conf, electronMapKeys):
858 if not conf:
859 raise ValueError("No configuration found for trigger chain.")
860 if len(conf) == 1:
861 return conf[0]
862
863 for c in conf:
864 if c in electronMapKeys:
865 return c
866
867 return conf[0]
868
869 if self.includeAllYearsPerRun:
870 years = [int(year) for year in self.triggerChainsPerYear.keys()]
871 else:
872 from TriggerAnalysisAlgorithms.TriggerAnalysisSFConfig import (
873 get_input_years)
874 years = get_input_years(config)
875
876 # prepare keys
877 import ROOT
878 triggerChainsPerYear_Run2 = {}
879 triggerChainsPerYear_Run3 = {}
880 for year, chains in self.triggerChainsPerYear.items():
881 if not chains:
882 log.warning("No trigger chains configured for year %s. "
883 "Assuming this is intended, no Electron trigger SF will be computed.", year)
884 continue
885
886 chains_split = [chain.replace("HLT_", "").replace(" || ", "_OR_") for chain in chains]
887 if int(year) >= 2022:
888 triggerChainsPerYear_Run3[str(year)] = ' || '.join(chains_split)
889 else:
890 triggerChainsPerYear_Run2[str(year)] = ' || '.join(chains_split)
891 electronMapKeys_Run2 = ROOT.std.map("string", "string")()
892 electronMapKeys_Run3 = ROOT.std.map("string", "string")()
893
894 sc_Run2 = ROOT.TrigGlobalEfficiencyCorrectionTool.suggestElectronMapKeys(triggerChainsPerYear_Run2, version_Run2, electronMapKeys_Run2)
895 sc_Run3 = ROOT.TrigGlobalEfficiencyCorrectionTool.suggestElectronMapKeys(triggerChainsPerYear_Run3, version_Run3, electronMapKeys_Run3)
896 if sc_Run2.code() != 2 or sc_Run3.code() != 2:
897 raise RuntimeError("Failed to suggest electron map keys")
898 electronMapKeys = dict(electronMapKeys_Run2) | dict(electronMapKeys_Run3)
899
900 # collect configurations
901 from TriggerAnalysisAlgorithms.TriggerAnalysisConfig import is_year_in_current_period
902 triggerConfigs = {}
903 for year in years:
904 if not is_year_in_current_period(config, year):
905 continue
906
907 triggerChains = self.triggerChainsPerYear.get(int(year), self.triggerChainsPerYear.get(str(year), []))
908 for chain in triggerChains:
909 chain = chain.replace(" || ", "_OR_")
910 chain_noHLT = chain.replace("HLT_", "")
911 chain_out = chain_noHLT if self.removeHLTPrefix else chain
912 legs = triggerDict[chain_noHLT]
913 if not legs:
914 if chain_noHLT[0] == 'e' and chain_noHLT[1].isdigit:
915 chain_key = f"{year}_{chain_noHLT}"
916 chain_conf = mapKeysDict[chain_key][0]
917 triggerConfigs[chain_conf if self.useToolKeyAsOutput else chain_out] = chain_conf
918 else:
919 for leg in legs:
920 if leg[0] == 'e' and leg[1].isdigit:
921 leg_out = leg if self.removeHLTPrefix else f"HLT_{leg}"
922 leg_key = f"{year}_{leg}"
923 leg_conf = filterConfFromMap(mapKeysDict[leg_key], electronMapKeys)
924 triggerConfigs[leg_conf if self.useToolKeyAsOutput else leg_out] = leg_conf
925
926 decorations = [self.prefixSF]
927 if self.saveEff:
928 decorations += [self.prefixEff]
929
930 for label, conf in triggerConfigs.items():
931 for deco in decorations:
932 alg = config.createAlgorithm('CP::ElectronEfficiencyCorrectionAlg',
933 'EleTrigEfficiencyCorrectionsAlg' + deco +
934 '_' + label)
935 config.addPrivateTool( 'efficiencyCorrectionTool',
936 'AsgElectronEfficiencyCorrectionTool' )
937
938 # Reproduce config from TrigGlobalEfficiencyAlg
939 alg.efficiencyCorrectionTool.MapFilePath = map_Run3 if config.geometry() is LHCPeriod.Run3 else map_Run2
940 alg.efficiencyCorrectionTool.IdKey = self.electronID.replace("LH","")
941 alg.efficiencyCorrectionTool.IsoKey = self.electronIsol
942 alg.efficiencyCorrectionTool.TriggerKey = (
943 ("Eff_" if deco == self.prefixEff else "") + conf)
944 alg.efficiencyCorrectionTool.CorrelationModel = "TOTAL"
945 alg.efficiencyCorrectionTool.ForceDataType = \
946 PATCore.ParticleDataType.Full
947
948 alg.scaleFactorDecoration = f"el_{deco}_{label}_%SYS%"
949
950 alg.outOfValidity = 2 #silent
951 alg.outOfValidityDeco = f"bad_eff_ele{deco}_{label}"
952 alg.electrons = config.readName (self.containerName)
953 alg.preselection = config.getPreselection (self.containerName, "")
954 config.addOutputVar (self.containerName, alg.scaleFactorDecoration, f"{deco}_{label}")
955
956
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 954 of file ElectronAnalysisConfig.py.

◆ includeAllYearsPerRun

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.includeAllYearsPerRun

Definition at line 869 of file ElectronAnalysisConfig.py.

◆ saveEff

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.saveEff

Definition at line 927 of file ElectronAnalysisConfig.py.

◆ useToolKeyAsOutput

python.ElectronAnalysisConfig.ElectronTriggerAnalysisSFBlock.useToolKeyAsOutput

Definition at line 835 of file ElectronAnalysisConfig.py.


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