ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock Class Reference
Inheritance diagram for python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock:
Collaboration diagram for python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock:

Public Member Functions

def __init__ (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

 multiTriggerChainsPerYear
 
 triggerChainsPerYear
 

Detailed Description

the ConfigBlock for trigger analysis

Definition at line 64 of file TriggerAnalysisSFConfig.py.

Constructor & Destructor Documentation

◆ __init__()

def python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.__init__ (   self)

Definition at line 66 of file TriggerAnalysisSFConfig.py.

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

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 198 of file TriggerAnalysisSFConfig.py.

198  def createTrigMatching(
199  self,
200  config: ConfigAccumulator,
201  matchingTool,
202  particles,
203  trig_string: str = "",
204  trig_chains: set = None,
205  trig_chains_dummy: set = None,
206  ) -> None:
207  if not particles or (not trig_chains and not trig_chains_dummy):
208  return
209 
210  if not any(trig_string in trig for trig in trig_chains) \
211  and not any(trig_string in trig for trig in trig_chains_dummy):
212  return
213 
214  alg = config.createAlgorithm("CP::TrigMatchingAlg", f"TrigMatchingAlg_{trig_string}{self.postfix}")
215  alg.matchingTool = f"{matchingTool.getType()}/{matchingTool.getName()}"
216  alg.matchingDecoration = f"trigMatched{self.postfix}"
217  alg.trigSingleMatchingList = [trig for trig in trig_chains if trig_string in trig]
218  alg.trigSingleMatchingListDummy = [trig for trig in trig_chains_dummy if trig_string in trig]
219  alg.particles, alg.particleSelection = config.readNameAndSelection(particles)
220 
221  for trig in list(alg.trigSingleMatchingList) + list(alg.trigSingleMatchingListDummy):
222  trig = trig.replace(".", "p").replace("-", "_").replace(" ", "")
223  if trig_string in trig:
224  config.addOutputVar(particles.split(".")[0], f"trigMatched_{self.postfix}{trig}", f"trigMatched_{self.postfix}{trig}", noSys=True)
225 

◆ makeAlgs()

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

Definition at line 256 of file TriggerAnalysisSFConfig.py.

256  def makeAlgs(self, config: ConfigAccumulator) -> None:
257  if (
258  self.multiTriggerChainsPerYear and
259  self.triggerChainsPerYear and
260  self.triggerChainsPerYear not in self.multiTriggerChainsPerYear.values()
261  ):
262  raise Exception('multiTriggerChainsPerYear and triggerChainsPerYear cannot be configured at the same time!')
263 
264  if self.triggerChainsPerYear and not self.multiTriggerChainsPerYear:
265  self.multiTriggerChainsPerYear = {'': self.triggerChainsPerYear}
266 
267  # Create the decision algorithm, keeping track of the decision tool for later
268  decisionTool = TriggerAnalysisBlock.makeTriggerDecisionTool(config)
269 
270  # Now pass it to the matching algorithm, keeping track of the matching tool for later
271  matchingTool = TriggerAnalysisBlock.makeTriggerMatchingTool(config, decisionTool)
272 
273  # Calculate multi-lepton (electron/muon/photon) trigger efficiencies and SFs
274  if self.multiTriggerChainsPerYear and not self.noGlobalTriggerEff:
275  for suffix, trigger_chains in self.multiTriggerChainsPerYear.items():
276  self.triggerChainsPerYear = trigger_chains
277  self.makeTriggerGlobalEffCorrAlg(config, matchingTool, self.noEffSF, suffix)
278 
279  # Save trigger matching information (currently only single leg trigger are supported)
280  if self.triggerMatchingChainsPerYear:
281  self.makeTrigMatchingAlg(config, matchingTool)
282 
283  return

◆ makeTriggerGlobalEffCorrAlg()

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

Definition at line 131 of file TriggerAnalysisSFConfig.py.

131  def makeTriggerGlobalEffCorrAlg(
132  self,
133  config: ConfigAccumulator,
134  matchingTool,
135  noSF: bool,
136  triggerSuffix: str = ''
137  ) -> None:
138  alg = config.createAlgorithm( 'CP::TrigGlobalEfficiencyAlg', 'TrigGlobalSFAlg' + triggerSuffix + self.postfix)
139  if config.geometry() is LHCPeriod.Run3:
140  alg.triggers_2022 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2022)]
141  alg.triggers_2023 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2023)]
142  alg.triggers_2024 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2024)]
143  alg.triggers_2025 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2025)]
144  if is_mc_from(config, Campaign.MC23a) or is_data_from(config, 2022):
145  if not alg.triggers_2022:
146  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2022!')
147  elif is_mc_from(config, Campaign.MC23d) or is_data_from(config, 2023):
148  if not alg.triggers_2023:
149  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2023!')
150  else:
151  alg.triggers_2015 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2015)]
152  alg.triggers_2016 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2016)]
153  alg.triggers_2017 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2017)]
154  alg.triggers_2018 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2018)]
155  if is_mc_from(config, Campaign.MC20a):
156  if not (alg.triggers_2015 and alg.triggers_2016):
157  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the years 2015 and 2016!')
158  elif is_data_from(config, 2015):
159  if not alg.triggers_2015:
160  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2015!')
161  elif is_data_from(config, 2016):
162  if not alg.triggers_2016:
163  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2016!')
164  elif is_mc_from(config, Campaign.MC20d) or is_data_from(config, 2017):
165  if not alg.triggers_2017:
166  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2017!')
167  elif is_mc_from(config, Campaign.MC20e) or is_data_from(config, 2018):
168  if not alg.triggers_2018:
169  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2018!')
170 
171  alg.matchingTool = '%s/%s' % ( matchingTool.getType(), matchingTool.getName() )
172  alg.isRun3Geo = config.geometry() is LHCPeriod.Run3
173  alg.numberOfToys = self.numberOfToys
174  alg.scaleFactorDecoration = 'globalTriggerEffSF' + triggerSuffix + self.postfix + '_%SYS%'
175  alg.matchingDecoration = 'globalTriggerMatch' + triggerSuffix + self.postfix + '_%SYS%'
176  alg.eventDecisionOutputDecoration = 'globalTriggerMatch' + triggerSuffix + self.postfix + '_dontsave_%SYS%'
177  alg.doMatchingOnly = config.dataType() is DataType.Data or noSF
178  alg.noFilter = self.noFilter
179  alg.electronID = self.electronID
180  alg.electronIsol = self.electronIsol
181  alg.photonIsol = self.photonIsol
182  alg.muonID = self.muonID
183  if self.electrons:
184  alg.electrons, alg.electronSelection = config.readNameAndSelection(self.electrons)
185  if self.muons:
186  alg.muons, alg.muonSelection = config.readNameAndSelection(self.muons)
187  if self.photons:
188  alg.photons, alg.photonSelection = config.readNameAndSelection(self.photons)
189  if not (self.electrons or self.muons or self.photons):
190  raise ValueError('TriggerAnalysisConfig: at least one object collection must be provided! (electrons, muons, photons)' )
191 
192  if config.dataType() is not DataType.Data and not alg.doMatchingOnly:
193  config.addOutputVar('EventInfo', alg.scaleFactorDecoration, 'globalTriggerEffSF' + triggerSuffix + self.postfix)
194  config.addOutputVar('EventInfo', alg.matchingDecoration, 'globalTriggerMatch' + triggerSuffix + self.postfix, noSys=False)
195 
196  return
197 

