ATLAS Offline Software
Loading...
Searching...
No Matches
python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock Class Reference
Inheritance diagram for python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock:
Collaboration diagram for python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock:

Public Member Functions

 __init__ (self)
 instanceName (self)
None makeTriggerGlobalEffCorrAlg (self, ConfigAccumulator config, matchingTool, bool noSF, str triggerSuffix='')
None createTrigMatching (self, ConfigAccumulator config, matchingTool, particles, str trig_string="", set trig_chains=None, set trig_chains_dummy=None)
None makeTrigMatchingAlg (self, ConfigAccumulator config, matchingTool)
None makeAlgs (self, ConfigAccumulator config)

Public Attributes

 separateChainMatching
 triggerChainsPerYear
 electrons
 muons
 photons
 postfix
 triggerMatchingChainsPerYear
 includeAllYearsPerRun
 taus
dict multiTriggerChainsPerYear
 noGlobalTriggerEff
 noEffSF

Detailed Description

the ConfigBlock for trigger analysis

Definition at line 77 of file TriggerAnalysisSFConfig.py.

Constructor & Destructor Documentation

◆ __init__()

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.__init__ ( self)

Definition at line 79 of file TriggerAnalysisSFConfig.py.

79 def __init__(self):
80 super(TriggerAnalysisSFBlock, self).__init__()
81 self.addDependency('Electrons', required=False)
82 self.addDependency('Photons', required=False)
83 self.addDependency('Muons', required=False)
84 self.addDependency('Taus', required=False)
85 self.addDependency('OverlapRemoval', required=False)
86
87 self.addOption ('triggerChainsPerYear', {}, type=dict,
88 info="a dictionary with key (string) the year and value (list of "
89 "strings) the trigger chains. You can also use `||` within a string "
90 "to enforce an OR of triggers without looking up the individual "
91 "triggers. Used for both trigger selection and SFs.")
92 self.addOption ('multiTriggerChainsPerYear', {}, type=dict,
93 info="a dictionary with key (string) a trigger set name and value a "
94 "`triggerChainsPerYear` dictionary, following the previous convention. "
95 "Relevant for analyses using different triggers in different categories, "
96 "where the trigger global scale factors shouldn't be combined.")
97 self.addOption ('noFilter', False, type=bool,
98 info="do not apply an event filter (i.e. keep events "
99 "not passing trigger selection and matching).")
100 self.addOption ('electronID', '', type=str,
101 info="the electron ID WP to use.")
102 self.addOption ('electronIsol', '', type=str,
103 info="the electron isolation WP to use.")
104 self.addOption ('photonIsol', '', type=str,
105 info="the photon isolation WP to use.")
106 self.addOption ('muonID', '', type=str,
107 info="the muon quality WP to use.")
108 self.addOption ('electrons', '', type=str,
109 info="the input electron container, with a possible selection, in "
110 "the format `container` or `container.selection`.")
111 self.addOption ('muons', '', type=str,
112 info="the input muon container, with a possible selection, in the "
113 "format `container` or `container.selection`.")
114 self.addOption ('photons', '', type=str,
115 info="the input photon container, with a possible selection, in "
116 "the format `container` or `container.selection`.")
117 self.addOption ('taus', '', type=str,
118 info="the input tau-jet container, with a possible selection, in "
119 "the format `container` or `container.selection`.")
120 self.addOption ('numberOfToys', 0, type=int,
121 info="the number of toy experiments to run to estimate the trigger efficiencies, "
122 "instead of using explicit formulas. Set it to 0 to not use toys.")
123 self.addOption ('noEffSF', False, type=bool,
124 info="disables the calculation of efficiencies and scale factors. "
125 "Experimental! only useful to test a new WP for which scale "
126 "factors are not available. Still performs the global trigger "
127 "matching (same behaviour as on data).",
128 expertMode=True)
129 self.addOption ('noGlobalTriggerEff', False, type=bool,
130 info="disables the global trigger efficiency tool (including "
131 "matching), which is only suited for electron/muon/photon "
132 "trigger legs.")
133 self.addOption ('separateChainMatching', False, type=bool,
134 info="store the matching status for each trigger separately.")
135 self.addOption ('triggerMatchingChainsPerYear', {}, type=dict,
136 info="a dictionary with key (string) the year and value (list of "
137 "strings) the trigger chains.")
138 self.addOption("includeAllYearsPerRun", False, type=bool,
139 info="trigger matching will include all configured years "
140 "in the LHC run in all jobs.")
141 self.addOption ('postfix', '', type=str,
142 info="a unique identifier for the trigger matching decorations. Only "
143 "useful when defining multiple setups.")
144

