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 triggerSuffix='', str trig_string='', list trig_chains=[''])
 
None makeTrigMatchingAlg (self, ConfigAccumulator config, matchingTool, str triggerSuffix='')
 
None makeAlgs (self, ConfigAccumulator config)
 

Public Attributes

 multiTriggerChainsPerYear
 
 triggerChainsPerYear
 

Detailed Description

the ConfigBlock for trigger analysis

Definition at line 35 of file TriggerAnalysisSFConfig.py.

Constructor & Destructor Documentation

◆ __init__()

def python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.__init__ (   self)

Definition at line 37 of file TriggerAnalysisSFConfig.py.

37  def __init__(self):
38  super(TriggerAnalysisSFBlock, self).__init__()
39  self.addDependency('Electrons', required=False)
40  self.addDependency('Photons', required=False)
41  self.addDependency('Muons', required=False)
42  self.addDependency('Taus', required=False)
43  self.addDependency('OverlapRemoval', required=False)
44 
45  self.addOption ('triggerChainsPerYear', {}, type=None,
46  info="a dictionary with key (string) the year and value (list of "
47  "strings) the trigger chains. You can also use || within a string "
48  "to enforce an OR of triggers without looking up the individual "
49  "triggers. Used for both trigger selection and SFs. "
50  "The default is {} (empty dictionary).")
51  self.addOption ('multiTriggerChainsPerYear', {}, type=None,
52  info="a dictionary with key (string) a trigger set name and value a "
53  "triggerChainsPerYear dictionary, following the previous convention. "
54  "Relevant for analyses using different triggers in different categories, "
55  "where the trigger global scale factors shouldn't be combined. "
56  "The default is {} (empty dictionary).")
57  self.addOption ('noFilter', False, type=bool,
58  info="do not apply an event filter. The default is False, i.e. "
59  "remove events not passing trigger selection and matching.")
60  self.addOption ('electronID', '', type=str,
61  info="the electron ID WP (string) to use.")
62  self.addOption ('electronIsol', '', type=str,
63  info="the electron isolation WP (string) to use.")
64  self.addOption ('photonIsol', '', type=str,
65  info="the photon isolation WP (string) to use.")
66  self.addOption ('muonID', '', type=str,
67  info="the muon quality WP (string) to use.")
68  self.addOption ('electrons', '', type=str,
69  info="the input electron container, with a possible selection, in "
70  "the format container or container.selection.")
71  self.addOption ('muons', '', type=str,
72  info="the input muon container, with a possible selection, in the "
73  "format container or container.selection.")
74  self.addOption ('photons', '', type=str,
75  info="the input photon container, with a possible selection, in "
76  "the format container or container.selection.")
77  self.addOption ('taus', '', type=str,
78  info="the input tau container, with a possible selection, in "
79  "the format container or container.selection.")
80  self.addOption ('noEffSF', False, type=bool,
81  info="disables the calculation of efficiencies and scale factors. "
82  "Experimental! only useful to test a new WP for which scale "
83  "factors are not available. Still performs the global trigger "
84  "matching (same behaviour as on data). The default is False.")
85  self.addOption ('noGlobalTriggerEff', False, type=bool,
86  info="disables the global trigger efficiency tool (including "
87  "matching), which is only suited for electron/muon/photon "
88  "trigger legs. The default is False.")
89  self.addOption ('triggerMatchingChainsPerYear', {}, type=None,
90  info="a dictionary with key (string) the year and value (list of "
91  "strings) the trigger chains. The default is {} (empty dictionary).")
92  self.addOption ('postfix', '', type=str,
93  info="a unique identifier for the trigger matching decorations. Only "
94  "useful when defining multiple setups. The default is '' (empty string).")
95 

Member Function Documentation

◆ createTrigMatching()

None python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.createTrigMatching (   self,
ConfigAccumulator  config,
  matchingTool,
  particles,
str   triggerSuffix = '',
str   trig_string = '',
list   trig_chains = [''] 
)

Definition at line 162 of file TriggerAnalysisSFConfig.py.