◆ makeTrigMatchingAlg()

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

Definition at line 226 of file TriggerAnalysisSFConfig.py.

226  def makeTrigMatchingAlg(
227  self,
228  config: ConfigAccumulator,
229  matchingTool,
230  ) -> None:
231  years = get_input_years(config)
232 
233  triggerMatchingChains = set()
234  triggerMatchingChainsDummy = set()
235  for year in years:
236  for trig in get_year_data(self.triggerMatchingChainsPerYear, year):
237  trig = trig.replace(' || ', '_OR_')
238  triggerMatchingChains.update(trig.split('_OR_'))
239  if self.includeAllYearsPerRun:
240  triggerMatchingChainsAll = set()
241  for year in self.triggerMatchingChainsPerYear:
242  if not is_year_in_current_period(config, year):
243  continue
244  for trig in get_year_data(self.triggerMatchingChainsPerYear, year):
245  trig = trig.replace(' || ', '_OR_')
246  triggerMatchingChainsAll.update(trig.split('_OR_'))
247  triggerMatchingChainsDummy = triggerMatchingChainsAll - triggerMatchingChains
248 
249  self.createTrigMatching(config, matchingTool, self.electrons, 'HLT_e', triggerMatchingChains, triggerMatchingChainsDummy)
250  self.createTrigMatching(config, matchingTool, self.muons, 'HLT_mu', triggerMatchingChains, triggerMatchingChainsDummy)
251  self.createTrigMatching(config, matchingTool, self.photons, 'HLT_g', triggerMatchingChains, triggerMatchingChainsDummy)
252  self.createTrigMatching(config, matchingTool, self.taus, 'HLT_tau', triggerMatchingChains, triggerMatchingChainsDummy)
253 
254  return
255 

Member Data Documentation

◆ multiTriggerChainsPerYear

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.multiTriggerChainsPerYear

Definition at line 265 of file TriggerAnalysisSFConfig.py.

◆ triggerChainsPerYear

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.triggerChainsPerYear

Definition at line 276 of file TriggerAnalysisSFConfig.py.


The documentation for this class was generated from the following file:
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
python.TriggerAnalysisSFConfig.is_mc_from
bool is_mc_from(ConfigAccumulator config, Union[Campaign, Iterable[Campaign]] campaign_list)
Definition: TriggerAnalysisSFConfig.py:11
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:808
python.TriggerAnalysisConfig.is_year_in_current_period
bool is_year_in_current_period(ConfigAccumulator config, int|str year)
Definition: TriggerAnalysisConfig.py:9
python.TriggerAnalysisSFConfig.get_year_data
list get_year_data(dict dictionary, int|str year)
Definition: TriggerAnalysisSFConfig.py:28
python.TriggerAnalysisSFConfig.is_data_from
bool is_data_from(config, Union[int, Iterable[int]] data_year_list)
Definition: TriggerAnalysisSFConfig.py:20
python.TriggerAnalysisSFConfig.get_input_years
list[int] get_input_years(ConfigAccumulator config)
Definition: TriggerAnalysisSFConfig.py:35
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
CxxUtils::set
constexpr std::enable_if_t< is_bitmask_v< E >, E & > set(E &lhs, E rhs)
Convenience function to set bits in a class enum bitmask.
Definition: bitmask.h:232
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:71
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18