Member Function Documentation

◆ createTrigMatching()

None python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.createTrigMatching ( self,
ConfigAccumulator config,
matchingTool,
particles,
str trig_string = "",
set trig_chains = None,
set trig_chains_dummy = None )

Definition at line 228 of file TriggerAnalysisSFConfig.py.

236 ) -> None:
237 if not particles or (not trig_chains and not trig_chains_dummy):
238 return
239
240 if not any(trig_string in trig for trig in trig_chains) \
241 and not any(trig_string in trig for trig in trig_chains_dummy):
242 return
243
244 alg = config.createAlgorithm("CP::TrigMatchingAlg", f"TrigMatchingAlg_{trig_string}")
245 alg.matchingTool = f"{matchingTool.getType()}/{matchingTool.getName()}"
246 alg.matchingDecoration = f"trigMatched{self.postfix}"
247 alg.trigSingleMatchingList = [trig for trig in trig_chains if trig_string in trig]
248 alg.trigSingleMatchingListDummy = [trig for trig in trig_chains_dummy if trig_string in trig]
249 alg.particles, _ = config.readNameAndSelection(particles)
250
251 for trig in list(alg.trigSingleMatchingList) + list(alg.trigSingleMatchingListDummy):
252 trig = trig.replace(".", "p").replace("-", "_").replace(" ", "")
253 if trig_string in trig:
254 config.addOutputVar(particles.split(".")[0], f"trigMatched{self.postfix}_{trig}", f"trigMatched{self.postfix}_{trig}", noSys=True, auxType="char")
255
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:312

◆ instanceName()

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.instanceName ( self)

Definition at line 145 of file TriggerAnalysisSFConfig.py.

145 def instanceName(self):
146 return self.postfix
147

◆ makeAlgs()

None python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.makeAlgs ( self,
ConfigAccumulator config )

Definition at line 286 of file TriggerAnalysisSFConfig.py.

286 def makeAlgs(self, config: ConfigAccumulator) -> None:
287 if (
288 self.multiTriggerChainsPerYear and
289 self.triggerChainsPerYear and
290 self.triggerChainsPerYear not in self.multiTriggerChainsPerYear.values()
291 ):
292 raise Exception('multiTriggerChainsPerYear and triggerChainsPerYear cannot be configured at the same time!')
293
294 if self.triggerChainsPerYear and not self.multiTriggerChainsPerYear:
295 self.multiTriggerChainsPerYear = {'': self.triggerChainsPerYear}
296
297 # Create the decision algorithm, keeping track of the decision tool for later
298 decisionTool = TriggerAnalysisBlock.makeTriggerDecisionTool(config)
299
300 # Now pass it to the matching algorithm, keeping track of the matching tool for later
301 matchingTool = TriggerAnalysisBlock.makeTriggerMatchingTool(config, decisionTool)
302
303 # Calculate multi-lepton (electron/muon/photon) trigger efficiencies and SFs
304 if self.multiTriggerChainsPerYear and not self.noGlobalTriggerEff:
305 for suffix, trigger_chains in self.multiTriggerChainsPerYear.items():
306 self.triggerChainsPerYear = trigger_chains
307 self.makeTriggerGlobalEffCorrAlg(config, matchingTool, self.noEffSF, suffix)
308
309 # Save trigger matching information (currently only single leg trigger are supported)
310 if self.triggerMatchingChainsPerYear:
311 self.makeTrigMatchingAlg(config, matchingTool)
312
313 return