162  def createTrigMatching(
163  self,
164  config: ConfigAccumulator,
165  matchingTool,
166  particles,
167  triggerSuffix: str = '',
168  trig_string: str = '',
169  trig_chains: list = ['']
170  ) -> None:
171  if particles and any(trig_string in trig for trig in trig_chains):
172  alg = config.createAlgorithm( 'CP::TrigMatchingAlg', f'TrigMatchingAlg_{trig_string}{triggerSuffix}{self.postfix}' )
173  alg.matchingTool = '%s/%s' % ( matchingTool.getType(), matchingTool.getName() )
174  alg.matchingDecoration = 'trigMatched' + triggerSuffix + self.postfix
175  alg.trigSingleMatchingList = trig_chains
176  alg.particles, alg.particleSelection = config.readNameAndSelection(particles)
177 
178  for trig in alg.trigSingleMatchingList:
179  trig = trig.replace(".", "p").replace("-", "_").replace(" ", "")
180  if trig_string in trig:
181  config.addOutputVar(particles.split('.')[0], f'trigMatched_{triggerSuffix}{self.postfix}{trig}', f'trigMatched_{triggerSuffix}{self.postfix}{trig}')
182  return
183 

◆ makeAlgs()

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

Definition at line 215 of file TriggerAnalysisSFConfig.py.

215  def makeAlgs(self, config: ConfigAccumulator) -> None:
216  if (
217  self.multiTriggerChainsPerYear and
218  self.triggerChainsPerYear and
219  self.triggerChainsPerYear not in self.multiTriggerChainsPerYear.values()
220  ):
221  raise Exception('multiTriggerChainsPerYear and triggerChainsPerYear cannot be configured at the same time!')
222 
223  if self.triggerChainsPerYear and not self.multiTriggerChainsPerYear:
224  self.multiTriggerChainsPerYear = {'': self.triggerChainsPerYear}
225 
226  # Create the decision algorithm, keeping track of the decision tool for later
227  decisionTool = TriggerAnalysisBlock.makeTriggerDecisionTool(config)
228 
229  # Now pass it to the matching algorithm, keeping track of the matching tool for later
230  matchingTool = TriggerAnalysisBlock.makeTriggerMatchingTool(config, decisionTool)
231 
232  # Calculate multi-lepton (electron/muon/photon) trigger efficiencies and SFs
233  if self.multiTriggerChainsPerYear and not self.noGlobalTriggerEff:
234  for suffix, trigger_chains in self.multiTriggerChainsPerYear.items():
235  self.triggerChainsPerYear = trigger_chains
236  self.makeTriggerGlobalEffCorrAlg(config, matchingTool, self.noEffSF, suffix)
237 
238  # Save trigger matching information (currently only single leg trigger are supported)
239  if self.triggerMatchingChainsPerYear:
240  self.makeTrigMatchingAlg(config, matchingTool)
241 
242  return

◆ makeTriggerGlobalEffCorrAlg()

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

Definition at line 96 of file TriggerAnalysisSFConfig.py.

