3 from AnalysisAlgorithmsConfig.ConfigBlock
import ConfigBlock
4 from AnalysisAlgorithmsConfig.ConfigSequence
import groupBlocks
5 from AnalysisAlgorithmsConfig.ConfigAccumulator
import DataType
6 from AthenaConfiguration.Enums
import LHCPeriod
10 """the ConfigBlock for trigger analysis"""
14 super (TriggerAnalysisBlock, self).__init__ ()
15 self.addOption (
'triggerChainsPerYear', {}, type=
None,
16 info=
"a dictionary with key (string) the year and value (list of "
17 "strings) the trigger chains. You can also use || within a string "
18 "to enforce an OR of triggers without looking up the individual "
19 "triggers. Used for both trigger selection and SFs. "
20 "The default is {} (empty dictionary).")
21 self.addOption (
'multiTriggerChainsPerYear', {}, type=
None,
22 info=
"a dictionary with key (string) a trigger set name and value a "
23 "triggerChainsPerYear dictionary, following the previous convention. "
24 "Relevant for analyses using different triggers in different categories, "
25 "where the trigger global scale factors shouldn't be combined. "
26 "The default is {} (empty dictionary).")
27 self.addOption (
'triggerChainsForSelection', [], type=
None,
28 info=
"a list of trigger chains (list of strings) to be used for "
29 "trigger selection. Only set it if you need a different setup "
30 "than for trigger SFs. The default is [] (empty list).")
31 self.addOption (
'triggerChainsForDecoration', [], type=
None,
32 info=
"a list of trigger chains (list of strings) to be used for "
33 "trigger decoration, if it needs to be different from the selection one. "
34 "The default is [] (empty list).")
35 self.addOption (
'prescaleDecoration',
'prescale', type=str,
36 info=
"name (prefix) of decoration for trigger prescales.")
37 self.addOption (
'prescaleLumiCalcFiles', [], type=
None,
38 info=
"a list of lumical files (list of strings) to calculate "
39 "trigger prescales. The default is [] (empty list). Mutually "
40 "exclusive with prescaleLumiCalcFilesPerYear")
41 self.addOption (
'prescaleLumiCalcFilesPerYear', {}, type=
None,
42 info=
"a dicrionary with key (string) the year and value (list of "
43 "strings) the list of lumicalc files to calculate trigger prescales "
44 "for an individual data year. The default is {} (empty dictionary). "
45 "Mutually exclusive with prescaleLumiCalcFiles")
46 self.addOption (
'prescaleTriggersFormula',
'', type=str,
47 info=
"a formula used in (un)prescaling, producing overall prescale "
48 "factor instead of prescale per trigger.")
49 self.addOption (
'prescaleMC',
False, type=bool,
50 info=
"ouput trigger prescales when running on MC. The default is False.")
51 self.addOption (
'unprescaleData',
False, type=bool,
52 info=
"ouput trigger prescales when running on Data. The default is False.")
53 self.addOption (
'prescaleIncludeAllYears',
False, type=bool,
54 info=
"if True, trigger prescales will include all configured years "
55 "from prescaleLumiCalcFilesPerYear in all jobs. The default is False.")
56 self.addOption (
'noFilter',
False, type=bool,
57 info=
"do not apply an event filter. The default is False, i.e. "
58 "remove events not passing trigger selection and matching.")
60 self.addOption (
'noL1',
False, type=bool,
66 toolName =
"TrigDecisionTool"
67 if toolName
in config._algorithms:
68 return config._algorithms[toolName]
71 xAODConfTool = config.createPublicTool(
"TrigConf::xAODConfigTool",
"xAODConfigTool")
72 decisionTool = config.createPublicTool(
"Trig::TrigDecisionTool", toolName)
73 decisionTool.ConfigTool = f
"{xAODConfTool.getType()}/{xAODConfTool.getName()}"
74 decisionTool.HLTSummary = config.hltSummary()
75 if config.geometry()
is LHCPeriod.Run3:
79 decisionTool.NavigationFormat =
"TrigComposite"
86 toolName =
"TrigMatchingTool"
87 if toolName
in config._algorithms:
88 return config._algorithms[toolName]
91 if config.geometry()
is LHCPeriod.Run3:
92 drScoringTool = config.createPublicTool(
"Trig::DRScoringTool",
"DRScoringTool")
93 matchingTool = config.createPublicTool(
"Trig::R3MatchingTool", toolName)
94 matchingTool.ScoringTool = f
"{drScoringTool.getType()}/{drScoringTool.getName()}"
95 matchingTool.TrigDecisionTool = f
"{decisionTool.getType()}/{decisionTool.getName()}"
97 matchingTool = config.createPublicTool(
"Trig::MatchFromCompositeTool", toolName)
98 if config.isPhyslite():
99 matchingTool.InputPrefix =
"AnalysisTrigMatch_"
104 return [lumicalc.split(
":")[-1]
for lumicalc
in lumicalc_files
if ":" in lumicalc]
109 alg = config.createAlgorithm(
'CP::TrigEventSelectionAlg',
'TrigEventSelectionAlg' )
110 alg.tool =
'%s/%s' % \
111 ( decisionTool.getType(), decisionTool.getName() )
113 alg.selectionDecoration =
'trigPassed'
114 alg.noFilter = self.noFilter
118 t = t.replace(
".",
"p").
replace(
"-",
"_")
119 config.addOutputVar (
'EventInfo',
'trigPassed_' + t,
'trigPassed_' + t, noSys=
True)
123 if triggerChainsForDeco :
124 alg = config.createAlgorithm(
'CP::TrigEventSelectionAlg',
'TrigEventSelectionAlgDeco' )
125 alg.tool =
'%s/%s' % \
126 ( decisionTool.getType(), decisionTool.getName() )
127 alg.triggers = triggerChainsForDeco
128 alg.selectionDecoration =
'trigPassed'
132 for t
in triggerChainsForDeco :
133 t = t.replace(
".",
"p").
replace(
"-",
"_")
134 config.addOutputVar (
'EventInfo',
'trigPassed_' + t,
'trigPassed_' + t, noSys=
True)
137 if (self.prescaleLumiCalcFiles
or self.prescaleLumiCalcFilesPerYear)
and (
138 self.unprescaleData
if config.dataType()
is DataType.Data
else self.prescaleMC
142 if self.prescaleLumiCalcFiles:
143 lumicalc_files = self.prescaleLumiCalcFiles
144 elif self.prescaleLumiCalcFilesPerYear:
145 from TriggerAnalysisAlgorithms.TriggerAnalysisSFConfig
import get_input_years, get_year_data
149 lumicalc_files.extend(
get_year_data(self.prescaleLumiCalcFilesPerYear, year))
151 alg = config.createAlgorithm(
'CP::TrigPrescalesAlg',
'TrigPrescalesAlg' )
152 config.addPrivateTool(
'pileupReweightingTool',
'CP::PileupReweightingTool' )
153 alg.pileupReweightingTool.LumiCalcFiles = lumicalc_files
154 alg.selectionDecoration =
'trigPassed'
155 alg.prescaleMC = config.dataType()
is not DataType.Data
156 alg.prescaleDecoration = self.prescaleDecoration
157 if self.prescaleTriggersFormula !=
'':
158 alg.prescaleTriggersFormula = self.prescaleTriggersFormula
159 config.addOutputVar(
"EventInfo", alg.prescaleDecoration, alg.prescaleDecoration, noSys=
True)
165 triggers_output =
set(alg.triggers)
166 if self.prescaleIncludeAllYears
and self.prescaleLumiCalcFilesPerYear:
167 all_lumicalc_files = [
169 for lumicalc_year
in self.prescaleLumiCalcFilesPerYear.
values()
170 for lumicalc
in lumicalc_year
173 for trigger
in triggers_output:
174 trigger = trigger.replace(
"-",
"_")
177 alg.prescaleDecoration +
"_" + trigger,
178 alg.prescaleDecoration +
"_" + trigger,
189 raise Exception(
'multiTriggerChainsPerYear and triggerChainsPerYear cannot be configured at the same time!')
191 if self.prescaleLumiCalcFiles
and self.prescaleLumiCalcFilesPerYear:
192 raise Exception(
'prescaleLumiCalcFiles and prescaleLumiCalcFilesPerYear cannot be configured at the same time!')
194 if self.prescaleIncludeAllYears
and not self.prescaleLumiCalcFilesPerYear:
195 raise Exception(
'prescaleIncludeAllYears requires prescaleLumiCalcFilesPerYear to be configured!')
197 if (self.prescaleLumiCalcFiles
or self.prescaleLumiCalcFilesPerYear)
and not (
198 self.unprescaleData
or self.prescaleMC
200 raise Exception(
'Lumicalc files are provided but no trigger prescale output is configured! Specify output with "unprescaleData" and/or "prescaleMC".')
209 for chain_list
in self.triggerChainsPerYear.
values():
210 for chain
in chain_list:
212 chains = chain.split(
'||')
213 triggers.update(map(str.strip, chains))
215 triggers.add(chain.strip())
231 from TriggerAnalysisAlgorithms.TriggerAnalysisSFConfig
import TriggerAnalysisSFBlock
232 seq.append(TriggerAnalysisSFBlock())