◆ makeTriggerGlobalEffCorrAlg()

None python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.makeTriggerGlobalEffCorrAlg ( self,
ConfigAccumulator config,
matchingTool,
bool noSF,
str triggerSuffix = '' )

Definition at line 148 of file TriggerAnalysisSFConfig.py.

154 ) -> None:
155 alg = config.createAlgorithm("CP::TrigGlobalEfficiencyAlg", "TrigGlobalSFAlg" + triggerSuffix)
156 if config.geometry() is LHCPeriod.Run3:
157 alg.triggers_2022 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2022)]
158 alg.triggers_2023 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2023)]
159 alg.triggers_2024 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2024)]
160 alg.triggers_2025 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2025)]
161 if is_mc_from(config, Campaign.MC23a) or is_data_from(config, 2022):
162 if not alg.triggers_2022:
163 raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2022!')
164 elif is_mc_from(config, Campaign.MC23d) or is_data_from(config, 2023):
165 if not alg.triggers_2023:
166 raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2023!')
167 else:
168 alg.triggers_2015 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2015)]
169 alg.triggers_2016 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2016)]
170 alg.triggers_2017 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2017)]
171 alg.triggers_2018 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2018)]
172 if is_mc_from(config, Campaign.MC20a):
173 if not (alg.triggers_2015 and alg.triggers_2016):
174 raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the years 2015 and 2016!')
175 elif is_data_from(config, 2015):
176 if not alg.triggers_2015:
177 raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2015!')
178 elif is_data_from(config, 2016):
179 if not alg.triggers_2016:
180 raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2016!')
181 elif is_mc_from(config, Campaign.MC20d) or is_data_from(config, 2017):
182 if not alg.triggers_2017:
183 raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2017!')
184 elif is_mc_from(config, Campaign.MC20e) or is_data_from(config, 2018):
185 if not alg.triggers_2018:
186 raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2018!')
187
188 triggerMatchingChains = set()
189 if self.separateChainMatching:
190 for year in get_input_years(config):
191 for trig in get_year_data(self.triggerChainsPerYear, year):
192 triggerMatchingChains.update(trig.replace(' || ', '_OR_').split('_OR_'))
193 alg.separateMatchingTriggers = list(triggerMatchingChains)
194 alg.separateMatchingDecorationSuffix = triggerSuffix + self.postfix
195
196 alg.matchingTool = '%s/%s' % ( matchingTool.getType(), matchingTool.getName() )
197 alg.isRun3Geo = config.geometry() is LHCPeriod.Run3
198 alg.campaign = config.campaign().value
199 alg.numberOfToys = self.numberOfToys
200 alg.scaleFactorDecoration = 'globalTriggerEffSF' + triggerSuffix + self.postfix + '_%SYS%'
201 alg.matchingDecoration = 'globalTriggerMatch' + triggerSuffix + self.postfix + '_%SYS%'
202 alg.eventDecisionOutputDecoration = 'globalTriggerMatch' + triggerSuffix + self.postfix + '_dontsave_%SYS%'
203 alg.doMatchingOnly = config.dataType() is DataType.Data or noSF
204 alg.noFilter = self.noFilter
205 alg.electronID = self.electronID
206 alg.electronIsol = self.electronIsol
207 alg.photonIsol = self.photonIsol
208 alg.muonID = self.muonID
209 if self.electrons:
210 alg.electrons, alg.electronSelection = config.readNameAndSelection(self.electrons)
211 if self.muons:
212 alg.muons, alg.muonSelection = config.readNameAndSelection(self.muons)
213 if self.photons:
214 alg.photons, alg.photonSelection = config.readNameAndSelection(self.photons)
215 if not (self.electrons or self.muons or self.photons):
216 raise ValueError('TriggerAnalysisConfig: at least one object collection must be provided! (electrons, muons, photons)' )
217
218 if config.dataType() is not DataType.Data and not alg.doMatchingOnly:
219 config.addOutputVar('EventInfo', alg.scaleFactorDecoration, 'globalTriggerEffSF' + triggerSuffix + self.postfix)
220 config.addOutputVar('EventInfo', alg.matchingDecoration, 'globalTriggerMatch' + triggerSuffix + self.postfix, noSys=False)
221
222 for trig in triggerMatchingChains:
223 var = f'triggerMatch_{trig.replace("-", "_").replace(".", "p")}{alg.separateMatchingDecorationSuffix}'
224 config.addOutputVar('EventInfo', f'{var}_%SYS%', var, noSys=False)
225
226 return
227
STL class.
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179