96  def makeTriggerGlobalEffCorrAlg(
97  self,
98  config: ConfigAccumulator,
99  matchingTool,
100  noSF: bool,
101  triggerSuffix: str = ''
102  ) -> None:
103  alg = config.createAlgorithm( 'CP::TrigGlobalEfficiencyAlg', 'TrigGlobalSFAlg' + triggerSuffix + self.postfix)
104  if config.geometry() is LHCPeriod.Run3:
105  alg.triggers_2022 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2022)]
106  alg.triggers_2023 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2023)]
107  alg.triggers_2024 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2024)]
108  alg.triggers_2025 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2025)]
109  if is_mc_from(config, [Campaign.MC21a, Campaign.MC23a]) or is_data_from(config, 2022):
110  if not alg.triggers_2022:
111  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2022!')
112  elif is_mc_from(config, [Campaign.MC23c, Campaign.MC23d]) or is_data_from(config, 2023):
113  if not alg.triggers_2023:
114  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2023!')
115  else:
116  alg.triggers_2015 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2015)]
117  alg.triggers_2016 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2016)]
118  alg.triggers_2017 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2017)]
119  alg.triggers_2018 = [trig.replace("HLT_","").replace(" || ", "_OR_") for trig in get_year_data(self.triggerChainsPerYear, 2018)]
120  if is_mc_from(config, Campaign.MC20a):
121  if not (alg.triggers_2015 and alg.triggers_2016):
122  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the years 2015 and 2016!')
123  elif is_data_from(config, 2015):
124  if not alg.triggers_2015:
125  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2015!')
126  elif is_data_from(config, 2016):
127  if not alg.triggers_2016:
128  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2016!')
129  elif is_mc_from(config, Campaign.MC20d) or is_data_from(config, 2017):
130  if not alg.triggers_2017:
131  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2017!')
132  elif is_mc_from(config, Campaign.MC20e) or is_data_from(config, 2018):
133  if not alg.triggers_2018:
134  raise ValueError('TriggerAnalysisConfig: you must provide a set of triggers for the year 2018!')
135 
136  alg.matchingTool = '%s/%s' % ( matchingTool.getType(), matchingTool.getName() )
137  alg.isRun3Geo = config.geometry() is LHCPeriod.Run3
138  alg.scaleFactorDecoration = 'globalTriggerEffSF' + triggerSuffix + self.postfix + '_%SYS%'
139  alg.matchingDecoration = 'globalTriggerMatch' + triggerSuffix + self.postfix + '_%SYS%'
140  alg.eventDecisionOutputDecoration = 'globalTriggerMatch' + triggerSuffix + self.postfix + '_dontsave_%SYS%'
141  alg.doMatchingOnly = config.dataType() is DataType.Data or noSF
142  alg.noFilter = self.noFilter
143  alg.electronID = self.electronID
144  alg.electronIsol = self.electronIsol
145  alg.photonIsol = self.photonIsol
146  alg.muonID = self.muonID
147  if self.electrons:
148  alg.electrons, alg.electronSelection = config.readNameAndSelection(self.electrons)
149  if self.muons:
150  alg.muons, alg.muonSelection = config.readNameAndSelection(self.muons)
151  if self.photons:
152  alg.photons, alg.photonSelection = config.readNameAndSelection(self.photons)
153  if not (self.electrons or self.muons or self.photons):
154  raise ValueError('TriggerAnalysisConfig: at least one object collection must be provided! (electrons, muons, photons)' )
155 
156  if config.dataType() is not DataType.Data and not alg.doMatchingOnly:
157  config.addOutputVar('EventInfo', alg.scaleFactorDecoration, 'globalTriggerEffSF' + triggerSuffix + self.postfix)
158  config.addOutputVar('EventInfo', alg.matchingDecoration, 'globalTriggerMatch' + triggerSuffix + self.postfix, noSys=False)
159 
160  return
161 

◆ makeTrigMatchingAlg()

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

Definition at line 184 of file TriggerAnalysisSFConfig.py.

184  def makeTrigMatchingAlg(
185  self,
186  config: ConfigAccumulator,
187  matchingTool,
188  triggerSuffix: str = ''
189  ) -> None:
190  years = []
191  if config.campaign() is Campaign.MC20a: years = [2015, 2016]
192  elif is_data_from(config, 2015): years = [2015]
193  elif is_data_from(config, 2016): years = [2016]
194  elif config.campaign() is Campaign.MC20d or is_data_from(config, 2017): years = [2017]
195  elif config.campaign() is Campaign.MC20e or is_data_from(config, 2018): years = [2018]
196  elif config.campaign() in [Campaign.MC21a, Campaign.MC23a] or is_data_from(config, 2022): years = [2022]
197  elif config.campaign() in [Campaign.MC23c, Campaign.MC23d] or is_data_from(config, 2023): years = [2023]
198 
199  triggerMatchingChains = []
200  for year in years:
201  for trig in get_year_data(self.triggerChainsPerYear, year):
202  trig = trig.replace(' || ', '_OR_')
203  triggerMatchingChains += trig.split('_OR_')
204 
205  # Remove duplicates
206  triggerMatchingChains = list(set(triggerMatchingChains))
207 
208  self.createTrigMatching(config, matchingTool, self.electrons, triggerSuffix, 'HLT_e', triggerMatchingChains)
209  self.createTrigMatching(config, matchingTool, self.muons, triggerSuffix, 'HLT_mu', triggerMatchingChains)
210  self.createTrigMatching(config, matchingTool, self.photons, triggerSuffix, 'HLT_g', triggerMatchingChains)
211  self.createTrigMatching(config, matchingTool, self.taus, triggerSuffix, 'HLT_tau', triggerMatchingChains)
212 
213  return
214 

Member Data Documentation

◆ multiTriggerChainsPerYear

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.multiTriggerChainsPerYear

Definition at line 224 of file TriggerAnalysisSFConfig.py.

◆ triggerChainsPerYear

python.TriggerAnalysisSFConfig.TriggerAnalysisSFBlock.triggerChainsPerYear

Definition at line 235 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:805
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
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:79
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18