ATLAS Offline Software
TrigTauInfo.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 TrigTauInfo::TrigTauInfo(const std::string& trigger)
8  : m_trigger{trigger}
9 {
10  parseTriggerString();
11 }
12 
13 TrigTauInfo::TrigTauInfo(const std::string& trigger, const std::map<std::string, float>& L1Phase1_thresholds)
14  : m_trigger{trigger}
15 {
16  parseTriggerString(L1Phase1_thresholds);
17 }
18 
19 TrigTauInfo::TrigTauInfo(const std::string& trigger, const std::map<std::string, float>& L1Phase1_thresholds, const std::map<std::string, uint64_t>& L1Phase1_threshold_patterns)
20  : m_trigger{trigger}
21 {
22  parseTriggerString(L1Phase1_thresholds, L1Phase1_threshold_patterns);
23 }
24 
25 TrigTauInfo::TrigTauInfo(const std::string& trigger, const std::map<int, int>& L1Phase1ThrMap_eTAU, const std::map<int, int>& L1Phase1ThrMap_jTAU)
26  : m_trigger{trigger}
27 {
28  parseTriggerString(L1Phase1ThrMap_eTAU, L1Phase1ThrMap_jTAU);
29 }
30 
31 void TrigTauInfo::parseTriggerString(bool remove_L1_phase1_thresholds)
32 {
33  std::string clean_trigger = m_trigger;
34 
35  // Change the "L1_" prefix to "L1" internally, in case the trigger being parsed is a pure L1 trigger with the usual L1 standalone naming scheme
36  if(clean_trigger.size() > 3 && clean_trigger.rfind("L1_", 0) == 0) {
37  clean_trigger = "L1" + clean_trigger.substr(3);
38  }
39 
40  std::vector<std::string> sections;
41  boost::split(sections, m_trigger, boost::is_any_of("_"));
42 
43  std::regex tau_rgx("^(\\d*)tau(\\d+)$");
44  std::regex elec_rgx("^(\\d*)e(\\d+)$");
45  std::regex muon_rgx("^(\\d*)mu(\\d+)$");
46  std::regex gamma_rgx("^(\\d*)g(\\d+)$");
47  std::regex jet_rgx("^(\\d*)j(\\d+)$");
48  std::regex met_rgx("^xe(\\d+)$");
49  std::regex noalg_rgx("^noalg$");
50  std::regex l1_rgx("^L1.*$");
51  std::regex l1_tau_rgx("(\\d*)(e|j|c|)TAU(\\d+)(L|M|T|HL|HM|HT|H|IM|I|)");
52  std::regex l1_toposeparate_rgx("^(\\d{0,2})(DETA|DPHI)(\\d{0,2})$");
53  std::regex topo_rgx("^.*(invm|dR|deta|dphi)AB.*$");
54  std::vector<std::regex*> all_regexes = {&tau_rgx, &elec_rgx, &muon_rgx, &gamma_rgx, &jet_rgx, &met_rgx, &l1_rgx};
55 
56  std::regex tau_type_rgx("^(ptonly|tracktwoMVA|tracktwoMVABDT|tracktwoLLP|trackLRT)$");
57  std::regex tau_ID_rgx("^(perf|idperf|veryloose.*|loose.*|medium.*|tight.*)$");
58 
59  std::smatch match;
60  std::regex_token_iterator<std::string::iterator> rend;
61 
62  // Check each leg
63  std::vector<std::string> leg;
64  for(size_t i = 0; i < sections.size(); i++) {
65  leg.push_back(sections[i]); // Attach to the current leg
66 
67  //Match the beginning of a new leg, or the end of the chain
68  if(i == sections.size() - 1 || (std::any_of(all_regexes.begin(), all_regexes.end(), [&sections, i](const std::regex* rgx) { return std::regex_match(sections[i+1], *rgx); }))) {
69  // Process the previous leg, which starts with the item, multiplicity, and threshold
70  if(std::regex_match(leg[0], match, tau_rgx)) {
71  size_t multiplicity = match[1].str() == "" ? 1 : std::stoi(match[1].str());
72  unsigned int threshold = std::stoi(match[2].str());
73 
74  // HLT Tau sequence
75  auto itr = find_if(leg.begin(), leg.end(), [tau_type_rgx](const std::string& s) { return std::regex_match(s, tau_type_rgx); });
76  std::string type = itr != leg.end() ? *itr : "";
77 
78  // HLT Tau ID
79  itr = find_if(leg.begin(), leg.end(), [tau_ID_rgx](const std::string& s) { return std::regex_match(s, tau_ID_rgx); });
80  std::string tau_id = itr != leg.end() ? *itr : "";
81  if(boost::starts_with(tau_id, "veryloose")) tau_id = tau_id.substr(9);
82  else if(boost::starts_with(tau_id, "loose")) tau_id = tau_id.substr(5);
83  else if(boost::starts_with(tau_id, "medium")) tau_id = tau_id.substr(6);
84  else if(boost::starts_with(tau_id, "tight")) tau_id = tau_id.substr(5);
85 
86  // Override for the old trigger names
87  if(tau_id == "RNN") {
88  if(type == "tracktwoMVA") tau_id = "DeepSet";
89  if(type == "tracktwoLLP" || type == "trackLRT") tau_id = "RNNLLP";
90  }
91 
92  // Replacements (this is temprary, the entire TrigTauInfo class will be removed soon, and all this will be handled centrally in Python using the already available infrastructure)
93  if(tau_id == "DS") tau_id = "DeepSet";
94  else if(tau_id == "GNT") tau_id = "GNTau";
95 
96  for(size_t j = 0; j < multiplicity; j++) {
97  m_HLTThr.push_back(threshold);
98  m_HLTTauTypes.push_back(type);
99  m_HLTTauIDs.push_back(tau_id);
100  }
101  } else if(std::regex_match(leg[0], match, elec_rgx)) {
102  size_t multiplicity = match[1].str() == "" ? 1 : std::stoi(match[1].str());
103  unsigned int threshold = std::stoi(match[2].str());
104  for(size_t j = 0; j < multiplicity; j++) m_HLTElecThr.push_back(threshold);
105  } else if(std::regex_match(leg[0], match, muon_rgx)) {
106  size_t multiplicity = match[1].str() == "" ? 1 : std::stoi(match[1].str());
107  unsigned int threshold = std::stoi(match[2].str());
108  for(size_t j = 0; j < multiplicity; j++) m_HLTMuonThr.push_back(threshold);
109  } else if(std::regex_match(leg[0], match, gamma_rgx)) {
110  size_t multiplicity = match[1].str() == "" ? 1 : std::stoi(match[1].str());
111  unsigned int threshold = std::stoi(match[2].str());
112  for(size_t j = 0; j < multiplicity; j++) m_HLTGammaThr.push_back(threshold);
113  } else if(std::regex_match(leg[0], match, jet_rgx)) {
114  size_t multiplicity = match[1].str() == "" ? 1 : std::stoi(match[1].str());
115  unsigned int threshold = std::stoi(match[2].str());
116  for(size_t j = 0; j < multiplicity; j++) m_HLTJetThr.push_back(threshold);
117  } else if(std::regex_match(leg[0], match, met_rgx)) {
118  unsigned int threshold = std::stoi(match[2].str());
119  m_HLTMETThr.push_back(threshold);
120  } else if(std::regex_match(leg[0], match, noalg_rgx)) {
121  m_isStreamer = true;
122  } else if(std::regex_match(leg[0], l1_rgx)) { // Treat the L1 items as a leg
123  for(size_t j = 0; j < leg.size(); j++) {
124  if(std::regex_match(leg[j], topo_rgx)) continue; // Remove HLT topo sections, not part of the L1 item
125 
126  // L1Topo items (they all include a "-" in the name, or have a separate "##DETA/PHI##_" prefix):
127  if(leg[j].find('-') != std::string::npos || std::regex_match(leg[j], l1_toposeparate_rgx)) {
128  // We only keep information from the legacy L1Topo item, from which we will not always use all thresholds
129  // Since we won't be adding any more Legacy thresholds, let's hard-code it...
130  if(leg[0] == "L1TAU60" && leg[j] == "DR-TAU12ITAU12I") leg[j] = "TAU12IM"; // L1_TAU60_DR-TAU20ITAU12I, uses "TAU12IM" threshold from the L1Topo item
131  else if(leg.size() == 1 && (leg[0] == "L1DR-TAU20ITAU12I" || leg[0] == "L1DR-TAU20ITAU12I-J25")) {
132  // Uses both TAU items, in the M isolation threshold
133  leg[0] = "L1TAU20IM";
134  leg.push_back("TAU12IM");
135  // Even on combined chains using jets, we don't use the jets threshold
136  }
137  else continue; // Remove the Phase 1 L1Topo items, since we always use a multiplicity threshold
138  }
139 
140  m_L1Items.push_back(j == 0 ? leg[j].substr(2, leg[j].size()) : leg[j]); // Remove the "L1" prefix on the first L1 item
141  }
142  }
143 
144  // Start a new leg
145  leg = {};
146  }
147  }
148 
149  if(!m_L1Items.empty()) {
150  // Build the full L1 string
151  m_L1Item = m_L1Items[0];
152  for(size_t j = 1; j < m_L1Items.size(); j++) m_L1Item += "_" + m_L1Items[j];
153 
154  // Get all individual L1 TAU items
155  std::regex_token_iterator<std::string::iterator> rgx_iter(m_L1Item.begin(), m_L1Item.end(), l1_tau_rgx);
156  while(rgx_iter != rend) {
157  std::string s = *rgx_iter;
158  std::regex_match(s, match, l1_tau_rgx);
159  size_t multiplicity = match[1].str() == "" ? 1 : std::stoi(match[1].str());
160  std::string item_type = match[2].str(); // e, j, c, or ""
161  int threshold = std::stoi(match[3].str());
162  std::string item_isolation = match[4].str(); // "", L, M, T, HL, HM, HT, IM, H
163 
164  // Set the Phase 1 thresholds to -1
165  if(remove_L1_phase1_thresholds && (item_type == "e" || item_type == "j" || item_type == "c")) threshold = -1;
166 
167  for(size_t j = 0; j < multiplicity; j++) {
168  m_tauL1Items.push_back(s.substr(match[1].str().size()));
169  m_tauL1Thr.push_back(threshold);
170  m_tauL1Type.push_back(item_type + "TAU");
171  m_tauL1Iso.push_back(item_isolation);
172  m_tauL1ThresholdPattern.push_back(-1);
173  }
174  rgx_iter++;
175  }
176 
177  m_L1Item = "L1" + m_L1Items[0];
178  }
179 }
180 
181 void TrigTauInfo::parseTriggerString(const std::map<std::string, float>& L1Phase1_thresholds)
182 {
184 
185  for(size_t i = 0; i < m_tauL1Items.size(); i++) {
186  if(m_tauL1Type.at(i) == "TAU") continue; // Skip the legacy items
187 
188  const std::string& item = m_tauL1Items.at(i);
189 
190  m_tauL1Thr[i] = L1Phase1_thresholds.at(item);
191  }
192 }
193 
194 void TrigTauInfo::parseTriggerString(const std::map<std::string, float>& L1Phase1_thresholds, const std::map<std::string, uint64_t>& L1Phase1_threshold_patterns)
195 {
197 
198  for(size_t i = 0; i < m_tauL1Items.size(); i++) {
199  if(m_tauL1Type.at(i) == "TAU") continue; // Skip the legacy items
200 
201  const std::string& item = m_tauL1Items.at(i);
202 
203  m_tauL1Thr[i] = L1Phase1_thresholds.at(item);
204  m_tauL1ThresholdPattern[i] = L1Phase1_threshold_patterns.at(item);
205  }
206 }
207 
208 void TrigTauInfo::parseTriggerString(const std::map<int, int>& L1Phase1ThrMap_eTAU, const std::map<int, int>& L1Phase1ThrMap_jTAU)
209 {
210  parseTriggerString(false);
211 
212  // Correct the Phase 1 thresholds:
213  for(size_t i = 0; i < m_tauL1Items.size(); i++) {
214  const std::string& item_type = m_tauL1Type.at(i);
215  if(item_type == "eTAU" || item_type == "cTAU") {
216  m_tauL1Thr[i] = L1Phase1ThrMap_eTAU.at(m_tauL1Thr.at(i));
217  } else if(item_type == "jTAU") {
218  m_tauL1Thr[i] = L1Phase1ThrMap_jTAU.at(m_tauL1Thr.at(i));
219  }
220  }
221 }
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
TrigTauInfo::m_HLTElecThr
std::vector< float > m_HLTElecThr
Definition: TrigTauInfo.h:86
TrigTauInfo::m_HLTTauIDs
std::vector< std::string > m_HLTTauIDs
Definition: TrigTauInfo.h:76
TrigTauInfo::m_L1Item
std::string m_L1Item
Definition: TrigTauInfo.h:78
TrigTauInfo::m_HLTMETThr
std::vector< float > m_HLTMETThr
Definition: TrigTauInfo.h:90
TrigTauInfo::m_isStreamer
bool m_isStreamer
Definition: TrigTauInfo.h:73
TrigTauInfo::m_L1Items
std::vector< std::string > m_L1Items
Definition: TrigTauInfo.h:79
TrigTauInfo::m_HLTMuonThr
std::vector< float > m_HLTMuonThr
Definition: TrigTauInfo.h:87
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigTauInfo::m_tauL1ThresholdPattern
std::vector< int64_t > m_tauL1ThresholdPattern
Definition: TrigTauInfo.h:84
TrigTauInfo::m_trigger
std::string m_trigger
Definition: TrigTauInfo.h:72
compute_lumi.leg
leg
Definition: compute_lumi.py:95
TrigTauInfo::m_HLTJetThr
std::vector< float > m_HLTJetThr
Definition: TrigTauInfo.h:89
TrigTauInfo::m_tauL1Items
std::vector< std::string > m_tauL1Items
Definition: TrigTauInfo.h:81
TrigTauInfo::m_HLTTauTypes
std::vector< std::string > m_HLTTauTypes
Definition: TrigTauInfo.h:75
threshold
Definition: chainparser.cxx:74
item
Definition: ItemListSvc.h:43
TrigTauInfo::TrigTauInfo
TrigTauInfo()
Definition: TrigTauInfo.h:17
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
TrigTauInfo::m_HLTGammaThr
std::vector< float > m_HLTGammaThr
Definition: TrigTauInfo.h:88
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrigTauInfo::m_tauL1Type
std::vector< std::string > m_tauL1Type
Definition: TrigTauInfo.h:82
TrigTauInfo.h
TrigTauInfo::m_tauL1Iso
std::vector< std::string > m_tauL1Iso
Definition: TrigTauInfo.h:83
python.prefilter_mask.rgx
rgx
Definition: prefilter_mask.py:14
TrigTauInfo::m_tauL1Thr
std::vector< float > m_tauL1Thr
Definition: TrigTauInfo.h:80
TrigTauInfo::parseTriggerString
void parseTriggerString(bool remove_L1_phase1_thresholds=true)
Definition: TrigTauInfo.cxx:31
TrigTauInfo::m_HLTThr
std::vector< float > m_HLTThr
Definition: TrigTauInfo.h:74
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356