◆ makeTrigMatchingAlg()

None python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.makeTrigMatchingAlg ( self,
ConfigAccumulator config,
matchingTool )

Definition at line 256 of file TriggerAnalysisSFConfig.py.

260 ) -> None:
261 years = get_input_years(config)
262
263 triggerMatchingChains = set()
264 triggerMatchingChainsDummy = set()
265 for year in years:
266 for trig in get_year_data(self.triggerMatchingChainsPerYear, year):
267 trig = trig.replace(' || ', '_OR_')
268 triggerMatchingChains.update(trig.split('_OR_'))
269 if self.includeAllYearsPerRun:
270 triggerMatchingChainsAll = set()
271 for year in self.triggerMatchingChainsPerYear:
272 if not is_year_in_current_period(config, year):
273 continue
274 for trig in get_year_data(self.triggerMatchingChainsPerYear, year):
275 trig = trig.replace(' || ', '_OR_')
276 triggerMatchingChainsAll.update(trig.split('_OR_'))
277 triggerMatchingChainsDummy = triggerMatchingChainsAll - triggerMatchingChains
278
279 self.createTrigMatching(config, matchingTool, self.electrons, 'HLT_e', triggerMatchingChains, triggerMatchingChainsDummy)
280 self.createTrigMatching(config, matchingTool, self.muons, 'HLT_mu', triggerMatchingChains, triggerMatchingChainsDummy)
281 self.createTrigMatching(config, matchingTool, self.photons, 'HLT_g', triggerMatchingChains, triggerMatchingChainsDummy)
282 self.createTrigMatching(config, matchingTool, self.taus, 'HLT_tau', triggerMatchingChains, triggerMatchingChainsDummy)
283
284 return
285

Member Data Documentation

◆ electrons

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.electrons

Definition at line 209 of file TriggerAnalysisSFConfig.py.

◆ includeAllYearsPerRun

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.includeAllYearsPerRun

Definition at line 269 of file TriggerAnalysisSFConfig.py.

◆ multiTriggerChainsPerYear

dict python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.multiTriggerChainsPerYear

Definition at line 294 of file TriggerAnalysisSFConfig.py.

◆ muons

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.muons

Definition at line 211 of file TriggerAnalysisSFConfig.py.

◆ noEffSF

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.noEffSF

Definition at line 307 of file TriggerAnalysisSFConfig.py.

◆ noGlobalTriggerEff

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.noGlobalTriggerEff

Definition at line 304 of file TriggerAnalysisSFConfig.py.

◆ photons

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.photons

Definition at line 213 of file TriggerAnalysisSFConfig.py.

◆ postfix

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.postfix

Definition at line 219 of file TriggerAnalysisSFConfig.py.

◆ separateChainMatching

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.separateChainMatching

Definition at line 189 of file TriggerAnalysisSFConfig.py.

◆ taus

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.taus

Definition at line 282 of file TriggerAnalysisSFConfig.py.

◆ triggerChainsPerYear

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.triggerChainsPerYear

Definition at line 191 of file TriggerAnalysisSFConfig.py.

◆ triggerMatchingChainsPerYear

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.triggerMatchingChainsPerYear

Definition at line 266 of file TriggerAnalysisSFConfig.py.


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