ATLAS Offline Software
TriggerAnalysisConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 # AnaAlgorithm import(s):
4 from AnalysisAlgorithmsConfig.ConfigBlock import ConfigBlock
5 from AnalysisAlgorithmsConfig.ConfigSequence import groupBlocks
6 from AnalysisAlgorithmsConfig.ConfigAccumulator import DataType
7 from AthenaConfiguration.Enums import LHCPeriod
8 
9 
10 class TriggerAnalysisBlock (ConfigBlock):
11  """the ConfigBlock for trigger analysis"""
12 
13  # configName is not used
14  def __init__ (self, configName='') :
15  super (TriggerAnalysisBlock, self).__init__ ()
16  self.addOption ('triggerChainsPerYear', {}, type=None,
17  info="a dictionary with key (string) the year and value (list of "
18  "strings) the trigger chains. You can also use || within a string "
19  "to enforce an OR of triggers without looking up the individual "
20  "triggers. Used for both trigger selection and SFs. "
21  "The default is {} (empty dictionary).")
22  self.addOption ('multiTriggerChainsPerYear', {}, type=None,
23  info="a dictionary with key (string) a trigger set name and value a "
24  "triggerChainsPerYear dictionary, following the previous convention. "
25  "Relevant for analyses using different triggers in different categories, "
26  "where the trigger global scale factors shouldn't be combined. "
27  "The default is {} (empty dictionary).")
28  self.addOption ('triggerChainsForSelection', [], type=None,
29  info="a list of trigger chains (list of strings) to be used for "
30  "trigger selection. Only set it if you need a different setup "
31  "than for trigger SFs. The default is [] (empty list).")
32  self.addOption ('prescaleLumiCalcFiles', [], type=None,
33  info="a list of lumical files (list of strings) to calculate "
34  "trigger prescales. The default is [] (empty list).")
35  self.addOption ('prescaleTriggersFormula', '', type=str,
36  info="a formula used in (un)prescaling, producing overall prescale "
37  "factor instead of prescale per trigger.")
38  self.addOption ('prescaleMC', False, type=bool,
39  info="prescale MC instead of unprescaling of data.")
40  self.addOption ('noFilter', False, type=bool,
41  info="do not apply an event filter. The default is False, i.e. "
42  "remove events not passing trigger selection and matching.")
43  # TODO: add info string
44  self.addOption ('noL1', False, type=bool,
45  info="")
46 
47  def makeTriggerDecisionTool(self, config):
48 
49  # Create public trigger tools
50  xAODConfTool = config.createPublicTool( 'TrigConf::xAODConfigTool', 'xAODConfigTool' )
51  decisionTool = config.createPublicTool( 'Trig::TrigDecisionTool', 'TrigDecisionTool' )
52  decisionTool.ConfigTool = '%s/%s' % \
53  ( xAODConfTool.getType(), xAODConfTool.getName() )
54  decisionTool.HLTSummary = config.hltSummary()
55  if config.geometry() is LHCPeriod.Run3:
56  decisionTool.NavigationFormat = 'TrigComposite' # Read Run 3 navigation (options are "TrigComposite" for R3 or "TriggElement" for R2, R2 navigation is not kept in most DAODs)
57 
58  return decisionTool
59 
60 
61  def makeTriggerSelectionAlg(self, config, decisionTool):
62 
63  # Set up the trigger selection:
64  alg = config.createAlgorithm( 'CP::TrigEventSelectionAlg', 'TrigEventSelectionAlg' )
65  alg.tool = '%s/%s' % \
66  ( decisionTool.getType(), decisionTool.getName() )
67  alg.triggers = self.triggerChainsForSelection
68  alg.selectionDecoration = 'trigPassed'
69  alg.noFilter = self.noFilter
70  alg.noL1 = self.noL1
71 
72  for t in self.triggerChainsForSelection :
73  t = t.replace(".", "p").replace("-", "_")
74  config.addOutputVar ('EventInfo', 'trigPassed_' + t, 'trigPassed_' + t, noSys=True)
75 
76  # Calculate trigger prescales
77  if ((config.dataType() is DataType.Data) != self.prescaleMC) and self.prescaleLumiCalcFiles:
78 
79  alg = config.createAlgorithm( 'CP::TrigPrescalesAlg', 'TrigPrescalesAlg' )
80  config.addPrivateTool( 'pileupReweightingTool', 'CP::PileupReweightingTool' )
81  alg.pileupReweightingTool.LumiCalcFiles = self.prescaleLumiCalcFiles
82  alg.pileupReweightingTool.TrigDecisionTool = '%s/%s' % \
83  ( decisionTool.getType(), decisionTool.getName() )
84  if self.prescaleTriggersFormula != '':
85  alg.prescaleTriggersFormula = self.prescaleTriggersFormula
86  else:
87  alg.triggers = [lumicalc.split(':')[-1] for lumicalc in self.prescaleLumiCalcFiles if ':' in lumicalc]
88  alg.triggersAll = self.triggerChainsForSelection
89  alg.prescaleMC = self.prescaleMC
90  alg.prescaleDecoration = 'prescale'
91 
92  return
93 
94 
95  def makeAlgs (self, config) :
96 
97  if (self.multiTriggerChainsPerYear and self.triggerChainsPerYear and
98  self.triggerChainsPerYear is not self.multiTriggerChainsPerYear.get('')):
99  raise Exception('multiTriggerChainsPerYear and triggerChainsPerYear cannot be configured at the same time!')
100 
101  if self.triggerChainsPerYear and not self.multiTriggerChainsPerYear:
102  self.multiTriggerChainsPerYear = {'': self.triggerChainsPerYear}
103 
104  # if we are only given the trigger dictionary, we fill the selection list automatically
105  if self.triggerChainsPerYear and not self.triggerChainsForSelection:
106  triggers = set()
107  for trigger_chains in self.multiTriggerChainsPerYear.values():
108  for chain_list in self.triggerChainsPerYear.values():
109  for chain in chain_list:
110  if '||' in chain:
111  chains = chain.split('||')
112  triggers.update(map(str.strip, chains))
113  else:
114  triggers.add(chain.strip())
116 
117  # Create the decision algorithm, keeping track of the decision tool for later
118  decisionTool = self.makeTriggerDecisionTool(config)
119 
121  self.makeTriggerSelectionAlg(config, decisionTool)
122 
123  return
124 
125 
126 
127 @groupBlocks
128 def Trigger(seq):
129  seq.append(TriggerAnalysisBlock())
130  from TriggerAnalysisAlgorithms.TriggerAnalysisSFConfig import TriggerAnalysisSFBlock
131  seq.append(TriggerAnalysisSFBlock())
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
python.TriggerAnalysisConfig.TriggerAnalysisBlock.makeAlgs
def makeAlgs(self, config)
Definition: TriggerAnalysisConfig.py:95
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
python.TriggerAnalysisConfig.TriggerAnalysisBlock.multiTriggerChainsPerYear
multiTriggerChainsPerYear
Definition: TriggerAnalysisConfig.py:102
python.TriggerAnalysisConfig.TriggerAnalysisBlock.makeTriggerDecisionTool
def makeTriggerDecisionTool(self, config)
Definition: TriggerAnalysisConfig.py:47
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.TriggerAnalysisConfig.Trigger
def Trigger(seq)
Definition: TriggerAnalysisConfig.py:128
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
python.TriggerAnalysisConfig.TriggerAnalysisBlock.makeTriggerSelectionAlg
def makeTriggerSelectionAlg(self, config, decisionTool)
Definition: TriggerAnalysisConfig.py:61
python.TriggerAnalysisConfig.TriggerAnalysisBlock.__init__
def __init__(self, configName='')
Definition: TriggerAnalysisConfig.py:14
python.TriggerAnalysisConfig.TriggerAnalysisBlock
Definition: TriggerAnalysisConfig.py:10
python.TriggerAnalysisConfig.TriggerAnalysisBlock.triggerChainsForSelection
triggerChainsForSelection
Definition: TriggerAnalysisConfig.py:115
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127