ATLAS Offline Software
TriggerListsHelper.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 # TriggerListsHelper: helper class which retrieves the full set of triggers needed for
3 # trigger matching in the DAODs and can then return them when needed.
4 
5 from TriggerMenuMT.TriggerAPI import TriggerAPISession, TriggerType, TriggerAPI, TriggerPeriod
6 from PathResolver import PathResolver
7 from AthenaConfiguration.AutoConfigFlags import GetFileMD
8 
9 def read_trig_list_file(fname):
10  """Read a text file containing a list of triggers
11  Returns the list of triggers held in the file
12  """
13  triggers = []
14  with open(PathResolver.FindCalibFile(fname)) as fp:
15  for line in fp:
16  line = line.strip()
17  if line == "" or line.startswith("#"):
18  continue
19  triggers.append(line)
20  return triggers
21 
23  trigger_names_notau = []
24  trigger_names_tau = []
25  for chain_name in flags.Trigger.derivationsExtraChains:
26  if "tau" in chain_name:
27  trigger_names_tau.append(chain_name)
28  else:
29  trigger_names_notau.append(chain_name)
30  return (trigger_names_notau, trigger_names_tau)
31 
32 def getTapisSession(flags):
33  from Campaigns.Utils import Campaign
34  from AthenaConfiguration.Enums import Format
35  yearStr = str(flags.Input.DataYear) if not flags.Input.isMC else ""
36  if flags.Input.isMC:
37  if flags.Input.MCCampaign == Campaign.MC16a or flags.Input.MCCampaign == Campaign.MC20a:
38  yearStr = "2015_2016"
39  elif flags.Input.MCCampaign == Campaign.MC16d or flags.Input.MCCampaign == Campaign.MC20d:
40  yearStr = "2017"
41  elif flags.Input.MCCampaign == Campaign.MC16e or flags.Input.MCCampaign == Campaign.MC20e:
42  yearStr = "2018"
43  elif flags.Input.MCCampaign == Campaign.MC23a or flags.Input.MCCampaign == Campaign.MC21a:
44  yearStr = "2022"
45  elif flags.Input.MCCampaign == Campaign.MC23c or flags.Input.MCCampaign == Campaign.MC23d:
46  yearStr = "2023"
47 
48  session_files = {
49  "2015": "TriggerAPISessions/tapis_data15_13TeV_20190708_PHYS_StandardGRL_All_Good_25ns.json",
50  "2016": "TriggerAPISessions/tapis_data16_13TeV_20190708_PHYS_StandardGRL_All_Good_25ns_WITH_IGNORES.json",
51  "2015_2016": "TriggerAPISessions/tapis_data15_13TeV_20190708_PHYS_StandardGRL_All_Good_25ns_data16_13TeV_20190708_PHYS_StandardGRL_All_Good_25ns_WITH_IGNORES.json",
52  "2017": "TriggerAPISessions/tapis_data17_13TeV_20190708_PHYS_StandardGRL_All_Good_25ns_Triggerno17e33prim.json",
53  "2018": "TriggerAPISessions/tapis_data18_13TeV_20190708_PHYS_StandardGRL_All_Good_25ns_Triggerno17e33prim.json",
54  "2022": "TriggerAPISessions/tapis_data22_13p6TeV_20230207_PHYS_StandardGRL_All_Good_25ns.json",
55  "2023": "TriggerAPISessions/tapis_data23_13p6TeV_20230828_PHYS_StandardGRL_All_Good_25ns.json",
56  }
57 
58  if yearStr in session_files:
59  return TriggerAPISession(json=session_files[yearStr])
60 
61  # Otherwise: data24, MC23e, phase-II. Base this on the menu from the AOD.
62  if flags.Input.Format == Format.POOL:
63  return TriggerAPISession(file=flags.Input.Files[0])
64 
65  from AthenaCommon.Logging import logging
66  logging.getLogger('TriggerListHelper::GetTriggerLists::getTapisSession').error('Failed to obtain a session.')
67  return None
68 
69 
71  def __init__(self, flags):
72  self.flags = flags
73  TriggerAPI.setConfigFlags(flags)
76  self.Run3TriggerNames = []
77  self.GetTriggerLists()
78 
79  def GetTriggerLists(self):
80 
81  md = GetFileMD(self.flags.Input.Files)
82  hlt_menu = md.get('TriggerMenu', {}).get('HLTChains', None)
83 
84  if self.flags.Trigger.EDMVersion <= 2:
85 
86  # Trigger API for Runs 1, 2
87  #====================================================================
88  # TRIGGER CONTENT
89  #====================================================================
90 
93  allperiods = TriggerPeriod.y2015 | TriggerPeriod.y2016 | TriggerPeriod.y2017 | TriggerPeriod.y2018 | TriggerPeriod.future2e34
94  trig_el = TriggerAPI.getLowestUnprescaledAnyPeriod(allperiods, triggerType=TriggerType.el, livefraction=0.8)
95  trig_mu = TriggerAPI.getLowestUnprescaledAnyPeriod(allperiods, triggerType=TriggerType.mu, livefraction=0.8)
96  trig_g = TriggerAPI.getLowestUnprescaledAnyPeriod(allperiods, triggerType=TriggerType.g, livefraction=0.8)
97  trig_tau = TriggerAPI.getLowestUnprescaledAnyPeriod(allperiods, triggerType=TriggerType.tau, livefraction=0.8)
98 
99  trig_em = TriggerAPI.getLowestUnprescaledAnyPeriod(allperiods, triggerType=TriggerType.el, additionalTriggerType=TriggerType.mu, livefraction=0.8)
100  trig_et = TriggerAPI.getLowestUnprescaledAnyPeriod(allperiods, triggerType=TriggerType.el, additionalTriggerType=TriggerType.tau, livefraction=0.8)
101  trig_mt = TriggerAPI.getLowestUnprescaledAnyPeriod(allperiods, triggerType=TriggerType.mu, additionalTriggerType=TriggerType.tau, livefraction=0.8)
102  # Note that this seems to pick up both isolated and non-isolated triggers already, so no need for extra grabs
103  trig_txe = TriggerAPI.getLowestUnprescaledAnyPeriod(allperiods, triggerType=TriggerType.tau, additionalTriggerType=TriggerType.xe, livefraction=0.8)
104 
105 
106  extra_file_notau = read_trig_list_file("DerivationFrameworkPhys/run2ExtraMatchingTriggers.txt")
107  extra_file_tau = read_trig_list_file("DerivationFrameworkPhys/run2ExtraMatchingTauTriggers.txt")
108 
109 
110  extra_flag_notau, extra_flag_tau = read_trig_list_flags(self.flags)
111 
112 
113  trigger_names_full_notau = list(set(trig_el+trig_mu+trig_g+trig_em+trig_et+trig_mt+extra_file_notau+extra_flag_notau))
114  trigger_names_full_tau = list(set(trig_tau+trig_txe+extra_file_tau+extra_flag_tau))
115 
116 
117  trigger_names_notau = []
118  trigger_names_tau = []
119 
120  if hlt_menu:
121  for chain_name in hlt_menu:
122  if chain_name in trigger_names_full_notau: trigger_names_notau.append(chain_name)
123  if chain_name in trigger_names_full_tau: trigger_names_tau.append(chain_name)
124  else: # No means to filter based on in-file metadata
125  trigger_names_notau = trigger_names_full_notau
126  trigger_names_tau = trigger_names_full_tau
127 
128  self.Run2TriggerNamesNoTau = trigger_names_notau
129  self.Run2TriggerNamesTau = trigger_names_tau
130 
131  else: # Run 3 and Run 4
132 
133  # TriggerAPI Session based trigger lists
134  session = getTapisSession(self.flags)
135  lf = 0.8 # Prescale weighted life fraction of the GRL's LBs
136  api_trigger_names = set()
137  api_trigger_names = session.getLowestUnprescaled(triggerType=TriggerType.el, livefraction=lf).union(api_trigger_names)
138  api_trigger_names = session.getLowestUnprescaled(triggerType=TriggerType.mu, livefraction=lf).union(api_trigger_names)
139  api_trigger_names = session.getLowestUnprescaled(triggerType=TriggerType.g, livefraction=lf).union(api_trigger_names)
140  api_trigger_names = session.getLowestUnprescaled(triggerType=TriggerType.tau, livefraction=lf).union(api_trigger_names)
141 
142  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.el, TriggerType.mu], livefraction=lf).union(api_trigger_names)
143  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.el, TriggerType.tau], livefraction=lf).union(api_trigger_names)
144  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.mu, TriggerType.tau], livefraction=lf).union(api_trigger_names)
145  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.tau, TriggerType.xe], livefraction=lf).union(api_trigger_names)
146 
147  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.el, TriggerType.g], livefraction=lf).union(api_trigger_names)
148  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.el, TriggerType.xe], livefraction=lf).union(api_trigger_names)
149  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.mu, TriggerType.g], livefraction=lf).union(api_trigger_names)
150  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.g, TriggerType.xe], livefraction=lf).union(api_trigger_names)
151  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.tau, TriggerType.g], livefraction=lf).union(api_trigger_names)
152 
153  # Add hadronic categories, new for Run 3
154  api_trigger_names = session.getLowestUnprescaled(triggerType=TriggerType.j, livefraction=lf).union(api_trigger_names)
155  api_trigger_names = session.getLowestUnprescaled(triggerType=TriggerType.bj, livefraction=lf).union(api_trigger_names)
156  # Add cross-triggers as well
157  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.el, TriggerType.j], livefraction=lf).union(api_trigger_names)
158  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.mu, TriggerType.j], livefraction=lf).union(api_trigger_names)
159  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.j, TriggerType.bj], livefraction=lf).union(api_trigger_names)
160  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.j, TriggerType.g], livefraction=lf).union(api_trigger_names)
161  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.j, TriggerType.tau], livefraction=lf).union(api_trigger_names)
162  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.j, TriggerType.xe], livefraction=lf).union(api_trigger_names)
163  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.j, TriggerType.ht], livefraction=lf).union(api_trigger_names)
164  api_trigger_names = session.getLowestUnprescaled(triggerType=[TriggerType.bj, TriggerType.xe], livefraction=lf).union(api_trigger_names)
165 
166 
167  extra_flag_notau, extra_flag_tau = read_trig_list_flags(self.flags)
168  extra_flag = extra_flag_notau + extra_flag_tau
169 
170 
171  extra_file = read_trig_list_file("DerivationFrameworkPhys/run3ExtraMatchingTriggers.txt")
172 
173 
174  self.Run3TriggerNames = list(set(extra_file + extra_flag + list(api_trigger_names)))
175 
176  return
python.TriggerListsHelper.TriggerListsHelper.flags
flags
Definition: TriggerListsHelper.py:72
python.TriggerListsHelper.TriggerListsHelper.Run2TriggerNamesTau
Run2TriggerNamesTau
Definition: TriggerListsHelper.py:74
PathResolver::FindCalibFile
static std::string FindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.h:108
python.AutoConfigFlags.GetFileMD
def GetFileMD(filenames, allowEmpty=True)
Definition: AutoConfigFlags.py:51
python.TriggerListsHelper.TriggerListsHelper.Run2TriggerNamesNoTau
Run2TriggerNamesNoTau
See https://twiki.cern.ch/twiki/bin/view/Atlas/TriggerAPI Get single and multi mu,...
Definition: TriggerListsHelper.py:75
python.TriggerListsHelper.TriggerListsHelper.GetTriggerLists
def GetTriggerLists(self)
Definition: TriggerListsHelper.py:79
python.TriggerListsHelper.read_trig_list_flags
def read_trig_list_flags(flags)
Definition: TriggerListsHelper.py:22
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
python.TriggerListsHelper.read_trig_list_file
def read_trig_list_file(fname)
Definition: TriggerListsHelper.py:9
python.TriggerListsHelper.TriggerListsHelper
Definition: TriggerListsHelper.py:70
Trk::open
@ open
Definition: BinningType.h:40
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
str
Definition: BTagTrackIpAccessor.cxx:11
python.TriggerListsHelper.getTapisSession
def getTapisSession(flags)
Definition: TriggerListsHelper.py:32
python.TriggerListsHelper.TriggerListsHelper.Run3TriggerNames
Run3TriggerNames
Add Run 2 cross-triggers for some sets.
Definition: TriggerListsHelper.py:76
error
Definition: IImpactPoint3dEstimator.h:70
python.TriggerListsHelper.TriggerListsHelper.__init__
def __init__(self, flags)
Definition: TriggerListsHelper.py:71