Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ImportData.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // contact: jmaurer@cern.ch
6 
9 
10 #include <fstream>
11 #include <functional>
12 #include <algorithm>
13 #include <limits>
14 
16 
19  asg::AsgMessaging("TrigGlobalEfficiencyCorrectionTool"),
20  m_parent(nullptr),
21  m_dictionary(*new std::map<std::size_t,std::string>),
22  m_hasher(*new std::hash<std::string>)
23 {
24 }
25 
27  asg::AsgMessaging(&parent),
28  m_parent(&parent),
29  m_dictionary(parent.m_dictionary),
30  m_hasher(parent.m_hasher)
31 {
32  msg().setLevel(parent.msg().level());
33 }
34 
36 {
37  if(!m_parent)
38  {
39  delete &m_dictionary;
40  delete &m_hasher;
41  }
42 }
43 
44 bool ImportData::importAll(const std::map<std::string, std::string>& overridenThresholds)
45 {
46  return importPeriods()
47  && importThresholds(overridenThresholds)
48  && importTriggers()
49  && importHierarchies();
50 }
51 
52 bool ImportData::readDataFile(const char* filename, std::vector<std::string>& contents)
53 {
54  contents.clear();
55  bool success = true;
57  if(name.length())
58  {
59  std::ifstream f(name.c_str(),std::ios_base::in);
60  if(f.is_open())
61  {
62  std::string line;
63  while(f.good())
64  {
65  if(std::getline(f,line))
66  {
67  const std::string::size_type i = line.find('#');
68  if(i != std::string::npos) line.resize(i);
69  if(line.length() >= 3) contents.emplace_back(std::move(line));
70  }
71  }
72  if(!f.eof())
73  {
74  ATH_MSG_ERROR("Issue encountered while reading configuration file " << filename);
75  success = false;
76  }
77  f.close();
78  return true;
79  }
80  else
81  {
82  ATH_MSG_ERROR("Unable to open configuration file " << filename);
83  success = false;
84  }
85  }
86  else
87  {
88  ATH_MSG_ERROR("Unable to find configuration file " << filename);
89  success = false;
90  }
91  return success;
92 }
93 
95 {
96  if(def.leg[0]==def.leg[1] && def.leg[1]==def.leg[2]) def.type = static_cast<TriggerType>(TT_TRILEPTON_SYM | flavourFlag);
97  else if(def.leg[0]!=def.leg[1] && def.leg[1]!=def.leg[2] && def.leg[0]!=def.leg[2]) def.type = static_cast<TriggerType>(TT_TRILEPTON_ASYM | flavourFlag);
98  else
99  {
100  if(def.leg[1]!=def.leg[0] && def.leg[1]!=def.leg[2]) std::swap(def.leg[0],def.leg[1]);
101  else if(def.leg[2]!=def.leg[0] && def.leg[2]!=def.leg[1]) std::swap(def.leg[0],def.leg[2]);
102  def.type = static_cast<TriggerType>(TT_TRILEPTON_HALFSYM | flavourFlag);
103  }
104 }
105 
107 {
108  if(!m_triggerThresholds.size() && !importThresholds()) return false;
109  m_triggerDefs.clear();
110  std::vector<std::string> config;
111  if(!readDataFile("TrigGlobalEfficiencyCorrection/Triggers.cfg", config)) return false;
112  std::stringstream ss;
113  std::string triggerName, token;
114  bool success = true;
115  for(auto& line : config)
116  {
118  ss.clear();
119  ss.str(line);
120  ss >> triggerName;
121  std::size_t h = m_hasher(triggerName);
122  auto& def = m_triggerDefs[h];
123  def.name = h;
124 
125  ss.clear();
126  ss.str(line);
127  ss >> triggerName;
128  m_dictionary[h] = triggerName;
129  ATH_MSG_DEBUG(std::to_string(h) << " " << triggerName );
130 
131  bool hasTauLeg{};
132  for(std::size_t& leg : def.leg)
133  {
134  if(!(ss >> token)) break;
135  auto flavour = associatedLeptonFlavour(token, success);
136  if (flavour == xAOD::Type::Tau)
137  {
138  // we don't support taus for now
139  leg = 0;
140  hasTauLeg = true;
141  }
142  else
143  {
144  h = m_hasher(token);
145  m_dictionary.emplace(h,token);
146  leg = h;
147  if(m_triggerThresholds.find(h) == m_triggerThresholds.end())
148  {
149  ATH_MSG_ERROR("Unknown trigger leg '" << token << "' found in Triggers.cfg");
150  success = false;
151  }
152  }
153  }
154  if(!def.leg[0])
155  {
156  def.leg[0] = h;
157  if(m_triggerThresholds.find(h) == m_triggerThresholds.end())
158  {
159  ATH_MSG_ERROR("Unknown trigger leg '" << triggerName << "' (inferred from trigger name) found in Triggers.cfg");
160  success = false;
161  }
162  }
163  if(!success) continue;
164 
166  def.type = TT_UNKNOWN;
167  // triggers with tau legs should stay unknown
168  if (hasTauLeg) {
169  continue;
170  }
171 
172  auto flavour0 = associatedLeptonFlavour(def.leg[0], success);
173  int ne = (flavour0 == xAOD::Type::Electron)*1;
174  int nm = (flavour0 == xAOD::Type::Muon)*1;
175  if(def.leg[1])
176  {
177  auto flavour1 = associatedLeptonFlavour(def.leg[1], success);
178  if(flavour1 == xAOD::Type::Electron)
179  {
180  if(!ne) std::swap(def.leg[0],def.leg[1]);
181  ++ne;
182  }
183  else if(flavour1 == xAOD::Type::Muon)
184  {
185  if(!(ne+nm)) std::swap(def.leg[0],def.leg[1]);
186  ++nm;
187  }
188  else if(flavour1 != xAOD::Type::Photon) success = false;
189  if(def.leg[2])
190  {
191  auto flavour2 = associatedLeptonFlavour(def.leg[2], success);
192  if(flavour2 == xAOD::Type::Electron)
193  {
194  if(!ne) std::swap(def.leg[0], def.leg[2]);
195  else if(ne==1) std::swap(def.leg[1], def.leg[2]);
196  ++ne;
197  }
198  else if(flavour2 == xAOD::Type::Muon)
199  {
200  if(!(ne+nm)) std::swap(def.leg[0], def.leg[2]);
201  else if((ne+nm)==1) std::swap(def.leg[1], def.leg[2]);
202  ++nm;
203  }
204  else if(flavour2 != xAOD::Type::Photon) success = false;
205  if(def.leg[3])
206  {
208  if(std::count(def.leg.cbegin(),
209  def.leg.cend(),
210  def.leg[0]) == 4)
211  {
212  def.type = nm? TT_4MU_SYM : TT_4E_SYM;
213  }
214  else success = false;
215  }
216  else if(ne+nm==0 || ne==3 || nm==3)
217  {
219  }
220  else
221  {
222  bool sym = (def.leg[0]==def.leg[1] || def.leg[1]==def.leg[2]);
223  if(ne==2) def.type = nm? (sym? TT_2E_MU_SYM : TT_2E_MU_ASYM) : (sym? TT_2E_G_SYM : TT_2E_G_ASYM);
224  else if(nm==2) def.type = ne? (sym? TT_E_2MU_SYM : TT_E_2MU_ASYM) : (sym? TT_2MU_G_SYM : TT_2MU_G_ASYM);
225  else if(ne+nm==1) def.type = ne? (sym? TT_E_2G_SYM : TT_E_2G_ASYM) : (sym? TT_MU_2G_SYM : TT_MU_2G_ASYM);
226  else success = false;
227  }
228  }
229  else
230  {
231  if(ne==2) def.type = (def.leg[0]==def.leg[1])? TT_2E_SYM : TT_2E_ASYM;
232  else if(nm==2) def.type = (def.leg[0]==def.leg[1])? TT_2MU_SYM : TT_2MU_ASYM;
233  else if(ne+nm==0) def.type = (def.leg[0]==def.leg[1])? TT_2G_SYM : TT_2G_ASYM;
234  else if(ne==1 && nm==1) def.type = TT_E_MU;
235  else if(ne==1) def.type = TT_E_G;
236  else if(nm==1) def.type = TT_MU_G;
237  }
238  }
239  else
240  {
241  def.type = ne? TT_SINGLE_E : nm? TT_SINGLE_MU : TT_SINGLE_G;
242  }
243  if(!success || def.type==TT_UNKNOWN)
244  {
245  success = false;
246  ATH_MSG_ERROR("Configuration issue for trigger " << triggerName);
247  }
248  }
249  return success;
250 }
251 
252 bool ImportData::importThresholds(const std::map<std::string, std::string>& overridenThresholds)
253 {
254  m_triggerThresholds.clear();
255  std::vector<std::string> config;
256  if(!readDataFile("TrigGlobalEfficiencyCorrection/Thresholds.cfg", config)) return false;
257  std::stringstream ss;
258  std::string leg, unit;
259  float pt;
260  bool success = true;
261  for(auto& line : config)
262  {
263  ss.clear();
264  ss.str(line);
265  if(ss >> leg >> pt >> unit)
266  {
267  std::size_t h = m_hasher(leg);
268  m_dictionary.emplace(h,leg);
269  if(unit == "GeV") pt *= 1e3f;
270  else if(unit != "MeV")
271  {
272  ATH_MSG_ERROR("Unable to import pT threshold for leg \"" << leg << "\" (missing unit)");
273  success = false;
274  }
276  }
277  else
278  {
279  ATH_MSG_ERROR("Unable to import pT threshold for leg \"" << leg << '"');
280  success = false;
281  }
282  }
283  if(!success)
284  {
285  m_triggerThresholds.clear();
286  return false;
287  }
288 
290  bool belowRecommended = false;
291  for(auto& kv : overridenThresholds)
292  {
293  auto itr = m_triggerThresholds.find(m_hasher(kv.first));
294  if(itr != m_triggerThresholds.end())
295  {
296  float pt = 0.f;
297  try { pt = std::stof(kv.second); }
298  catch(...)
299  {
300  ATH_MSG_ERROR("Unable to convert threshold argument \""<<kv.second<<"\" to floating-point value");
301  success = false;
302  continue;
303  }
304  if(pt<1e3f)
305  {
306  ATH_MSG_WARNING("Suspiciously low threshold (" << pt << " MeV) set for trigger leg " << kv.first
307  << ", please make sure you provided the threshold in MeV and not in GeV!");
308  }
309  if(pt < itr->second) belowRecommended = true;
310  itr->second = pt;
311  }
312  else
313  {
314  ATH_MSG_ERROR("Can't override threshold for unknown trigger leg " << kv.first);
315  success = false;
316  }
317  }
318  if(belowRecommended)
319  {
320  ATH_MSG_WARNING("Tool configured to use trigger thresholds below those recommended!");
321  }
322  return success;
323 }
324 
326 {
327  m_dataPeriods.clear();
328  std::vector<std::string> config;
329  if(!readDataFile("TrigGlobalEfficiencyCorrection/DataPeriods.cfg", config)) return false;
330  std::stringstream ss;
331  std::string key;
332  std::pair<unsigned,unsigned> runs;
333  for(auto& line : config)
334  {
335  ss.clear();
336  ss.str(line);
337  ss >> key >> runs.first >> runs.second;
338  if(ss.fail())
339  {
340  m_dataPeriods.clear();
341  return false;
342  }
343  m_dataPeriods.emplace(key,runs);
344  }
345  return true;
346 }
347 
349 {
350  if(!m_triggerThresholds.size() && !importThresholds()) return false;
351  m_hierarchyMeta.clear();
352  m_hierarchyData.clear();
353  std::vector<std::string> config;
354  if(!readDataFile("TrigGlobalEfficiencyCorrection/Hierarchies.cfg", config)) return false;
355  std::stringstream ss;
356  std::string token, unit;
357  std::map<std::size_t, std::vector<std::size_t> > aliases;
358  for(auto& line : config)
359  {
360  bool success = true;
361  ss.clear();
362  ss.str(line);
363  if(line[0]=='[')
364  {
365  auto& meta = *m_hierarchyMeta.emplace(m_hierarchyMeta.end(), Hierarchy{(short)m_hierarchyData.size(),0,0.f,std::numeric_limits<float>::max()});
366  if(line[1]=='-' && line[2]==']') ss.ignore(3);
367  else
368  {
369  char sep = '-';
370  if(line[1]=='>') ss.ignore(2) >> meta.minPt >> unit;
371  else if(line[1]=='<') ss.ignore(2) >> meta.maxPt >> unit;
372  else ss.ignore(1) >> meta.minPt >> sep >> meta.maxPt >> unit;
373  if(!ss || sep!='-' || (unit!="GeV]" && unit!="MeV]"))
374  {
375  ATH_MSG_ERROR("Unable to parse pT restrictions in Hierarchies.cfg");
376  success = false;
377  }
378  if(unit == "GeV]")
379  {
380  meta.minPt *= 1e3f;
381  if(meta.maxPt < std::numeric_limits<float>::max()) meta.maxPt *= 1e3f;
382  }
383  }
384  while(ss >> token)
385  {
386  std::size_t h = m_hasher(token);
387  auto itr = aliases.find(h);
388  if(itr == aliases.end())
389  {
390  if(m_triggerThresholds.find(h) == m_triggerThresholds.end())
391  {
392  ATH_MSG_ERROR("Unknown trigger leg '" << token << "' found in Hierarchies.cfg");
393  success = false;
394  }
395  m_dictionary.emplace(h,token);
396  m_hierarchyData.push_back(h);
397  }
398  else m_hierarchyData.insert(m_hierarchyData.end(),itr->second.begin(),itr->second.end());
399  if(ss >> token && token!=">") success = false;
400  }
401  meta.nLegs = m_hierarchyData.size() - meta.offset;
402  success = success && meta.nLegs;
403  }
404  else
405  {
406  ss >> token;
407  auto& legs = aliases[m_hasher(token)];
408  if(ss >> token && token==":=")
409  {
410  legs.clear();
411  while(ss >> token)
412  {
413  std::size_t h = m_hasher(token);
414  m_dictionary.emplace(h,token);
415  legs.push_back(h);
416  if(m_triggerThresholds.find(h) == m_triggerThresholds.end())
417  {
418  ATH_MSG_ERROR("Unknown trigger leg '" << token << "' found in Hierarchies.cfg");
419  success = false;
420  }
421  if(ss >> token && token!=">") success = false;
422  }
423  success = success && legs.size();
424  }
425  else success = false;
426  }
427  if(!success)
428  {
429  ATH_MSG_ERROR("Failed parsing line from Hierarchies.cfg:\n" << line);
430  m_hierarchyMeta.clear();
431  m_hierarchyData.clear();
432  return false;
433  }
434  }
435  return true;
436 }
437 
438 bool ImportData::importMapKeys(const std::string& version, std::map<std::size_t,std::map<std::size_t,int> >& keysPerLeg)
439 {
440  keysPerLeg.clear();
441  std::vector<std::string> config;
442  if(!readDataFile("TrigGlobalEfficiencyCorrection/MapKeys.cfg", config)) return false;
443  std::stringstream ss;
444  std::string token;
445  bool reading = false;
446  for(auto& line : config)
447  {
448  std::size_t pos = line.find("[VERSION]");
449  if(pos != std::string::npos)
450  {
451  reading = false;
452  ss.clear();
454  while(std::getline(ss, token, ','))
455  {
456  if(token == version)
457  {
458  reading = true;
459  break;
460  }
461  }
462  continue;
463  }
464  if(!reading) continue;
465  ss.clear();
466  ss.str(line);
467  int year;
468  ss >> year >> token;
469  year = 1<<(year-2015);
470  std::size_t leg = m_hasher(token);
471  auto& keys = keysPerLeg[leg];
472  while(ss >> token)
473  {
474  std::size_t h = m_hasher(token);
475  auto insertion = keys.emplace(h, year);
476  if(insertion.second) m_dictionary.emplace(h, token);
477  else insertion.first->second |= year;
478  }
479  }
480  if(!keysPerLeg.size())
481  {
482  ATH_MSG_ERROR("Unable to import the available map keys for the version " << version);
483  return false;
484  }
485  return true;
486 }
487 
488 bool ImportData::getPeriodBoundaries(const std::string& period, std::pair<unsigned,unsigned>& boundaries)
489 {
490  // First possibility: a defined period keyword
491  auto itr = m_dataPeriods.find(period);
492  if(itr!=m_dataPeriods.end())
493  {
494  boundaries = itr->second;
495  return true;
496  }
497  // Otherwise it's a '-'-separated range
498  auto sep = period.find_first_of('-');
499  if(sep!=std::string::npos)
500  {
501  std::string kwMin = period.substr(0,sep);
502  std::string kwMax = period.substr(sep+1);
503  // Second possibility: a range of defined period keywords
504  auto itrMin = m_dataPeriods.find(kwMin);
505  auto itrMax = m_dataPeriods.find(kwMax);
506  if(itrMin!=m_dataPeriods.end() && itrMax!=m_dataPeriods.end())
507  {
508  boundaries = std::minmax({itrMin->second.first, itrMax->second.first, itrMin->second.second, itrMax->second.second});
509  return true;
510  }
511  // Third possibility: a range of run numbers
512  try
513  {
514  boundaries = std::minmax(std::stoi(kwMin), std::stoi(kwMax));
515  return true;
516  }
517  catch(...) {}
518  }
519  ATH_MSG_ERROR("Unable to understand the period/range " << period);
520  return false;
521 }
522 
524 {
525  // note: 'success' is not set to 'true', only downgraded to 'false' if needed
526  if(leg.length()>=2 && leg[0]=='e' && leg[1]>='1' && leg[1]<='9') return xAOD::Type::Electron;
527  else if(leg.length()>=3 && leg[0]=='m' && leg[1]=='u' && leg[2]>='1' && leg[2]<='9') return xAOD::Type::Muon;
528  else if(leg.length()>=3 && leg[0]=='g' && leg[1]>='1' && leg[1]<='9') return xAOD::Type::Photon;
529  else if(leg.length()>=4 && leg[0]=='t' && leg[1]=='a' && leg[2]=='u' && leg[3]>='1' && leg[3]<='9') return xAOD::Type::Tau;
530  success = false;
531  return xAOD::Type::Other;
532 }
533 
535 {
536  // note: 'success' is not set to 'true', only downgraded to 'false' if needed
537  auto itr = m_dictionary.find(leg);
538  if(itr != m_dictionary.end())
539  {
540  return associatedLeptonFlavour(itr->second,success);
541  }
542  success = false;
543  return xAOD::Type::Other;
544 }
545 
546 std::vector<ImportData::TrigDef> ImportData::parseTriggerString(const std::string& triggerString, bool& success)
547 {
548  std::string s = TrigGlobEffCorr::removeWhitespaces(triggerString);
549  if(s.find("|||") != std::string::npos)
550  {
551  ATH_MSG_ERROR("Invalid format for the trigger combination '" << triggerString <<"'");
552  success = false;
553  return {};
554  }
556  while(true)
557  {
558  auto i = s.find("||");
559  if(i == std::string::npos) break;
560  s.replace(i, 1, "");
561  }
562  if(s=="" || s=="|")
563  {
564  ATH_MSG_ERROR("Invalid format for the trigger combination '" << triggerString <<"'");
565  success = false;
566  return {};
567  }
568  std::vector<TrigDef> triggers;
569  std::set<std::size_t> hashes;
570  std::stringstream ss(s);
571  while(std::getline(ss,s,'|'))
572  {
573  std::size_t trig = m_hasher(s);
574  ATH_MSG_DEBUG(std::to_string(trig) << " --> " << s );
575  auto itr = m_triggerDefs.find(trig);
576  if(itr == m_triggerDefs.end())
577  {
578  ATH_MSG_ERROR("Unknown trigger '" << s << "' found while parsing trigger combination");
579  success = false;
580  return {};
581  }
582  if(!hashes.insert(trig).second)
583  {
584  ATH_MSG_ERROR("The trigger '" << s << "' is present more than once in the combination");
585  success = false;
586  return {};
587  }
588  triggers.push_back(itr->second);
589  }
590  success = success && triggers.size();
591  return triggers;
592 }
593 
594 bool ImportData::suggestEgammaMapKeys(const std::map<std::string,std::string>& triggerCombination,
595  const std::string& version,
596  std::map<std::string,std::string>& legsPerKey,
598 {
599  legsPerKey.clear();
600  if(!importAll()) return false;
601 
602  bool success = true;
603  std::map<std::size_t,int> legs;
604 
605  for(auto& kv : triggerCombination)
606  {
607  auto itrPeriod = m_dataPeriods.find(kv.first);
608  if(itrPeriod == m_dataPeriods.end())
609  {
610  ATH_MSG_ERROR("Unknown period " << kv.first);
611  success = false;
612  continue;
613  }
614  int years = 0;
615  for(int k=0;k<32;++k)
616  {
617  auto itr = m_dataPeriods.find(std::to_string(2015+k));
618  if(itr != m_dataPeriods.end() && itrPeriod->second.first <= itr->second.second
619  && itrPeriod->second.second >= itr->second.first)
620  {
621  years |= (1<<k);
622  }
623  }
624  auto triggers = parseTriggerString(kv.second,success);
625  if(!success) continue;
626  for(auto& trig : triggers)
627  {
628  for(std::size_t leg : trig.leg)
629  {
630  if(leg && associatedLeptonFlavour(leg, success)==type)
631  {
632  auto insertion = legs.emplace(leg,years);
633  if(!insertion.second) insertion.first->second |= years;
634  }
635  }
636  }
637  }
638  if(!success) return false;
639 
640  if(version != "")
641  {
642  std::map<std::size_t,std::map<std::size_t,int> > allKeys;
643  if(!importMapKeys(version, allKeys)) return false;
644  std::map<std::size_t,std::vector<std::size_t> > allLegsPerKey;
645  std::set<std::size_t> legsWithMultipleKeys;
646  bool sameKeyForAllyears = true;
647  while(legs.size())
648  {
649  allLegsPerKey.clear();
650  for(auto& kvLegs : legs) // loop on remaining legs
651  {
652  std::size_t leg = kvLegs.first;
653  int years = kvLegs.second;
654  auto itrKeys = allKeys.find(leg); // list of keys for that leg
655  if(itrKeys != allKeys.end())
656  {
657  for(auto& kvKeys : itrKeys->second) // loop on those keys
658  {
659  auto y = (kvKeys.second & years);
660  if((y==years) || (!sameKeyForAllyears && y!=0)) // key must support all years needed for that leg -- until no longer possible
661  {
662  auto insertion = allLegsPerKey.emplace(kvKeys.first,std::vector<std::size_t>{leg});
663  if(!insertion.second) insertion.first->second.push_back(leg);
664  }
665  }
666  }
667  else
668  {
669  ATH_MSG_ERROR("Sorry, no idea what the map key should be for the trigger leg '"
670  << m_dictionary.at(leg) << "', manual configuration is needed");
671  success = false;
672  }
673  }
674  if(!success) break;
675 
676  if(!allLegsPerKey.size())
677  {
678  if(sameKeyForAllyears)
679  {
680  sameKeyForAllyears = false;
681  continue;
682  }
683  success = false;
684  break;
685  }
686 
687  using T = decltype(allLegsPerKey)::value_type;
688  auto itrKey = std::max_element(allLegsPerKey.begin(), allLegsPerKey.end(),
689  [](T& x,T& y){return x.second.size()<y.second.size();});
690  std::string& strLegs = legsPerKey[m_dictionary.at(itrKey->first)];
691  for(std::size_t leg : itrKey->second)
692  {
693  int& wantedYears = legs.at(leg);
694  int supportedYears = (allKeys.at(leg).at(itrKey->first)) & wantedYears;
695  if(supportedYears!=wantedYears || legsWithMultipleKeys.count(leg))
696  {
697  legsWithMultipleKeys.insert(leg);
698  for(int i=0;i<32;++i)
699  {
700  if(supportedYears & (1u<<i))
701  {
702  if(strLegs.length() && strLegs.back()!=',') strLegs += ',';
703  strLegs += m_dictionary.at(leg) + "[" + std::to_string(2015 + i) + "]";
704  }
705  }
706  }
707  else
708  {
709  if(strLegs.length() && strLegs.back()!=',') strLegs += ',';
710  strLegs += m_dictionary.at(leg);
711  }
712  if(supportedYears == wantedYears) legs.erase(leg);
713  else wantedYears &= ~supportedYears;
714  }
715  }
716  }
717  else
718  {
720  for(auto& kv : legs)
721  {
722  legsPerKey.emplace(std::to_string(legsPerKey.size()), m_dictionary.at(kv.first));
723  }
724  }
725  for (auto& [key, legs]: legsPerKey)
726  {
728  {
729  ATH_MSG_WARNING("Some of the requested triggers will result in "
730  "a default scale factor of 1 being returned");
731  }
732  }
733  if(!success) legsPerKey.clear();
734  return success;
735 }
736 
737 bool ImportData::adaptTriggerListForTriggerMatching(std::vector<ImportData::TrigDef>& triggers)
738 {
740  std::set<std::size_t> extraItems;
741  std::vector<ImportData::TrigDef> updatedTriggers;
742  for(auto& trig : triggers)
743  {
744  auto& name = m_dictionary.at(trig.name);
745  std::size_t pos = 0, len = name.find("_OR_");
746  if(len == std::string::npos)
747  {
748  updatedTriggers.emplace_back(trig);
749  continue;
750  }
751  while(true)
752  {
753  std::string item = name.substr(pos, len);
754  auto h = m_hasher(item);
755  auto def = m_triggerDefs.find(h);
756  if(def == m_triggerDefs.end())
757  {
758  ATH_MSG_ERROR("while listing triggers for trigger matching; trigger \"" << item << "\" extracted from \"" << name << "\" is not recognized");
759  return false;
760  }
761  if(extraItems.emplace(h).second) updatedTriggers.emplace_back(def->second);
762  if(len == std::string::npos) break;
763  pos += len + 4;
764  len = name.find("_OR_", pos);
765  if(len != std::string::npos) len -= pos;
766  }
767  }
768  triggers.swap(updatedTriggers);
769  return true;
770 }
python.root_lsr_rank.hashes
hashes
Definition: root_lsr_rank.py:34
TrigGlobEffCorr::TT_E_MU
@ TT_E_MU
Definition: ImportData.h:48
TrigGlobEffCorr::ImportData::importMapKeys
bool importMapKeys(const std::string &tag, std::map< std::size_t, std::map< std::size_t, int > > &keysPerLeg)
Definition: ImportData.cxx:438
python.AtlRunQueryAMI.period
period
Definition: AtlRunQueryAMI.py:225
TrigGlobEffCorr::TT_2MU_SYM
@ TT_2MU_SYM
Definition: ImportData.h:46
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
TrigGlobEffCorr::TT_2E_MU_SYM
@ TT_2E_MU_SYM
Definition: ImportData.h:64
checkFileSG.line
line
Definition: checkFileSG.py:75
TrigGlobEffCorr::TT_2G_ASYM
@ TT_2G_ASYM
Definition: ImportData.h:50
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
TrigGlobEffCorr::TT_SINGLE_MU
@ TT_SINGLE_MU
Definition: ImportData.h:38
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ObjectType
ObjectType
Definition: BaseObject.h:11
TrigGlobEffCorr::ImportData::m_dataPeriods
std::map< std::string, std::pair< unsigned, unsigned > > m_dataPeriods
Definition: ImportData.h:147
TrigGlobEffCorr::ImportData::adaptTriggerListForTriggerMatching
bool adaptTriggerListForTriggerMatching(std::vector< ImportData::TrigDef > &triggers)
Definition: ImportData.cxx:737
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
TrigGlobEffCorr::ImportData::getPeriodBoundaries
bool getPeriodBoundaries(const std::string &period, std::pair< unsigned, unsigned > &boundaries)
Definition: ImportData.cxx:488
python.base_data.config
config
Definition: base_data.py:21
find_tgc_unfilled_channelids.runs
int runs
Definition: find_tgc_unfilled_channelids.py:10
TrigGlobEffCorr::ImportData::~ImportData
~ImportData()
Definition: ImportData.cxx:35
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
asg
Definition: DataHandleTestTool.h:28
test_pyathena.pt
pt
Definition: test_pyathena.py:11
TrigGlobEffCorr::TT_2E_ASYM
@ TT_2E_ASYM
Definition: ImportData.h:45
TrigGlobEffCorr::TT_E_2MU_SYM
@ TT_E_2MU_SYM
Definition: ImportData.h:65
TrigGlobEffCorr::TT_SINGLE_E
@ TT_SINGLE_E
Definition: ImportData.h:37
python.TrigTLAMonitorAlgorithm.triggers
triggers
Definition: TrigTLAMonitorAlgorithm.py:196
TrigGlobEffCorr::ImportData::importHierarchies
bool importHierarchies()
Definition: ImportData.cxx:348
python.AtlRunQueryAMI.year
year
Definition: AtlRunQueryAMI.py:226
x
#define x
TrigGlobEffCorr::TT_MUON_FLAG
@ TT_MUON_FLAG
Definition: ImportData.h:27
TrigGlobEffCorr::TT_E_2MU_ASYM
@ TT_E_2MU_ASYM
Definition: ImportData.h:67
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
TrigGlobEffCorr::TT_ELECTRON_FLAG
@ TT_ELECTRON_FLAG
Definition: ImportData.h:26
ImportData.h
TrigGlobEffCorr::TT_2MU_G_SYM
@ TT_2MU_G_SYM
Definition: ImportData.h:75
TrigGlobEffCorr::ImportData::parseTriggerString
std::vector< TrigDef > parseTriggerString(const std::string &triggerString, bool &success)
Definition: ImportData.cxx:546
TrigGlobEffCorr::TT_2G_SYM
@ TT_2G_SYM
Definition: ImportData.h:49
TrigGlobEffCorr::ImportData::m_hierarchyData
std::vector< std::size_t > m_hierarchyData
Definition: ImportData.h:149
TrigGlobEffCorr::TT_2E_SYM
@ TT_2E_SYM
Definition: ImportData.h:44
TrigGlobEffCorr::TT_MU_2G_ASYM
@ TT_MU_2G_ASYM
Definition: ImportData.h:78
TrigGlobEffCorr::ImportData::importThresholds
bool importThresholds(const std::map< std::string, std::string > &overridenThresholds={})
Definition: ImportData.cxx:252
TrigGlobEffCorr::ImportData::TrigDef::leg
std::array< std::size_t, 4 > leg
Definition: ImportData.h:96
TrigGlobEffCorr::TT_2E_MU_ASYM
@ TT_2E_MU_ASYM
Definition: ImportData.h:66
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TrigGlobEffCorr::ImportData::m_hierarchyMeta
std::vector< Hierarchy > m_hierarchyMeta
Definition: ImportData.h:148
TrigGlobEffCorr::TT_PHOTON_FLAG
@ TT_PHOTON_FLAG
Definition: ImportData.h:28
TrigGlobEffCorr::ImportData::ImportData
ImportData()
Definition: ImportData.cxx:17
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigGlobEffCorr::ImportData::associatedLeptonFlavour
xAOD::Type::ObjectType associatedLeptonFlavour(std::size_t leg, bool &success)
Definition: ImportData.cxx:534
TrigGlobEffCorr::TT_TRILEPTON_ASYM
@ TT_TRILEPTON_ASYM
Definition: ImportData.h:57
TrigGlobEffCorr::ImportData
Definition: ImportData.h:88
extractSporadic.h
list h
Definition: extractSporadic.py:97
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TrigGlobEffCorr::TT_TRILEPTON_HALFSYM
@ TT_TRILEPTON_HALFSYM
Definition: ImportData.h:56
asg::AsgMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AsgMessaging.cxx:49
test_pyathena.parent
parent
Definition: test_pyathena.py:15
compute_lumi.leg
leg
Definition: compute_lumi.py:95
TrigGlobEffCorr::ImportData::importPeriods
bool importPeriods()
Definition: ImportData.cxx:325
hist_file_dump.f
f
Definition: hist_file_dump.py:141
TrigGlobEffCorr::TT_4E_SYM
@ TT_4E_SYM
Definition: ImportData.h:82
TrigGlobEffCorr::ImportData::m_hasher
std::hash< std::string > & m_hasher
Definition: ImportData.h:143
TrigGlobEffCorr::TT_E_2G_ASYM
@ TT_E_2G_ASYM
Definition: ImportData.h:74
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
contents
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory, const std::string &pattern, const std::string &path)
Definition: computils.cxx:320
TrigGlobEffCorr::ImportData::m_triggerThresholds
std::map< std::size_t, float > m_triggerThresholds
Definition: ImportData.h:146
plotting.yearwise_efficiency.years
list years
Definition: yearwise_efficiency.py:29
TrigGlobEffCorr::ImportData::TrigDef::type
TriggerType type
Definition: ImportData.h:94
ImportData
TrigGlobEffCorr::ImportData ImportData
Definition: ImportData.cxx:15
grepfile.sep
sep
Definition: grepfile.py:38
TrigGlobEffCorr::TT_2E_G_ASYM
@ TT_2E_G_ASYM
Definition: ImportData.h:73
PathResolver.h
TrigGlobEffCorr::TriggerType
TriggerType
Definition: ImportData.h:23
TrigGlobEffCorr::ImportData::m_triggerDefs
std::map< std::size_t, TrigDef > m_triggerDefs
Definition: ImportData.h:145
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
TrigGlobEffCorr::ImportData::suggestEgammaMapKeys
bool suggestEgammaMapKeys(const std::map< std::string, std::string > &triggerCombination, const std::string &version, std::map< std::string, std::string > &legsPerKey, xAOD::Type::ObjectType type)
Definition: ImportData.cxx:594
TrigGlobalEfficiencyCorrectionTool
Definition: TrigGlobalEfficiencyCorrectionTool.h:39
item
Definition: ItemListSvc.h:43
TrigGlobEffCorr::ImportData::readDataFile
bool readDataFile(const char *filename, std::vector< std::string > &contents)
Definition: ImportData.cxx:52
TrigGlobEffCorr::ImportData::TrigDef
Definition: ImportData.h:93
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition: PathResolver.cxx:431
Muon
struct TBPatternUnitContext Muon
get_generator_info.version
version
Definition: get_generator_info.py:33
CalibCoolCompareRT.nm
nm
Definition: CalibCoolCompareRT.py:110
y
#define y
h
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
TrigGlobEffCorr::TT_UNKNOWN
@ TT_UNKNOWN
Definition: ImportData.h:24
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TrigGlobEffCorr::TT_E_2G_SYM
@ TT_E_2G_SYM
Definition: ImportData.h:72
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:21
TrigGlobEffCorr::TT_2MU_G_ASYM
@ TT_2MU_G_ASYM
Definition: ImportData.h:77
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
TrigGlobEffCorr::ImportData::importAll
bool importAll(const std::map< std::string, std::string > &overridenThresholds={})
Definition: ImportData.cxx:44
ITrigGlobalEfficiencyCorrectionTool::toolnameForDefaultScaleFactor
static std::string toolnameForDefaultScaleFactor()
To be used with the ListOfLegsPerTool property:
Definition: ITrigGlobalEfficiencyCorrectionTool.h:56
xAODType::Tau
@ Tau
The object is a tau (jet)
Definition: ObjectType.h:49
TrigGlobEffCorr::TT_4MU_SYM
@ TT_4MU_SYM
Definition: ImportData.h:83
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798
TrigGlobEffCorr::ImportData::importTriggers
bool importTriggers()
Definition: ImportData.cxx:106
TrigGlobEffCorr::TT_MU_2G_SYM
@ TT_MU_2G_SYM
Definition: ImportData.h:76
TrigGlobEffCorr::removeWhitespaces
std::string removeWhitespaces(const std::string &s)
Definition: ImportData.h:152
TrigGlobEffCorr::ImportData::m_dictionary
std::map< std::size_t, std::string > & m_dictionary
Definition: ImportData.h:142
TrigGlobEffCorr::TT_2E_G_SYM
@ TT_2E_G_SYM
Definition: ImportData.h:71
TrigGlobEffCorr::ImportData::setNonMixed3LType
void setNonMixed3LType(TrigDef &def, TriggerType flavourFlag)
Definition: ImportData.cxx:94
value_type
Definition: EDM_MasterSearch.h:11
TrigGlobEffCorr::ImportData::m_parent
TrigGlobalEfficiencyCorrectionTool * m_parent
Definition: ImportData.h:141
TrigGlobEffCorr::TT_MU_G
@ TT_MU_G
Definition: ImportData.h:52
TrigGlobEffCorr::TT_E_G
@ TT_E_G
Definition: ImportData.h:51
TrigGlobEffCorr::TT_TRILEPTON_SYM
@ TT_TRILEPTON_SYM
Definition: ImportData.h:55
TrigGlobalEfficiencyCorrectionTool::Hierarchy
Definition: TrigGlobalEfficiencyCorrectionTool.h:78
fitman.k
k
Definition: fitman.py:528
TrigGlobEffCorr::TT_SINGLE_G
@ TT_SINGLE_G
Definition: ImportData.h:39
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
TrigGlobEffCorr::TT_2MU_ASYM
@ TT_2MU_ASYM
Definition: ImportData.h:47