ATLAS Offline Software
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  bool found_tau_leg = false;
126  // Skip chains with a tau leg, not yet supported
127  while((ss >> token) && !found_tau_leg)
128  {
129  auto flavour = associatedLeptonFlavour(token, success);
130  if(flavour == xAOD::Type::Tau) found_tau_leg = true;
131  }
132  if(found_tau_leg) continue;
133 
134  ss.clear();
135  ss.str(line);
136  ss >> triggerName;
137  m_dictionary[h] = triggerName;
138  ATH_MSG_DEBUG(std::to_string(h) << " " << triggerName );
139  for(std::size_t& leg : def.leg)
140  {
141  if(!(ss >> token)) break;
142  h = m_hasher(token);
143  m_dictionary.emplace(h,token);
144  leg = h;
145  if(m_triggerThresholds.find(h) == m_triggerThresholds.end())
146  {
147  ATH_MSG_ERROR("Unknown trigger leg '" << token << "' found in Triggers.cfg");
148  success = false;
149  }
150  }
151  if(!def.leg[0])
152  {
153  def.leg[0] = h;
154  if(m_triggerThresholds.find(h) == m_triggerThresholds.end())
155  {
156  ATH_MSG_ERROR("Unknown trigger leg '" << triggerName << "' (inferred from trigger name) found in Triggers.cfg");
157  success = false;
158  }
159  }
160  if(!success) continue;
161 
163  def.type = TT_UNKNOWN;
164  auto flavour0 = associatedLeptonFlavour(def.leg[0], success);
165  int ne = (flavour0 == xAOD::Type::Electron)*1;
166  int nm = (flavour0 == xAOD::Type::Muon)*1;
167  if(def.leg[1])
168  {
169  auto flavour1 = associatedLeptonFlavour(def.leg[1], success);
170  if(flavour1 == xAOD::Type::Electron)
171  {
172  if(!ne) std::swap(def.leg[0],def.leg[1]);
173  ++ne;
174  }
175  else if(flavour1 == xAOD::Type::Muon)
176  {
177  if(!(ne+nm)) std::swap(def.leg[0],def.leg[1]);
178  ++nm;
179  }
180  else if(flavour1 != xAOD::Type::Photon) success = false;
181  if(def.leg[2])
182  {
183  auto flavour2 = associatedLeptonFlavour(def.leg[2], success);
184  if(flavour2 == xAOD::Type::Electron)
185  {
186  if(!ne) std::swap(def.leg[0], def.leg[2]);
187  else if(ne==1) std::swap(def.leg[1], def.leg[2]);
188  ++ne;
189  }
190  else if(flavour2 == xAOD::Type::Muon)
191  {
192  if(!(ne+nm)) std::swap(def.leg[0], def.leg[2]);
193  else if((ne+nm)==1) std::swap(def.leg[1], def.leg[2]);
194  ++nm;
195  }
196  else if(flavour2 != xAOD::Type::Photon) success = false;
197  if(def.leg[3])
198  {
200  if(std::count(def.leg.cbegin(),
201  def.leg.cend(),
202  def.leg[0]) == 4)
203  {
204  def.type = nm? TT_4MU_SYM : TT_4E_SYM;
205  }
206  else success = false;
207  }
208  else if(ne+nm==0 || ne==3 || nm==3)
209  {
211  }
212  else
213  {
214  bool sym = (def.leg[0]==def.leg[1] || def.leg[1]==def.leg[2]);
215  if(ne==2) def.type = nm? (sym? TT_2E_MU_SYM : TT_2E_MU_ASYM) : (sym? TT_2E_G_SYM : TT_2E_G_ASYM);
216  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);
217  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);
218  else success = false;
219  }
220  }
221  else
222  {
223  if(ne==2) def.type = (def.leg[0]==def.leg[1])? TT_2E_SYM : TT_2E_ASYM;
224  else if(nm==2) def.type = (def.leg[0]==def.leg[1])? TT_2MU_SYM : TT_2MU_ASYM;
225  else if(ne+nm==0) def.type = (def.leg[0]==def.leg[1])? TT_2G_SYM : TT_2G_ASYM;
226  else if(ne==1 && nm==1) def.type = TT_E_MU;
227  else if(ne==1) def.type = TT_E_G;
228  else if(nm==1) def.type = TT_MU_G;
229  }
230  }
231  else
232  {
233  def.type = ne? TT_SINGLE_E : nm? TT_SINGLE_MU : TT_SINGLE_G;
234  }
235  if(!success || def.type==TT_UNKNOWN)
236  {
237  success = false;
238  ATH_MSG_ERROR("Configuration issue for trigger " << triggerName);
239  }
240  }
241  return success;
242 }
243 
244 bool ImportData::importThresholds(const std::map<std::string, std::string>& overridenThresholds)
245 {
246  m_triggerThresholds.clear();
247  std::vector<std::string> config;
248  if(!readDataFile("TrigGlobalEfficiencyCorrection/Thresholds.cfg", config)) return false;
249  std::stringstream ss;
250  std::string leg, unit;
251  float pt;
252  bool success = true;
253  for(auto& line : config)
254  {
255  ss.clear();
256  ss.str(line);
257  if(ss >> leg >> pt >> unit)
258  {
259  std::size_t h = m_hasher(leg);
260  m_dictionary.emplace(h,leg);
261  if(unit == "GeV") pt *= 1e3f;
262  else if(unit != "MeV")
263  {
264  ATH_MSG_ERROR("Unable to import pT threshold for leg \"" << leg << "\" (missing unit)");
265  success = false;
266  }
268  }
269  else
270  {
271  ATH_MSG_ERROR("Unable to import pT threshold for leg \"" << leg << '"');
272  success = false;
273  }
274  }
275  if(!success)
276  {
277  m_triggerThresholds.clear();
278  return false;
279  }
280 
282  bool belowRecommended = false;
283  for(auto& kv : overridenThresholds)
284  {
285  auto itr = m_triggerThresholds.find(m_hasher(kv.first));
286  if(itr != m_triggerThresholds.end())
287  {
288  float pt = 0.f;
289  try { pt = std::stof(kv.second); }
290  catch(...)
291  {
292  ATH_MSG_ERROR("Unable to convert threshold argument \""<<kv.second<<"\" to floating-point value");
293  success = false;
294  continue;
295  }
296  if(pt<1e3f)
297  {
298  ATH_MSG_WARNING("Suspiciously low threshold (" << pt << " MeV) set for trigger leg " << kv.first
299  << ", please make sure you provided the threshold in MeV and not in GeV!");
300  }
301  if(pt < itr->second) belowRecommended = true;
302  itr->second = pt;
303  }
304  else
305  {
306  ATH_MSG_ERROR("Can't override threshold for unknown trigger leg " << kv.first);
307  success = false;
308  }
309  }
310  if(belowRecommended)
311  {
312  ATH_MSG_WARNING("Tool configured to use trigger thresholds below those recommended!");
313  }
314  return success;
315 }
316 
318 {
319  m_dataPeriods.clear();
320  std::vector<std::string> config;
321  if(!readDataFile("TrigGlobalEfficiencyCorrection/DataPeriods.cfg", config)) return false;
322  std::stringstream ss;
323  std::string key;
324  std::pair<unsigned,unsigned> runs;
325  for(auto& line : config)
326  {
327  ss.clear();
328  ss.str(line);
329  ss >> key >> runs.first >> runs.second;
330  if(ss.fail())
331  {
332  m_dataPeriods.clear();
333  return false;
334  }
335  m_dataPeriods.emplace(key,runs);
336  }
337  return true;
338 }
339 
341 {
342  if(!m_triggerThresholds.size() && !importThresholds()) return false;
343  m_hierarchyMeta.clear();
344  m_hierarchyData.clear();
345  std::vector<std::string> config;
346  if(!readDataFile("TrigGlobalEfficiencyCorrection/Hierarchies.cfg", config)) return false;
347  std::stringstream ss;
348  std::string token, unit;
349  std::map<std::size_t, std::vector<std::size_t> > aliases;
350  for(auto& line : config)
351  {
352  bool success = true;
353  ss.clear();
354  ss.str(line);
355  if(line[0]=='[')
356  {
357  auto& meta = *m_hierarchyMeta.emplace(m_hierarchyMeta.end(), Hierarchy{(short)m_hierarchyData.size(),0,0.f,std::numeric_limits<float>::max()});
358  if(line[1]=='-' && line[2]==']') ss.ignore(3);
359  else
360  {
361  char sep = '-';
362  if(line[1]=='>') ss.ignore(2) >> meta.minPt >> unit;
363  else if(line[1]=='<') ss.ignore(2) >> meta.maxPt >> unit;
364  else ss.ignore(1) >> meta.minPt >> sep >> meta.maxPt >> unit;
365  if(!ss || sep!='-' || (unit!="GeV]" && unit!="MeV]"))
366  {
367  ATH_MSG_ERROR("Unable to parse pT restrictions in Hierarchies.cfg");
368  success = false;
369  }
370  if(unit == "GeV]")
371  {
372  meta.minPt *= 1e3f;
373  if(meta.maxPt < std::numeric_limits<float>::max()) meta.maxPt *= 1e3f;
374  }
375  }
376  while(ss >> token)
377  {
378  std::size_t h = m_hasher(token);
379  auto itr = aliases.find(h);
380  if(itr == aliases.end())
381  {
382  if(m_triggerThresholds.find(h) == m_triggerThresholds.end())
383  {
384  ATH_MSG_ERROR("Unknown trigger leg '" << token << "' found in Hierarchies.cfg");
385  success = false;
386  }
387  m_dictionary.emplace(h,token);
388  m_hierarchyData.push_back(h);
389  }
390  else m_hierarchyData.insert(m_hierarchyData.end(),itr->second.begin(),itr->second.end());
391  if(ss >> token && token!=">") success = false;
392  }
393  meta.nLegs = m_hierarchyData.size() - meta.offset;
394  success = success && meta.nLegs;
395  }
396  else
397  {
398  ss >> token;
399  auto& legs = aliases[m_hasher(token)];
400  if(ss >> token && token==":=")
401  {
402  legs.clear();
403  while(ss >> token)
404  {
405  std::size_t h = m_hasher(token);
406  m_dictionary.emplace(h,token);
407  legs.push_back(h);
408  if(m_triggerThresholds.find(h) == m_triggerThresholds.end())
409  {
410  ATH_MSG_ERROR("Unknown trigger leg '" << token << "' found in Hierarchies.cfg");
411  success = false;
412  }
413  if(ss >> token && token!=">") success = false;
414  }
415  success = success && legs.size();
416  }
417  else success = false;
418  }
419  if(!success)
420  {
421  ATH_MSG_ERROR("Failed parsing line from Hierarchies.cfg:\n" << line);
422  m_hierarchyMeta.clear();
423  m_hierarchyData.clear();
424  return false;
425  }
426  }
427  return true;
428 }
429 
430 bool ImportData::importMapKeys(const std::string& version, std::map<std::size_t,std::map<std::size_t,int> >& keysPerLeg)
431 {
432  keysPerLeg.clear();
433  std::vector<std::string> config;
434  if(!readDataFile("TrigGlobalEfficiencyCorrection/MapKeys.cfg", config)) return false;
435  std::stringstream ss;
436  std::string token;
437  bool reading = false;
438  for(auto& line : config)
439  {
440  std::size_t pos = line.find("[VERSION]");
441  if(pos != std::string::npos)
442  {
443  reading = false;
444  ss.clear();
446  while(std::getline(ss, token, ','))
447  {
448  if(token == version)
449  {
450  reading = true;
451  break;
452  }
453  }
454  continue;
455  }
456  if(!reading) continue;
457  ss.clear();
458  ss.str(line);
459  int year;
460  ss >> year >> token;
461  year = 1<<(year-2015);
462  std::size_t leg = m_hasher(token);
463  auto& keys = keysPerLeg[leg];
464  while(ss >> token)
465  {
466  std::size_t h = m_hasher(token);
467  auto insertion = keys.emplace(h, year);
468  if(insertion.second) m_dictionary.emplace(h, token);
469  else insertion.first->second |= year;
470  }
471  }
472  if(!keysPerLeg.size())
473  {
474  ATH_MSG_ERROR("Unable to import the available map keys for the version " << version);
475  return false;
476  }
477  return true;
478 }
479 
480 bool ImportData::getPeriodBoundaries(const std::string& period, std::pair<unsigned,unsigned>& boundaries)
481 {
482  // First possibility: a defined period keyword
483  auto itr = m_dataPeriods.find(period);
484  if(itr!=m_dataPeriods.end())
485  {
486  boundaries = itr->second;
487  return true;
488  }
489  // Otherwise it's a '-'-separated range
490  auto sep = period.find_first_of('-');
491  if(sep!=std::string::npos)
492  {
493  std::string kwMin = period.substr(0,sep);
494  std::string kwMax = period.substr(sep+1);
495  // Second possibility: a range of defined period keywords
496  auto itrMin = m_dataPeriods.find(kwMin);
497  auto itrMax = m_dataPeriods.find(kwMax);
498  if(itrMin!=m_dataPeriods.end() && itrMax!=m_dataPeriods.end())
499  {
500  boundaries = std::minmax({itrMin->second.first, itrMax->second.first, itrMin->second.second, itrMax->second.second});
501  return true;
502  }
503  // Third possibility: a range of run numbers
504  try
505  {
506  boundaries = std::minmax(std::stoi(kwMin), std::stoi(kwMax));
507  return true;
508  }
509  catch(...) {}
510  }
511  ATH_MSG_ERROR("Unable to understand the period/range " << period);
512  return false;
513 }
514 
516 {
517  // note: 'success' is not set to 'true', only downgraded to 'false' if needed
518  if(leg.length()>=2 && leg[0]=='e' && leg[1]>='1' && leg[1]<='9') return xAOD::Type::Electron;
519  else if(leg.length()>=3 && leg[0]=='m' && leg[1]=='u' && leg[2]>='1' && leg[2]<='9') return xAOD::Type::Muon;
520  else if(leg.length()>=3 && leg[0]=='g' && leg[1]>='1' && leg[1]<='9') return xAOD::Type::Photon;
521  else if(leg.length()>=4 && leg[0]=='t' && leg[1]=='a' && leg[2]=='u' && leg[3]>='1' && leg[3]<='9') return xAOD::Type::Tau;
522  success = false;
523  return xAOD::Type::Other;
524 }
525 
527 {
528  // note: 'success' is not set to 'true', only downgraded to 'false' if needed
529  auto itr = m_dictionary.find(leg);
530  if(itr != m_dictionary.end())
531  {
532  return associatedLeptonFlavour(itr->second,success);
533  }
534  success = false;
535  return xAOD::Type::Other;
536 }
537 
538 std::vector<ImportData::TrigDef> ImportData::parseTriggerString(const std::string& triggerString, bool& success)
539 {
540  std::string s = TrigGlobEffCorr::removeWhitespaces(triggerString);
541  if(s.find("|||") != std::string::npos)
542  {
543  ATH_MSG_ERROR("Invalid format for the trigger combination '" << triggerString <<"'");
544  success = false;
545  return {};
546  }
548  while(true)
549  {
550  auto i = s.find("||");
551  if(i == std::string::npos) break;
552  s.replace(i, 1, "");
553  }
554  if(s=="" || s=="|")
555  {
556  ATH_MSG_ERROR("Invalid format for the trigger combination '" << triggerString <<"'");
557  success = false;
558  return {};
559  }
560  std::vector<TrigDef> triggers;
561  std::set<std::size_t> hashes;
562  std::stringstream ss(s);
563  while(std::getline(ss,s,'|'))
564  {
565  std::size_t trig = m_hasher(s);
566  ATH_MSG_DEBUG(std::to_string(trig) << " --> " << s );
567  auto itr = m_triggerDefs.find(trig);
568  if(itr == m_triggerDefs.end())
569  {
570  ATH_MSG_ERROR("Unknown trigger '" << s << "' found while parsing trigger combination");
571  success = false;
572  return {};
573  }
574  if(!hashes.insert(trig).second)
575  {
576  ATH_MSG_ERROR("The trigger '" << s << "' is present more than once in the combination");
577  success = false;
578  return {};
579  }
580  triggers.push_back(itr->second);
581  }
582  success = success && triggers.size();
583  return triggers;
584 }
585 
586 bool ImportData::suggestEgammaMapKeys(const std::map<std::string,std::string>& triggerCombination,
587  const std::string& version,
588  std::map<std::string,std::string>& legsPerKey,
590 {
591  legsPerKey.clear();
592  if(!importAll()) return false;
593 
594  bool success = true;
595  std::map<std::size_t,int> legs;
596 
597  for(auto& kv : triggerCombination)
598  {
599  auto itrPeriod = m_dataPeriods.find(kv.first);
600  if(itrPeriod == m_dataPeriods.end())
601  {
602  ATH_MSG_ERROR("Unknown period " << kv.first);
603  success = false;
604  continue;
605  }
606  int years = 0;
607  for(int k=0;k<32;++k)
608  {
609  auto itr = m_dataPeriods.find(std::to_string(2015+k));
610  if(itr != m_dataPeriods.end() && itrPeriod->second.first <= itr->second.second
611  && itrPeriod->second.second >= itr->second.first)
612  {
613  years |= (1<<k);
614  }
615  }
616  auto triggers = parseTriggerString(kv.second,success);
617  if(!success) continue;
618  for(auto& trig : triggers)
619  {
620  for(std::size_t leg : trig.leg)
621  {
622  if(leg && associatedLeptonFlavour(leg, success)==type)
623  {
624  auto insertion = legs.emplace(leg,years);
625  if(!insertion.second) insertion.first->second |= years;
626  }
627  }
628  }
629  }
630  if(!success) return false;
631 
632  if(version != "")
633  {
634  std::map<std::size_t,std::map<std::size_t,int> > allKeys;
635  if(!importMapKeys(version, allKeys)) return false;
636  std::map<std::size_t,std::vector<std::size_t> > allLegsPerKey;
637  std::set<std::size_t> legsWithMultipleKeys;
638  bool sameKeyForAllyears = true;
639  while(legs.size())
640  {
641  allLegsPerKey.clear();
642  for(auto& kvLegs : legs) // loop on remaining legs
643  {
644  std::size_t leg = kvLegs.first;
645  int years = kvLegs.second;
646  auto itrKeys = allKeys.find(leg); // list of keys for that leg
647  if(itrKeys != allKeys.end())
648  {
649  for(auto& kvKeys : itrKeys->second) // loop on those keys
650  {
651  auto y = (kvKeys.second & years);
652  if((y==years) || (!sameKeyForAllyears && y!=0)) // key must support all years needed for that leg -- until no longer possible
653  {
654  auto insertion = allLegsPerKey.emplace(kvKeys.first,std::vector<std::size_t>{leg});
655  if(!insertion.second) insertion.first->second.push_back(leg);
656  }
657  }
658  }
659  else
660  {
661  ATH_MSG_ERROR("Sorry, no idea what the map key should be for the trigger leg '"
662  << m_dictionary.at(leg) << "', manual configuration is needed");
663  success = false;
664  }
665  }
666  if(!success) break;
667 
668  if(!allLegsPerKey.size())
669  {
670  if(sameKeyForAllyears)
671  {
672  sameKeyForAllyears = false;
673  continue;
674  }
675  success = false;
676  break;
677  }
678 
679  using T = decltype(allLegsPerKey)::value_type;
680  auto itrKey = std::max_element(allLegsPerKey.begin(), allLegsPerKey.end(),
681  [](T& x,T& y){return x.second.size()<y.second.size();});
682  std::string& strLegs = legsPerKey[m_dictionary.at(itrKey->first)];
683  for(std::size_t leg : itrKey->second)
684  {
685  int& wantedYears = legs.at(leg);
686  int supportedYears = (allKeys.at(leg).at(itrKey->first)) & wantedYears;
687  if(supportedYears!=wantedYears || legsWithMultipleKeys.count(leg))
688  {
689  legsWithMultipleKeys.insert(leg);
690  for(int i=0;i<32;++i)
691  {
692  if(supportedYears & (1u<<i))
693  {
694  if(strLegs.length() && strLegs.back()!=',') strLegs += ',';
695  strLegs += m_dictionary.at(leg) + "[" + std::to_string(2015 + i) + "]";
696  }
697  }
698  }
699  else
700  {
701  if(strLegs.length() && strLegs.back()!=',') strLegs += ',';
702  strLegs += m_dictionary.at(leg);
703  }
704  if(supportedYears == wantedYears) legs.erase(leg);
705  else wantedYears &= ~supportedYears;
706  }
707  }
708  }
709  else
710  {
712  for(auto& kv : legs)
713  {
714  legsPerKey.emplace(std::to_string(legsPerKey.size()), m_dictionary.at(kv.first));
715  }
716  }
717  for (auto& [key, legs]: legsPerKey)
718  {
720  {
721  ATH_MSG_WARNING("Some of the requested triggers will result in "
722  "a default scale factor of 1 being returned");
723  }
724  }
725  if(!success) legsPerKey.clear();
726  return success;
727 }
728 
729 bool ImportData::adaptTriggerListForTriggerMatching(std::vector<ImportData::TrigDef>& triggers)
730 {
732  std::set<std::size_t> extraItems;
733  std::vector<ImportData::TrigDef> updatedTriggers;
734  for(auto& trig : triggers)
735  {
736  auto& name = m_dictionary.at(trig.name);
737  std::size_t pos = 0, len = name.find("_OR_");
738  if(len == std::string::npos)
739  {
740  updatedTriggers.emplace_back(trig);
741  continue;
742  }
743  while(true)
744  {
745  std::string item = name.substr(pos, len);
746  auto h = m_hasher(item);
747  auto def = m_triggerDefs.find(h);
748  if(def == m_triggerDefs.end())
749  {
750  ATH_MSG_ERROR("while listing triggers for trigger matching; trigger \"" << item << "\" extracted from \"" << name << "\" is not recognized");
751  return false;
752  }
753  if(extraItems.emplace(h).second) updatedTriggers.emplace_back(def->second);
754  if(len == std::string::npos) break;
755  pos += len + 4;
756  len = name.find("_OR_", pos);
757  if(len != std::string::npos) len -= pos;
758  }
759  }
760  triggers.swap(updatedTriggers);
761  return true;
762 }
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:430
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
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
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
max
#define max(a, b)
Definition: cfImp.cxx:41
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:729
TrigGlobEffCorr::ImportData::getPeriodBoundaries
bool getPeriodBoundaries(const std::string &period, std::pair< unsigned, unsigned > &boundaries)
Definition: ImportData.cxx:480
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:340
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:83
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:538
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:244
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:92
TrigGlobEffCorr::ImportData::associatedLeptonFlavour
xAOD::Type::ObjectType associatedLeptonFlavour(std::size_t leg, bool &success)
Definition: ImportData.cxx:526
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:317
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:319
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:35
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:192
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:586
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
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
unit
const PlainObject unit() const
This is a plugin that makes Eigen look like CLHEP & defines some convenience methods.
Definition: AmgMatrixBasePlugin.h:20
config
std::vector< std::string > config
Definition: fbtTestBasics.cxx:72
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:790
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