ATLAS Offline Software
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Private Member Functions | List of all members
FakeBkgTools::Database Class Reference

#include <Database.h>

Collaboration diagram for FakeBkgTools::Database:

Classes

struct  EfficiencyTable
 
struct  GenericError
 This propagates an error message. More...
 
struct  Param
 
struct  StatDef
 could try to keep track of the bin number, for the description More...
 
struct  StringRef
 Note: the following structure is used (instead of a simple std::string) so that XML line numbers can be printed in the error message, which requires keeping track of the position of the string in the original file. More...
 
struct  SystDef
 
struct  XmlError
 This propagates an error message + the reference to the faulty piece of XML when an exception is raised. More...
 

Public Types

enum  EfficiencyType {
  ELECTRON_REAL_EFFICIENCY = 0, ELECTRON_FAKE_EFFICIENCY, ELECTRON_FAKE_FACTOR, MUON_REAL_EFFICIENCY,
  MUON_FAKE_EFFICIENCY, MUON_FAKE_FACTOR, TAU_REAL_EFFICIENCY, TAU_FAKE_EFFICIENCY,
  TAU_FAKE_FACTOR, PHOTON_ELE_FAKE_FACTOR, PHOTON_ELE_FAKE_FACTOR_SF, N_EFFICIENCY_TYPES
}
 
enum  InputType { InputType::CENTRAL_VALUE, InputType::CORRECTION }
 
enum  StatMode { StatMode::GLOBAL, StatMode::PER_BIN, StatMode::NONE, StatMode::UNSPECIFIED }
 

Public Member Functions

 Database (Client client, bool useGeV, bool convertWhenMissing)
 
void importXML (std::string filename)
 
void importDefaultROOT (std::string filename)
 
bool ready () const
 
void reset ()
 
bool needEventInfo () const
 
bool fillEfficiencies (ParticleData &pd, const xAOD::IParticle &p, const xAOD::EventInfo &eventInfo, std::string &error) const
 
unsigned getXmlLineNumber (const char *pos) const
 
unsigned numberOfStats () const
 
unsigned numberOfSysts () const
 
const SystDeffindSyst (unsigned short uid) const
 
const StatDeffindStat (unsigned short uid) const
 

Static Public Member Functions

static constexpr unsigned short indexFromUID (unsigned short uid)
 
static constexpr unsigned short systIndexToUID (unsigned short index)
 
static constexpr unsigned short statIndexToUID (unsigned short index)
 
static constexpr bool isSystUID (unsigned short uid)
 
static constexpr bool isStatUID (unsigned short uid)
 

Protected Types

using AttributesMap = std::map< std::string, StringRef >
 

Protected Member Functions

void dropXmlComments (std::string &buffer)
 Methods used to parse XML files. More...
 
void dropRootTag (std::string &buffer)
 
void readNextTag (StringRef &stream, StringRef &tag, AttributesMap &attributes, StringRef &contents)
 
void readTagAttributes (StringRef stream, const std::string &tag, AttributesMap &attributes)
 
void resetAttributes (AttributesMap &attributes)
 
void importCustomROOT (const StringRef &tag, const StringRef &contents, const AttributesMap &attributes)
 
void addParams (const StringRef &tag, const StringRef &contents, AttributesMap &attributes)
 
void addSysts (const StringRef &tag, const StringRef &contents, const AttributesMap &attributes)
 
unsigned short addStat (EfficiencyType type, const StringRef &pos=StringRef())
 
void addTables (const StringRef &particleType, const AttributesMap &attributes, const StringRef &contents, TFile *source=nullptr)
 
void addDimension (EfficiencyTable &table, unsigned paramUID, const StringRef &contents)
 
void addValues (const StringRef &contents, EfficiencyTable &table, EfficiencyType type, StatMode statMode, unsigned short &globalStatUID)
 
void importNominalTH1 (const TH1 *hist, EfficiencyType type, const StringRef &paramX, const StringRef &paramY, const StringRef &paramZ, float scale, StatMode statMode, unsigned short &globalStatUID, const StringRef &xmlStream)
 Methods used to load from ROOT files. More...
 
void importSystTH1 (const TH1 *hist, EfficiencyType type, const std::string &sysname)
 
float getWeightedAverage (const TH1 *hist, const StringRef &xmlStream)
 
float getNormalizationFactor (const TH1 *hist, EfficiencyType type, const StringRef &norm, const StringRef &xmlStream)
 
bool retrieveParameterValue (const xAOD::IParticle &p, const xAOD::EventInfo &eventInfo, const Param &param, EfficiencyTable::BoundType &val) const
 
EfficiencyType getSourceType (EfficiencyType wantedType) const
 
int readEfficiencyFromTable (Efficiency &eff, const EfficiencyTable &table, std::map< unsigned, EfficiencyTable::BoundType > &cachedParamVals, const xAOD::IParticle &p, const xAOD::EventInfo &eventInfo, std::string &error) const
 
std::vector< std::string > getListOfNames (const StringRef &stream)
 

Static Protected Member Functions

static FakeBkgTools::EfficiencyselectEfficiency (FakeBkgTools::ParticleData &pd, const xAOD::IParticle &p, EfficiencyType type)
 Methods used to fill efficiencies. More...
 
template<typename ReturnValue , typename... Args>
static ReturnValue getAttribute (const StringRef &tag, const AttributesMap &attributes, const std::string &type, const char *ref, ReturnValue rv, Args... args)
 Helper methods. More...
 
static void assertNoLeftover (std::stringstream &ss, const StringRef &pos)
 
static constexpr unsigned short maxIndex ()
 
static std::string getTypeAsString (EfficiencyType type)
 
static std::bitset< N_EFFICIENCY_TYPESselectTypesToFill (Client client)
 This function is only called by the Database constructor. More...
 

Protected Attributes

const bool m_useGeV
 
const std::bitset< N_EFFICIENCY_TYPESm_typesToFill
 
const bool m_convertWhenMissing
 
bool m_storeAllUncertainties = true
 
std::vector< Paramm_params
 Permanent buffers. More...
 
std::vector< SystDefm_systs
 
std::vector< StatDefm_stats
 
std::map< int, std::vector< EfficiencyTable > > m_tables
 
std::string m_xmlBuffer
 Temporary buffers (only used while importing data) More...
 
std::vector< std::size_t > m_lineOffset
 
std::map< std::string, float > m_normFactors
 

Static Private Member Functions

template<typename ReturnValue >
static ReturnValue getAttribute (const StringRef &attr, const char *ref, ReturnValue rv)
 don't call these methods directly, use getAttribute(AttributesMap, string, ...) instead More...
 
template<typename ReturnValue , typename... Args>
static ReturnValue getAttribute (const StringRef &attr, const char *ref, ReturnValue rv, Args... args)
 

Detailed Description

Definition at line 28 of file Database.h.

Member Typedef Documentation

◆ AttributesMap

using FakeBkgTools::Database::AttributesMap = std::map<std::string, StringRef>
protected

Definition at line 175 of file Database.h.

Member Enumeration Documentation

◆ EfficiencyType

Enumerator
ELECTRON_REAL_EFFICIENCY 
ELECTRON_FAKE_EFFICIENCY 
ELECTRON_FAKE_FACTOR 
MUON_REAL_EFFICIENCY 
MUON_FAKE_EFFICIENCY 
MUON_FAKE_FACTOR 
TAU_REAL_EFFICIENCY 
TAU_FAKE_EFFICIENCY 
TAU_FAKE_FACTOR 
PHOTON_ELE_FAKE_FACTOR 
PHOTON_ELE_FAKE_FACTOR_SF 
N_EFFICIENCY_TYPES 

Definition at line 42 of file Database.h.

◆ InputType

Enumerator
CENTRAL_VALUE 
CORRECTION 

Definition at line 58 of file Database.h.

59  {
60  CENTRAL_VALUE, CORRECTION
61  };

◆ StatMode

Enumerator
GLOBAL 
PER_BIN 
NONE 
UNSPECIFIED 

Definition at line 62 of file Database.h.

63  {
64  GLOBAL, PER_BIN, NONE, UNSPECIFIED
65  };

Constructor & Destructor Documentation

◆ Database()

Database::Database ( Client  client,
bool  useGeV,
bool  convertWhenMissing 
)

Definition at line 25 of file Database.cxx.

25  :
26  m_useGeV(useGeV),
28  m_convertWhenMissing(convertWhenMissing)
29 {
30  reset();
31 }

Member Function Documentation

◆ addDimension()

void Database::addDimension ( EfficiencyTable table,
unsigned  paramUID,
const StringRef contents 
)
protected

Also accept a simpler syntax for integers (e.g. nJets = "2")

the stream might have consumed the leading '-' in its failed attempt to read a number, so recover it

Definition at line 510 of file Database.cxx.

511 {
512  if(!contents) return;
513  auto& param = m_params[paramUID];
514  const bool integer = param.integer();
515  const std::string fp = "[+-]?[0-9]*\\.?[0-9]+(?:[Ee][+-]?[0-9]+)?";
516  const std::string pattern = "^\\s*\\[\\s*(?:(?:-inf\\s*,\\s*|-?)inf|(?:-inf\\s*,\\s*)?"
517  + fp + "(?:\\s*,\\s*" + fp + ")*(?:\\s*,\\s*inf)?)\\s*\\]\\s*$";
518  if(!std::regex_match(contents.ptr, contents.endptr, std::regex(pattern)))
519  {
521  if(!integer || !std::regex_match(contents.ptr, contents.endptr, std::regex("\\s*[+-]?[0-9]+\\s*")))
522  {
523  throw(XmlError(contents) << "invalid format for the range of the parameter " << param.name);
524  }
525  }
526 
527  auto& bounds = table.m_bounds;
528  table.m_dimensions.emplace_back();
529  auto& dim = table.m_dimensions.back();
530  dim.paramUID = paramUID;
531  dim.iMinBound = table.m_bounds.size();
532  auto line = contents.str();
533  dim.nBounds = std::count(line.begin(), line.end(), ',') + 1;
534  if(integer && dim.nBounds < 1) throw(XmlError(contents) << "should specify at least one bin boundary for parameter " << param.name);
535  if(!integer && (dim.nBounds < 2)) throw(XmlError(contents) << "should specify at least two bin boundaries for parameter " << param.name);
536  for(auto&c : line) if(c==',' || c=='[' || c==']') c = ' ';
537  std::stringstream ss(line);
538  for(int i=0;i<dim.nBounds;++i)
539  {
540  EfficiencyTable::BoundType x;
541  if(integer) ss >> x.as_int;
542  else ss >> x.as_float;
543  if(ss.fail())
544  {
545  if(i==0 || i==(dim.nBounds-1))
546  {
547  ss.clear();
548  ss.unget();
549  ss.clear();
550  std::string x_s;
551  ss >> x_s;
552  if(x_s=="inf" || x_s=="-inf")
553  {
554  bool defMax = (x_s.front() != '-');
555  if(integer) x.as_int = defMax ? std::numeric_limits<int>::max() : std::numeric_limits<int>::min();
556  else x.as_float = defMax ? std::numeric_limits<float>::max() : std::numeric_limits<float>::lowest();
557  }
558  else throw(XmlError(contents) << "parsing error (invalid 'inf' string)");
559  }
560  if(ss.fail()) throw(XmlError(contents) << "parsing error (can't read int/float boundary)");
561  }
562  if(i)
563  {
564  if(integer ? (bounds.back().as_int > x.as_int) : (bounds.back().as_float > x.as_float))
565  {
566  throw(XmlError(contents) << "bin boundaries must be sorted in increasing order");
567  }
568  }
569  bounds.push_back(x);
570  }
572  if(integer && dim.nBounds==1)
573  {
574  dim.nBounds = 2;
575  bounds.push_back(bounds.back());
576  bounds.back().as_int += 1;
577  }
578 }

◆ addParams()

void Database::addParams ( const StringRef tag,
const StringRef contents,
AttributesMap attributes 
)
protected

Definition at line 359 of file Database.cxx.

360 {
362  auto level = getAttribute(tag, attributes, "level", "particle", Param::Level::PARTICLE, "event", Param::Level::EVENT);
363 
364  for(auto& name: getListOfNames(contents))
365  {
366  if(std::any_of(m_params.begin(), m_params.end(), [&](const Param& p){ return p.name == name; }))
367  {
368  throw(XmlError(contents) << "parameter \"" << name << "\" was already declared");
369  }
370  m_params.emplace_back(name, type, level);
371  attributes["bin/" + name];
372  attributes["table/" + name];
373  }
374 }

◆ addStat()

unsigned short Database::addStat ( EfficiencyType  type,
const StringRef pos = StringRef() 
)
protected

Definition at line 408 of file Database.cxx.

409 {
410  if(m_stats.size() >= maxIndex())
411  {
412  if(pos) throw(XmlError(pos) << "exceeded max number of statistical uncertainties");
413  else throw(GenericError() << "exceeded max number of statistical uncertainties");
414  }
415  m_stats.emplace_back(1 << type);
416  return statIndexToUID(m_stats.size() - 1);
417 }

◆ addSysts()

void Database::addSysts ( const StringRef tag,
const StringRef contents,
const AttributesMap attributes 
)
protected

Definition at line 376 of file Database.cxx.

377 {
378  std::bitset<N_EFFICIENCY_TYPES> affects;
379  for(auto& target : getListOfNames(attributes.at("syst/affects")))
380  {
381  auto targetMatches = [&](const char* a, const char* b) -> bool
382  { return target==a || target==b || target==std::string(a)+'-'+b; };
383  int matched = 0;
384  if(targetMatches("electron", "real-efficiency")) { affects.set(ELECTRON_REAL_EFFICIENCY); ++matched; }
385  if(targetMatches("muon", "real-efficiency")) { affects.set(MUON_REAL_EFFICIENCY); ++matched; }
386  if(targetMatches("tau", "real-efficiency")) { affects.set(TAU_REAL_EFFICIENCY); ++matched; }
387  if(targetMatches("electron", "fake-efficiency")) { affects.set(ELECTRON_FAKE_EFFICIENCY); ++matched; }
388  if(targetMatches("muon", "fake-efficiency")) { affects.set(MUON_FAKE_EFFICIENCY); ++matched; }
389  if(targetMatches("tau", "fake-efficiency")) { affects.set(TAU_FAKE_EFFICIENCY); ++matched; }
390  if(targetMatches("electron", "fake-factor")) { affects.set(ELECTRON_FAKE_FACTOR); ++matched; }
391  if(targetMatches("muon", "fake-factor")) { affects.set(MUON_FAKE_FACTOR); ++matched; }
392  if(targetMatches("tau", "fake-factor")) { affects.set(TAU_FAKE_FACTOR); ++matched; }
393  if(!matched) throw(XmlError(tag) << "the value \"" << target << "\" specified for the attribute \"affects\" is not recognized");
394  }
395  if(affects.none()) throw(XmlError(tag) << "missing or empty attribute \"affects\"");
396  for(auto& name: getListOfNames(contents))
397  {
398  if(name == "stat") throw(XmlError(contents) << "systematics can't be named \"stat\"");
399  if(std::any_of(m_systs.begin(), m_systs.end(), [&](const SystDef& s){ return s.name==name && (affects&s.affects).any(); }))
400  {
401  throw(XmlError(contents) << "the systematic \"" << name << "\" was already declared previously; duplicates are only allowed if their \"affects\" attributes do not overlap, which is not the case here");
402  }
403  if(m_systs.size() >= maxIndex()) throw(XmlError(contents) << "exceeded max number of systematic uncertainties");
404  m_systs.emplace_back(name, affects);
405  }
406 }

◆ addTables()

void Database::addTables ( const StringRef particleType,
const AttributesMap attributes,
const StringRef contents,
TFile *  source = nullptr 
)
protected

using the StringRef as map key ensures that dimensions will be listed in the same order as they were written

Definition at line 419 of file Database.cxx.

420 {
422  if(particle == "muon") type = getAttribute(particle, attributes, "type",
423  "real-efficiency", MUON_REAL_EFFICIENCY, "fake-efficiency", MUON_FAKE_EFFICIENCY, "fake-factor", MUON_FAKE_FACTOR);
424  else if(particle == "electron") type = getAttribute(particle, attributes, "type",
425  "real-efficiency", ELECTRON_REAL_EFFICIENCY, "fake-efficiency", ELECTRON_FAKE_EFFICIENCY, "fake-factor", ELECTRON_FAKE_FACTOR);
426  else if(particle == "tau") type = getAttribute(particle, attributes, "type",
427  "real-efficiency", TAU_REAL_EFFICIENCY, "fake-efficiency", TAU_FAKE_EFFICIENCY, "fake-factor", TAU_FAKE_FACTOR);
428  else throw(XmlError(particle) << "unexpected error: unsupported particle type " << particle.str());
429  auto statMode = attributes.at(particle.str()+"/stat") ? getAttribute(particle, attributes, "stat",
430  "global", StatMode::GLOBAL, "per-bin", StatMode::PER_BIN, "none", StatMode::NONE) : StatMode::UNSPECIFIED;
431  auto inputType = getAttribute(particle, attributes, "input", "central-value", InputType::CENTRAL_VALUE, "correction", InputType::CORRECTION);
432 
433  unsigned short globalStatUID = 0;
434 
435  AttributesMap subattributes;
436  StringRef stream = contents, subcontents;
437  while(stream.length())
438  {
439  StringRef tag;
440  resetAttributes(subattributes);
441  readNextTag(stream, tag, subattributes, subcontents);
442  const TH1* hist = nullptr;
443  if(tag=="bin" || tag=="table" || tag=="TH1")
444  {
445  if(tag == "TH1")
446  {
447  if(!source) throw(XmlError(tag) << "histograms can only be imported inside <ROOT>...</ROOT> blocks!");
448  if(!subattributes.at("TH1/X")) throw(XmlError(tag) << "the attribute 'X' should be specified (as well as 'Y' for 2D histograms, 'Z' for 3D histograms)");
449  auto name = subcontents.trim();
450  hist = static_cast<const TH1*>(source->Get(name.c_str()));
451  if(!hist) throw(XmlError(subcontents) << "can't find any histogram named \"" << name << "\" in the file " << source->GetName());
452  auto& norm = subattributes.at("TH1/norm");
453  if(inputType!=InputType::CORRECTION && (norm && norm!="none"))
454  throw(XmlError(norm) << "normalization of input histograms is only accepted for 'input=\"correction\"'");
455  float scale = getNormalizationFactor(hist, type, norm, subcontents);
456  importNominalTH1(hist, type, subattributes.at("TH1/X"), subattributes.at("TH1/Y"), subattributes.at("TH1/Z"), scale, statMode, globalStatUID, subcontents);
457  }
458  else m_tables[type].emplace_back();
459  auto& table = m_tables[type].back();
460  table.inputType = inputType;
461 
462  auto initialNumberOfBins = table.numberOfBins();
463  std::map<StringRef, unsigned> dimBins;
464  for(unsigned uid=0; uid<m_params.size(); ++uid)
465  {
466  auto& binning = subattributes.at(tag + "/" + m_params[uid].name);
467  if(binning) dimBins.emplace(binning, uid);
468  }
469  for(auto& kv : dimBins) addDimension(table, kv.second, kv.first);
470 
471  if(tag != "TH1")
472  {
473  if(tag == "bin" && table.numberOfBins() > 1) throw(XmlError(tag) << "use a <table> instead of a <bin> tag to hold several values");
474  addValues(subcontents, table, type, statMode, globalStatUID);
475  }
476  else if(table.numberOfBins() != initialNumberOfBins) throw(XmlError(tag) << "extra binned dimensions do not make sense");
477  if(tag=="TH1" || tag=="bin")
478  {
479  auto& label = subattributes.at(tag + "/label");
480  if(label)
481  {
482  float normFactor {0};
483  if(tag == "TH1") normFactor = 1.f / getWeightedAverage(hist, stream);
484  else
485  {
486  assert (tag == "bin");
487  normFactor = 1.f / table.m_efficiencies[0].nominal;
488  }
489  if(!std::isnormal(normFactor) || normFactor<=0.) throw(XmlError(label) << "computed normalization factor is 0 / NaN / infinite / negative");
490  if(!m_normFactors.emplace(label.str()+"-"+std::to_string(type), normFactor).second)
491  throw(XmlError(label) << "label \"" << label.str() << "\" has already been used");
492  }
493  }
494  }
495  else throw(XmlError(tag) << "unknown/unexpected XML tag \"" << tag.str() << "\"");
496  }
497 }

◆ addValues()

void Database::addValues ( const StringRef contents,
EfficiencyTable table,
EfficiencyType  type,
StatMode  statMode,
unsigned short &  globalStatUID 
)
protected

Definition at line 580 of file Database.cxx.

581 {
582  const std::string fpv = "(?:[0-9]+\\.)?[0-9]+(?:[Ee][+-]?[0-9]+)?", fpu = fpv + "\\s*\\%?";
583  const std::string pattern = "^\\s*" + fpv + "(?:\\s*(?:\\+(?:\\s*" + fpu + "\\s*)?-|-(?:\\s*" + fpu + "\\s*)?\\+)\\s*" + fpu + "\\s*\\([_[:alnum:]]+\\))*\\s*";
584  auto rxValidFormat = std::regex(pattern);
585  std::stringstream ssCSV(contents.str()), ss;
586  const char* ptr = contents.ptr;
587 
588  if(statMode==StatMode::GLOBAL && !globalStatUID) globalStatUID = addStat(type, contents);
589 
590  while(ptr && ptr<contents.endptr)
591  {
592  std::cmatch cm;
593  if(!std::regex_search(ptr, contents.endptr, cm, rxValidFormat))
594  {
595  StringRef lineref{ptr, contents.endptr};
596  throw(XmlError(lineref) << "the central value(s) and uncertainties are not in the expected format; first issue found with value " << lineref.str().substr(0, 32) << " [...]");
597  }
598  StringRef valref{ptr, static_cast<std::size_t>(cm.length())};
599  ptr += cm.length();
600  std::string value = valref.str();
601  value.erase(std::remove_if(value.begin(), value.end(), [](char c){ return std::isspace(c); }), value.end());
602  unsigned nErrs = std::count(value.begin(), value.end(), '(');
603  for(auto& c : value) if(c=='(' || c==')') c = ' ';
604  ss.clear();
605  ss.str(value);
606  table.m_efficiencies.emplace_back();
607  auto& eff = table.m_efficiencies.back();
608  ss >> eff.nominal;
609  bool foundStat = false;
610  for(unsigned i=0;i<nErrs;++i)
611  {
613  std::string sysname;
614  ss >> std::ws;
615  char c1 = ss.get(), c2 = ss.peek();
616  if(c2=='+' || c2=='-')
617  {
618  ss >> c2 >> uncval.up >> sysname;
619  if(sysname == "%")
620  {
621  uncval.up *= 0.01f * eff.nominal;
622  ss >> sysname;
623  }
624  uncval.down = uncval.up;
625  }
626  else
627  {
628  ss >> uncval.up >> c2;
629  if(c2 == '%')
630  {
631  uncval.up *= 0.01f * eff.nominal;
632  ss >> c2;
633  }
634  ss >> uncval.down >> sysname;
635  if(sysname == "%")
636  {
637  uncval.down *= 0.01f * eff.nominal;
638  ss >> sysname;
639  }
640  }
641  if(ss.bad()) throw(XmlError(valref) << "unexpected parsing error");
642  if(std::signbit(uncval.up) != std::signbit(uncval.down)) throw(XmlError(valref) << "one-sided up/down errors");
643  if(c1 == '-')
644  {
645  uncval.up = -uncval.up;
646  uncval.down = -uncval.down;
647  }
648 
649  uint16_t uid;
650  if(sysname == "stat")
651  {
652  if(foundStat) throw(XmlError(valref) << "there can be only one source of statistical uncertainty per bin");
653  if(statMode==StatMode::UNSPECIFIED || statMode==StatMode::NONE) throw(XmlError(valref) << "when using statistical uncertainties, the \"stat\" attribute must be specified (and not set to \"none\")");
654  foundStat = true;
655  uid = (statMode == StatMode::GLOBAL)? globalStatUID : addStat(type, contents);
656  }
657  else
658  {
659  auto sys = std::find_if(m_systs.begin(), m_systs.end(),
660  [&](const SystDef& sd){ return sd.name==sysname && sd.affects[type]; });
661  if(sys == m_systs.end()) throw(XmlError(valref) << "the systematic \"" << sysname << "\" has either not been defined, or does not affect this type of efficiency");
662  unsigned index = sys - m_systs.begin();
663  uid = systIndexToUID(index);
664  }
665  if(!eff.uncertainties.emplace(uid, uncval).second)
666  {
667  throw(XmlError(valref) << "source of uncertainty \"" << sysname << "\" specified twice");
668  }
669  }
671  }
672  if(table.m_efficiencies.size() != table.numberOfBins())
673  {
674  throw(XmlError(contents) << "the number of tabulated efficiencies (" << table.m_efficiencies.size()
675  << ") is inconsistent with the number of bins (" << table.numberOfBins() << ")");
676  }
677 }

◆ assertNoLeftover()

void Database::assertNoLeftover ( std::stringstream &  ss,
const StringRef pos 
)
inlinestaticprotected

Definition at line 499 of file Database.cxx.

500 {
501  ss >> std::ws;
502  if(!ss.eof())
503  {
504  std::string line;
505  std::getline(ss, line);
506  throw(XmlError(pos) << "unexpected parsing error (leftover data \"" << line << "\")");
507  }
508 }

◆ dropRootTag()

void Database::dropRootTag ( std::string &  buffer)
protected

Definition at line 304 of file Database.cxx.

305 {
306  const std::vector<std::string> keys = {"<efficiencies>", "</efficiencies>"};
307  for(const auto& key : keys)
308  {
309  std::size_t ipos;
310  while((ipos = buffer.find(key)) != std::string::npos)
311  {
312  buffer.erase(ipos, key.length()-1);
313  buffer[ipos] = ' ';
314  }
315  }
316 }

◆ dropXmlComments()

void Database::dropXmlComments ( std::string &  buffer)
protected

Methods used to parse XML files.

Definition at line 288 of file Database.cxx.

289 {
290  std::regex rx("<!--.*?-->");
291  std::smatch smr;
292  while(std::regex_search(buffer, smr, rx))
293  {
294  std::size_t pos = smr.position(0), length = smr.length(), endpos = pos + length;
295  for(auto& offset : m_lineOffset)
296  {
297  if(offset > endpos) offset -= length;
298  else if(offset > pos) offset = pos;
299  }
300  buffer = smr.prefix().str() + smr.suffix().str();
301  }
302 }

◆ fillEfficiencies()

bool Database::fillEfficiencies ( ParticleData pd,
const xAOD::IParticle p,
const xAOD::EventInfo eventInfo,
std::string &  error 
) const

Loop over all the type of efficiencies (real, fake, fake factor) that were requested to be filled

pointer to the proper member of ParticleData that needs to be filled

The efficiency tables to look for might be for a different type (if a Fake efficiency <--> Fake factor conversion is needed)

Loop over all the tables found for that type of efficiency

an error occurred

this table contained the central values

only a single table should be providing central values (the other tables might provide corrections)

Transform the fake efficiency into fake factor (or reciprocally)

Definition at line 64 of file Database.cxx.

65 {
66  std::map<unsigned, EfficiencyTable::BoundType> cachedParamVals;
68  for(int wt=0;wt<N_EFFICIENCY_TYPES;++wt)
69  {
70  EfficiencyType wantedType = static_cast<EfficiencyType>(wt);
71  if(!m_typesToFill[wantedType]) continue;
72  Efficiency* eff = selectEfficiency(pd, p, wantedType);
73  if(!eff) continue;
74 
76  EfficiencyType type = getSourceType(wantedType);
77 
78  bool found_central = false;
79  eff->nominal = 1.f;
80  eff->uncertainties.clear();
81 
82  auto relevantTables = m_tables.find(type);
83  if(relevantTables == m_tables.end())
84  {
85  error = "missing table for " + getTypeAsString(type);
86  return false;
87  }
88 
90  for(auto& table : relevantTables->second)
91  {
92  int status = readEfficiencyFromTable(*eff, table, cachedParamVals, p, eventInfo, error);
93  if(status < 0) return false;
94  if(status == 1)
95  {
96  if(found_central)
97  {
98  error = "while retrieving " + getTypeAsString(type) + ", found two non-orthogonal tables providing the central value";
99  return false;
100  }
101  found_central = true;
102  }
103  }
104  if(!found_central)
105  {
106  error = "didn't find central value for " + getTypeAsString(type);
107  return false;
108  }
110  if(type != wantedType)
111  {
112  if(eff == &pd.fake_factor)
113  {
114  float f = eff->nominal/(1.f-eff->nominal), k = pow(f/eff->nominal, 2);
115  eff->nominal = f;
116  for(auto& kv : eff->uncertainties) kv.second *= k;
117  }
118  else if(eff == &pd.fake_efficiency)
119  {
120  float e = eff->nominal/(1.f+eff->nominal), k = pow(e/eff->nominal, 2);
121  eff->nominal = e;
122  for(auto& kv : eff->uncertainties) kv.second *= k;
123  }
124  }
125  }
126  return true;
127 }

◆ findStat()

const StatDef* FakeBkgTools::Database::findStat ( unsigned short  uid) const
inline

Definition at line 232 of file Database.h.

233  {
234  if(!isStatUID(uid)) return nullptr;
235  unsigned index = indexFromUID(uid);
236  return (index<m_stats.size())? &m_stats[index] : nullptr;
237  }

◆ findSyst()

const SystDef* FakeBkgTools::Database::findSyst ( unsigned short  uid) const
inline

Definition at line 226 of file Database.h.

227  {
228  if(!isSystUID(uid)) return nullptr;
229  unsigned index = indexFromUID(uid);
230  return (index<m_systs.size())? &m_systs[index] : nullptr;
231  }

◆ getAttribute() [1/3]

template<typename ReturnValue >
ReturnValue Database::getAttribute ( const StringRef attr,
const char *  ref,
ReturnValue  rv 
)
inlinestaticprivate

don't call these methods directly, use getAttribute(AttributesMap, string, ...) instead

Definition at line 337 of file Database.cxx.

338 {
339  if(attr.str() == ref) return rv;
340  throw(XmlError(attr) << "unsupported parameter type \"" << attr.str() << "\"");
341 }

◆ getAttribute() [2/3]

template<typename ReturnValue , typename... Args>
ReturnValue Database::getAttribute ( const StringRef attr,
const char *  ref,
ReturnValue  rv,
Args...  args 
)
inlinestaticprivate

Definition at line 344 of file Database.cxx.

345 {
346  if(attr.str() == ref) return rv;
347  return getAttribute(attr, args...);
348 }

◆ getAttribute() [3/3]

template<typename ReturnValue , typename... Args>
ReturnValue Database::getAttribute ( const StringRef tag,
const AttributesMap attributes,
const std::string &  type,
const char *  ref,
ReturnValue  rv,
Args...  args 
)
inlinestaticprotected

Helper methods.

Definition at line 351 of file Database.cxx.

352 {
353  std::string attrname = tag.str() + "/" + type;
354  auto& attr = attributes.at(attrname);
355  if(!attr) throw(XmlError(tag) << "unspecified value for attribute \"" << type << "\"");
356  return getAttribute(attr, ref, rv, args...);
357 }

◆ getListOfNames()

std::vector< std::string > Database::getListOfNames ( const StringRef stream)
protected

Definition at line 318 of file Database.cxx.

319 {
320  std::vector<std::string> words;
321  std::stringstream ss(std::string(stream.ptr, stream.endptr));
322  std::string w;
323  while(std::getline(ss, w, ','))
324  {
325  std::size_t i = w.find_first_not_of(" \t");
326  std::size_t j = w.find_last_not_of(" \t");
327  if(i == std::string::npos)
328  {
329  throw(XmlError(stream) << "this should be a comma-separated list of names");
330  }
331  words.push_back(w.substr(i, j-i+1));
332  }
333  return words;
334 }

◆ getNormalizationFactor()

float Database::getNormalizationFactor ( const TH1 hist,
EfficiencyType  type,
const StringRef norm,
const StringRef xmlStream 
)
protected

Should be called only when processing XMLs

in principle the denominator has been checked not to be 0

Definition at line 828 of file Database.cxx.

829 {
831  if(!norm) return 1.f;
832  auto normType = norm.str();
833  if(normType == "auto") return 1.f / getWeightedAverage(hist, xmlStream);
834  else if(normType != "none")
835  {
836  auto itr = m_normFactors.find(normType + "-" + std::to_string(type));
837  if(itr == m_normFactors.end()) throw(XmlError(norm) << "unknown normalization tag \"" << normType << "\"");
838  return itr->second;
839  }
840  return 1.f;
841 }

◆ getSourceType()

Database::EfficiencyType Database::getSourceType ( EfficiencyType  wantedType) const
protected

Definition at line 1097 of file Database.cxx.

1098 {
1099  auto tables = m_tables.find(wantedType);
1100  if((tables==m_tables.end() || !tables->second.size()) && m_convertWhenMissing)
1101  {
1102  switch(wantedType)
1103  {
1106  case TAU_FAKE_EFFICIENCY: return TAU_FAKE_FACTOR;
1109  case TAU_FAKE_FACTOR: return TAU_FAKE_EFFICIENCY;
1112  default:;
1113  }
1114  }
1115  return wantedType;
1116 }

◆ getTypeAsString()

std::string Database::getTypeAsString ( EfficiencyType  type)
staticprotected

This function is only meant to be used to display meaningful error messages

Definition at line 1127 of file Database.cxx.

1128 {
1130  switch(type)
1131  {
1132  case ELECTRON_REAL_EFFICIENCY: return "real efficiency (electrons)";
1133  case ELECTRON_FAKE_EFFICIENCY: return "fake efficiency (electrons)";
1134  case ELECTRON_FAKE_FACTOR: return "fake factor (electrons)";
1135  case MUON_REAL_EFFICIENCY: return "real efficiency (muons)";
1136  case MUON_FAKE_EFFICIENCY: return "fake efficiency (muons)";
1137  case MUON_FAKE_FACTOR: return "fake factor (muons)";
1138  case TAU_REAL_EFFICIENCY: return "real efficiency (taus)";
1139  case TAU_FAKE_EFFICIENCY: return "fake efficiency (taus)";
1140  case TAU_FAKE_FACTOR: return "fake factor (taus)";
1141  case PHOTON_ELE_FAKE_FACTOR: return "fake rate (electrons->photons)";
1142  case PHOTON_ELE_FAKE_FACTOR_SF: return "fake rate SF(electrons->photons)";
1143  default:;
1144  }
1145  return "???";
1146 }

◆ getWeightedAverage()

float Database::getWeightedAverage ( const TH1 hist,
const StringRef xmlStream 
)
protected

compute weighted average of all bins

central value of the correction will be 1, but uncertainties may matter, so this is also a valid case

Definition at line 801 of file Database.cxx.

802 {
803  float avg = 1.f;
804  if(hist->GetNbinsX()!=1 || hist->GetNbinsY()!=1 || hist->GetNbinsZ()!=1)
805  {
807  double sum = 0., denom = 0.;
808  for(int i=1;i<=hist->GetNbinsX();++i)
809  for(int j=1;j<=hist->GetNbinsY();++j)
810  for(int k=1;k<=hist->GetNbinsZ();++k)
811  {
812  double x = hist->GetBinContent(i, j, k);
813  if(x == 0.) continue;
814  double w = hist->GetBinError(i, j, k);
815  if(w == 0.) throw(XmlError(xmlStream) << "bin with error = 0 encountered when trying to normalize histogram " << hist->GetName() << " to weighted bins average");
816  w = 1./(w*w);
817  sum += w * x;
818  denom += w;
819  }
820  avg = sum / denom;
821  }
822  else avg = 1. / hist->GetBinContent(1);
823  if(!std::isnormal(avg) || avg<=0.) throw(XmlError(xmlStream) << "something bad happened when trying to compute the weighted average of histogram \""
824  << hist->GetName() << "\" bins, the result ended up 0 / NaN / infinite / negative");
825  return avg;
826 }

◆ getXmlLineNumber()

unsigned Database::getXmlLineNumber ( const char *  pos) const

Definition at line 1118 of file Database.cxx.

1119 {
1120  if(!pos || !m_xmlBuffer.size() || !m_lineOffset.size()) return 0;
1121  if(pos < m_xmlBuffer.data()) return 0;
1122  unsigned offset = pos - m_xmlBuffer.data();
1123  if(offset >= m_xmlBuffer.size()) return 0;
1124  return std::upper_bound(m_lineOffset.begin(), m_lineOffset.end(), offset) - m_lineOffset.begin();
1125 }

◆ importCustomROOT()

void Database::importCustomROOT ( const StringRef tag,
const StringRef contents,
const AttributesMap attributes 
)
protected

Definition at line 679 of file Database.cxx.

680 {
681  std::string filename = attributes.at("ROOT/source").str();
682  if(!filename.length()) throw(XmlError(rootTag) << "the 'file' attribute must be specified!");
684 
685  TFile* file = TFile::Open(filename.c_str(), "READ");
686  if(!file || !file->IsOpen())
687  {
688  delete file;
689  throw(XmlError(rootTag) << "unable to locate/open the file " << filename);
690  }
691 
692  AttributesMap subattributes;
693  StringRef stream = contents, tag, subcontents;
694  while(stream.length())
695  {
696  resetAttributes(subattributes);
697  readNextTag(stream, tag, subattributes, subcontents);
698  if(tag=="electron" || tag=="muon" || tag=="tau") addTables(tag, subattributes, subcontents, file);
699  else throw(XmlError(stream) << "unknown/unexpected XML tag \"" << tag << "\"");
700  }
701 
702  file->Close();
703  delete file;
704 }

◆ importDefaultROOT()

void Database::importDefaultROOT ( std::string  filename)

step 0 = central value + stats step 1 = systs

Efficiency type

Definition at line 740 of file Database.cxx.

741 {
742  const std::string prefix = "^(FakeFactor|FakeEfficiency|RealEfficiency|FakeRate|FakeRateSF)", suffix = "_([[:w:]][^_]+)(__[[:w:]]+)?$";
743  const std::regex rxTH1(prefix + "_(el|mu|tau|e2y)" + suffix);
744  const std::regex rxTH2(prefix + "2D_(el|mu|tau|e2y)_([[:alnum:]]+)" + suffix);
745  const std::regex rxTH3(prefix + "3D_(el|mu|tau)_([[:alnum:]]+)_([[:alnum:]]+)" + suffix);
746 
748  TFile* file = TFile::Open(filename.c_str(), "READ");
749  if(!file || !file->IsOpen())
750  {
751  throw(GenericError() << "unable to locate/open the file " << filename);
752  }
753 
754  auto keys = file->GetListOfKeys();
755  if(!keys) throw(GenericError() << "unable to list keys in the file " << filename << " (corrupted?)");
756 
757  const StringRef nullStream;
758  unsigned short dummy;
759  for(unsigned step=0;step<2;++step)
760  {
763  for(int i=0;i<keys->GetSize();++i)
764  {
765  TKey* key = static_cast<TKey*>(keys->At(i));
766  std::cmatch mr;
767  std::string keyType = key->GetClassName();
768  unsigned nDims = 0;
769  if(keyType=="TH1F" || keyType=="TH1D") nDims = 1 * std::regex_match(key->GetName(), mr, rxTH1);
770  else if(keyType=="TH2F" || keyType=="TH2D") nDims = 2 * std::regex_match(key->GetName(), mr, rxTH2);
771  else if(keyType=="TH3F" || keyType=="TH3D") nDims = 3 * std::regex_match(key->GetName(), mr, rxTH3);
772  else continue;
773  if(nDims < 1) throw(GenericError() << "don't know what to do with histogram named \"" << key->GetName() << "\" (please check naming conventions)");
774  TH1* hist = static_cast<TH1*>(key->ReadObj());
776  std::string sss = mr[1].str() + "-" + mr[2].str();
777  auto type = getAttribute(StringRef(sss.data(), sss.length()),
778  "FakeFactor-el", ELECTRON_FAKE_FACTOR, "FakeFactor-mu", MUON_FAKE_FACTOR, "FakeFactor-tau", TAU_FAKE_FACTOR,
779  "FakeEfficiency-el", ELECTRON_FAKE_EFFICIENCY, "FakeEfficiency-mu", MUON_FAKE_EFFICIENCY, "FakeEfficiency-tau", TAU_FAKE_EFFICIENCY,
780  "RealEfficiency-el", ELECTRON_REAL_EFFICIENCY, "RealEfficiency-mu", MUON_REAL_EFFICIENCY, "RealEfficiency-tau", TAU_REAL_EFFICIENCY,
781  "FakeRate-e2y", PHOTON_ELE_FAKE_FACTOR, "FakeRateSF-e2y", PHOTON_ELE_FAKE_FACTOR_SF
782  );
783  bool systTH1 = (mr[mr.size()-1].str() != "");
784  if(step==0 && !systTH1)
785  {
786  StringRef paramX = StringRef(mr[3].first, mr[3].second);
787  StringRef paramY = (nDims>1) ? StringRef(mr[4].first, mr[4].second) : StringRef();
788  StringRef paramZ = (nDims>2) ? StringRef(mr[5].first, mr[5].second) : StringRef();
789  importNominalTH1(hist, type, paramX, paramY, paramZ, 1.f, StatMode::PER_BIN, dummy, nullStream);
790  m_tables[type].back().inputType = InputType::CENTRAL_VALUE;
791  }
792  else if(step==1 && systTH1) importSystTH1(hist, type, mr[nDims+3].str().substr(2));
793  else continue;
794  }
795  }
796 
797  file->Close();
798  delete file;
799 }

◆ importNominalTH1()

void Database::importNominalTH1 ( const TH1 hist,
EfficiencyType  type,
const StringRef paramX,
const StringRef paramY,
const StringRef paramZ,
float  scale,
StatMode  statMode,
unsigned short &  globalStatUID,
const StringRef xmlStream 
)
protected

Methods used to load from ROOT files.

Parameters and ranges

Copy, and include under/overflow into first/last bin:

Efficiencies + stat uncertainties

Definition at line 843 of file Database.cxx.

845 {
846  const bool useDefaults = !xmlStream;
847 
848  if(useDefaults && m_tables[type].size()) throw(GenericError() << "already filled that table, please use an XML to describe how to interpret the more complex ROOT files");
849  m_tables[type].emplace_back();
850  auto& table = m_tables[type].back();
851 
852  const int nDims = paramZ? 3 : paramY? 2 : 1;
853  if(hist->GetDimension() != nDims)
854  {
855  if(xmlStream) throw(XmlError(xmlStream) << "histogram " << hist->GetName() << " doesn't have the expected dimension");
856  else throw(GenericError() << "histogram " << hist->GetName() << " doesn't have the expected dimension");
857  }
858 
860  for(int j=0;j<nDims;++j)
861  {
862  std::string name = ((j==2)? paramZ : (j==1)? paramY : paramX).str();
863  const TAxis* axis = (j==2)? hist->GetZaxis() : (j==1)? hist->GetYaxis() : hist->GetXaxis();
864  if(useDefaults && name == "eta" && axis->GetBinLowEdge(1) >= 0) name = "|eta|";
865  table.m_dimensions.emplace_back();
866  auto& dim = table.m_dimensions.back();
867  auto itr = std::find_if(m_params.begin(), m_params.end(), [&](const Param& p){ return p.name == name; });
868  bool integer;
869  if(itr == m_params.end())
870  {
871  if(useDefaults)
872  {
873  dim.paramUID = m_params.size();
875  integer = false;
876  }
877  else throw(XmlError(j? paramY : paramX) << "parameter \"" << name << "\" has not been defined beforehand");
878  }
879  else
880  {
881  dim.paramUID = itr - m_params.begin();
882  integer = itr->integer();
883  }
884  dim.iMinBound = table.m_bounds.size();
885  dim.nBounds = axis->GetNbins() + 1;
887  table.m_bounds.emplace_back();
888  if(integer) table.m_bounds.back().as_int = std::numeric_limits<int>::min();
889  else table.m_bounds.back().as_float = std::numeric_limits<float>::lowest();
890  for(int k=1;k<dim.nBounds-1;++k)
891  {
892  table.m_bounds.emplace_back();
893  if(integer) table.m_bounds.back().as_int = std::ceil(axis->GetBinUpEdge(k));
894  else table.m_bounds.back().as_float = axis->GetBinUpEdge(k);
895  }
896  table.m_bounds.emplace_back();
897  if(integer) table.m_bounds.back().as_int = std::numeric_limits<int>::max();
898  else table.m_bounds.back().as_float = std::numeric_limits<float>::max();
899  }
900 
902  if(statMode==StatMode::GLOBAL && !globalStatUID) globalStatUID = addStat(type, xmlStream);
903  const unsigned xmax = table.m_dimensions.front().nBounds;
904  const unsigned ymax = table.m_dimensions.size()>1? table.m_dimensions[1].nBounds : 2;
905  const unsigned zmax = table.m_dimensions.size()>2? table.m_dimensions[2].nBounds : 2;
906  for(unsigned x=1;x<xmax;++x)
907  for(unsigned y=1;y<ymax;++y)
908  for(unsigned z=1;z<zmax;++z)
909  {
910  table.m_efficiencies.emplace_back();
911  auto& eff = table.m_efficiencies.back();
912  eff.nominal = scale * hist->GetBinContent(x, y, z);
913  if(statMode != StatMode::NONE)
914  {
915  uint16_t uid = (statMode==StatMode::GLOBAL)? globalStatUID : addStat(type, xmlStream);
916  float err = hist->GetBinError(x, y, z);
918  eff.uncertainties.emplace(uid, uncdata);
919  }
920  }
921 }

◆ importSystTH1()

void Database::importSystTH1 ( const TH1 hist,
EfficiencyType  type,
const std::string &  sysname 
)
protected

Definition at line 923 of file Database.cxx.

924 {
925  if(!m_tables[type].size()) throw(GenericError() << "there should be another histogram containing central values to accompany the histogram " << hist->GetName());
926  auto& table = m_tables[type].back();
927  const int xmax = table.m_dimensions.front().nBounds;
928  const int ymax = table.m_dimensions.size()>1? table.m_dimensions[1].nBounds : 2;
929  const int zmax = table.m_dimensions.size()>2? table.m_dimensions[2].nBounds : 2;
930  if(xmax!=hist->GetNbinsX()+1 || ymax!=hist->GetNbinsY()+1 || zmax!=hist->GetNbinsZ()+1)
931  {
932  throw(GenericError() << "binning mismatch between the nominal histogram and " << hist->GetName());
933  }
934 
935  uint16_t uid;
936  auto itr = std::find_if(m_systs.begin(), m_systs.end(), [&](const SystDef& sys){ return sys.name==sysname; });
937  if(itr != m_systs.end())
938  {
939  uid = systIndexToUID(itr - m_systs.begin());
940  itr->affects.set(type);
941  }
942  else
943  {
944  uid = systIndexToUID(m_systs.size());
945  m_systs.emplace_back(sysname, (1 << type));
946  }
947 
948  //loop through all bins once, to check whether all bins are zero error,
949  //or have the same central value as the nominal
950 
951  bool syst_central_equal_nom_central = true;
952  bool syst_errors_equal_zero = true;
953  bool syst_errors_equal_nom_errors = true;
954 
955  auto eff = table.m_efficiencies.begin();
956  for(int x=1;x<xmax;++x)
957  for(int y=1;y<ymax;++y)
958  for(int z=1;z<zmax;++z)
959  {
960  if (fabs ((float)eff->nominal - (float)hist->GetBinContent(x, y, z)) > 0.001 ){ syst_central_equal_nom_central = false;}
961  if ( hist->GetBinError(x, y, z) != 0 ) { syst_errors_equal_zero = false;}
962  float stat_up = 0;
963  for(auto& kv : eff->uncertainties)
964  {
965  if(!isStatUID(kv.first)) continue;
966  stat_up = kv.second.up; break;
967  }
968  if ( fabs((float) hist->GetBinError(x, y, z) - (float) stat_up ) > 0.001) { syst_errors_equal_nom_errors = false;}
969  ++eff;
970  }
971 
972  // loop bins a second time and determine proceedure using above heuristics
973  eff = table.m_efficiencies.begin();
974  for(int x=1;x<xmax;++x)
975  for(int y=1;y<ymax;++y)
976  for(int z=1;z<zmax;++z)
977  {
978 
979  float err =0;
980  //want to support several possible notations:
981  // a) central values are not the same as nominal: then we can assume
982  // that the central values of the syst histos are the errors,
983  // (default nomenclature from the documentation)
984  // b) if the central values for nominal and this hist are the same
985  // then probably the errors are to be taken from the error bars!
986  // but need to watch out for ambiguous cases
987  //
988  if (syst_central_equal_nom_central){ //central values are the same in nom and sys
989  if (syst_errors_equal_nom_errors ){ // this case is ambiguous. Is it a 100% uncertainty?
990  throw(GenericError() << "The central values and uncertainties for this systematic are identical to the nominal+stat uncertainties. This is ambiguous: did you mean to assign a 100% uncertainty? If so, please set all (unused) error bars to zero. ");
991  } else if (syst_errors_equal_zero ) { //assume here that it was intended as 100% uncertainty
992  err = hist->GetBinContent(x, y, z);
993  } else {
994  err = hist->GetBinError(x, y, z);
995  }
996  } else { // central values are different in nom and sys
997  err = hist->GetBinContent(x, y, z);
998  }
999 
1000 
1001  FakeBkgTools::Uncertainty uncdata{err, err};
1002  if(!eff->uncertainties.emplace(uid, uncdata).second)
1003  {
1004  throw(GenericError() << "unexpected error: tried filling twice the same systematic");
1005  }
1006  ++eff;
1007  }
1008 }

◆ importXML()

void Database::importXML ( std::string  filename)

not guaranteed that the above works, so truncating the buffer to a reasonable size if seemingly too large

Definition at line 185 of file Database.cxx.

186 {
188 
189  std::ifstream xml;
190  xml.open(filename, std::ios_base::binary);
191  auto begpos = xml.tellg();
192  xml.seekg(0, std::ios_base::end);
193  std::size_t bufferSize = 1.05 * static_cast<std::size_t>(xml.tellg() - begpos);
195  if(bufferSize > 0x100000) bufferSize = 0x100000;
196  xml.close();
197 
198  xml.open(filename, std::ios_base::in);
199  if(!xml.is_open()) throw(GenericError() << "unable to open file " << filename);
200 
201  std::string line;
202  m_xmlBuffer.reserve(bufferSize);
203  m_lineOffset.clear();
204  m_lineOffset.push_back(0);
205  while(std::getline(xml, line))
206  {
207  while(line.length() && (line.back()=='\n' || line.back()=='\r')) line.pop_back();
208  m_xmlBuffer += line + ' ';
209  m_lineOffset.push_back(m_xmlBuffer.length());
210  }
211  xml.close();
212 
215 
218  StringRef stream(m_xmlBuffer.data(), m_xmlBuffer.length()), contents, tag;
219  while(stream.length())
220  {
222  if(tag=="electron" || tag=="muon" || tag=="tau") addTables(tag, attributes, contents);
223  else if(tag=="param") addParams(tag, contents, attributes);
224  else if(tag=="syst") addSysts(tag, contents, attributes);
225  else if(tag=="ROOT") importCustomROOT(tag, contents, attributes);
226  else throw(XmlError(stream) << "unknown/unexpected XML tag \"" << tag.str() << "\"");
227  }
228  m_lineOffset.clear();
229  m_lineOffset.shrink_to_fit();
230  m_xmlBuffer.clear();
231  m_xmlBuffer.shrink_to_fit();
232 }

◆ indexFromUID()

static constexpr unsigned short FakeBkgTools::Database::indexFromUID ( unsigned short  uid)
inlinestaticconstexpr

Definition at line 219 of file Database.h.

219 { return uid&0x3FFF; }

◆ isStatUID()

static constexpr bool FakeBkgTools::Database::isStatUID ( unsigned short  uid)
inlinestaticconstexpr

Definition at line 223 of file Database.h.

223 { return ((uid&0xC000) == 0x8000); }

◆ isSystUID()

static constexpr bool FakeBkgTools::Database::isSystUID ( unsigned short  uid)
inlinestaticconstexpr

Definition at line 222 of file Database.h.

222 { return ((uid&0xC000) == 0x4000); }

◆ maxIndex()

static constexpr unsigned short FakeBkgTools::Database::maxIndex ( )
inlinestaticconstexprprotected

Definition at line 209 of file Database.h.

209 { return 0x4000; }

◆ needEventInfo()

bool Database::needEventInfo ( ) const

will no longer work if some event-level parameteres are predefined

Definition at line 55 of file Database.cxx.

56 {
57  for(auto& param : m_params)
58  {
59  if(param.level == Param::Level::EVENT) return true;
60  }
61  return false;
62 }

◆ numberOfStats()

unsigned FakeBkgTools::Database::numberOfStats ( ) const
inline

Definition at line 224 of file Database.h.

224 { return m_stats.size(); }

◆ numberOfSysts()

unsigned FakeBkgTools::Database::numberOfSysts ( ) const
inline

Definition at line 225 of file Database.h.

225 { return m_systs.size(); }

◆ readEfficiencyFromTable()

int Database::readEfficiencyFromTable ( Efficiency eff,
const EfficiencyTable table,
std::map< unsigned, EfficiencyTable::BoundType > &  cachedParamVals,
const xAOD::IParticle p,
const xAOD::EventInfo eventInfo,
std::string &  error 
) const
protected

Check if the particle falls in one bin of this table

if not, return

Yes! So read the central value / correction / uncertainties

=> tool will return weight + all uncertainties at once

Definition at line 129 of file Database.cxx.

130 {
132  int bin = 0;
133  for(const auto& dim : table.m_dimensions)
134  {
135  auto& param = m_params[dim.paramUID];
136  auto ins = cachedParamVals.emplace(dim.paramUID, EfficiencyTable::BoundType{});
137  auto& val = ins.first->second;
138  if(ins.second)
139  {
140  if(!retrieveParameterValue(p, eventInfo, param, val))
141  {
142  error = "can't retrieve value of parameter \"" + param.name + "\"";
143  return -1;
144  }
145  }
146  auto first = table.m_bounds.begin()+dim.iMinBound, last = first+dim.nBounds;
147  auto ubound = std::upper_bound(first, last, val,
148  [=](auto x, auto y){ return param.integer() ? (x.as_int<y.as_int) : (x.as_float<y.as_float); });
149  if(ubound==first || ubound==last)
150  {
151  bin = -1;
152  break;
153  }
154  bin = bin * (dim.nBounds-1) + (ubound - first - 1);
155  }
156  if(bin < 0) return 0;
157 
159  if(table.inputType != InputType::CENTRAL_VALUE && table.inputType != InputType::CORRECTION)
160  {
161  error = "unknown table type (tool implementation incomplete!)";
162  return -1;
163  }
164  auto& ref = table.m_efficiencies[bin];
165  for(auto& kv : eff.uncertainties) kv.second *= ref.nominal;
166  for(auto& kv : ref.uncertainties)
167  {
169  {
170  if(!eff.uncertainties.emplace(kv.first, eff.nominal*kv.second).second)
171  {
172  error = "central values and corrections must use different systematic uncertainties";
173  return -1;
174  }
175  }
176  }
177  eff.nominal *= ref.nominal;
178  return (table.inputType==InputType::CENTRAL_VALUE)? 1 : 2;
179 }

◆ readNextTag()

void Database::readNextTag ( StringRef stream,
StringRef tag,
AttributesMap attributes,
StringRef contents 
)
protected

Note: when modifying the pattern, make sure to also change readTagAttributes() if required!

Perhaps here do some looser pattern-matching to figure out where the format was not good: missing quotation marks? missing attribute value? no closing tag?

Definition at line 234 of file Database.cxx.

235 {
236  tag.clear();
237  contents.clear();
238  for(auto& kv : attributes) kv.second.clear();
240  std::string pattern = "^\\s*(<([[:alnum:]]+)((?:\\s+\\|?[_[:alnum:]]+\\|?\\s*=\\s*\"[_[:alnum:]\\s,-\\[\\]\\.\\|]+\")*)\\s*>)(.*?)</\\2>\\s*";
241  std::cmatch cmr;
242  if(!std::regex_search(stream.ptr, stream.endptr, cmr, std::regex(pattern)))
243  {
245  throw(XmlError(stream) << "unable to find next tag");
246  }
247  tag.set(stream.ptr+cmr.position(2), cmr.length(2));
248 
249  readTagAttributes(StringRef(stream.ptr+cmr.position(3), cmr.length(3)), tag.str(), attributes);
250 
251  auto cpos = cmr.size()-1;
252  contents.set(stream.ptr+cmr.position(cpos), cmr.length(cpos));
253 
254  stream.ptr += cmr.length();
255 }

◆ readTagAttributes()

void Database::readTagAttributes ( StringRef  stream,
const std::string &  tag,
AttributesMap attributes 
)
protected

Definition at line 257 of file Database.cxx.

258 {
259  auto nAttr = std::count(stream.ptr, stream.endptr, '=');
260  if(!nAttr) return;
261 
262  std::string pattern = "";
263  for(int i=0;i<nAttr;++i) pattern += "\\s+(\\|?[_[:alnum:]]+\\|?)\\s*=\\s*\"([_[:alnum:]\\s,-\\[\\]\\.\\|]+)\"";
264 
265  std::cmatch cmr;
266  if(!std::regex_match(stream.ptr, stream.endptr, cmr, std::regex(pattern)))
267  {
268  throw(XmlError(stream) << "unexpected error (internal))");
269  }
270  for(unsigned i=1;i<cmr.size();i+=2)
271  {
272  auto attr = cmr[i].str();
273  auto itr = attributes.find(tag + '/' + attr);
274  if(itr == attributes.end())
275  {
276  throw(XmlError(stream.ptr+cmr.position(i), attr.length()) << "invalid attribute \"" << attr << "\"");
277  }
278  if(!cmr.length(i+1))
279  {
280  throw(XmlError(stream.ptr+cmr.position(i), attr.length()) << "empty value for attribute \"" << attr << "\"");
281  }
282  auto& attrVal = itr->second;
283  if(attrVal) throw(XmlError(stream.ptr+cmr.position(i), attr.length()) << "the attribute \"" << attr << "\" has already been specified for that tag");
284  attrVal.set(stream.ptr+cmr.position(i+1), cmr.length(i+1));
285  }
286 }

◆ ready()

bool Database::ready ( ) const

Could do some more careful check here; for the moment just check that there's at least one table

Definition at line 45 of file Database.cxx.

46 {
48  for(auto& kv : m_tables)
49  {
50  if(kv.second.size()) return true;
51  }
52  return false;
53 }

◆ reset()

void Database::reset ( )

Definition at line 33 of file Database.cxx.

34 {
35  m_tables.clear();
36  m_systs.clear();
37  m_stats.clear();
38  m_params.clear();
43 }

◆ resetAttributes()

void Database::resetAttributes ( AttributesMap attributes)
protected

for now only a TH1 attribute

NB. the list of attributes allowed for bin or table tags can be further extended by new param tags. This is done inside addParams().

Definition at line 706 of file Database.cxx.

707 {
708  attributes["ROOT/source"];
709  attributes["param/type"];
710  attributes["param/level"];
711  attributes["syst/affects"];
712 
713  const std::vector<std::string> parts = {"electron", "muon", "tau"};
714  for(const auto& p : parts)
715  {
716  attributes[p + "/type"];
717  attributes[p + "/input"];
718  attributes[p + "/stat"];
719  }
720  attributes["TH1/X"];
721  attributes["TH1/Y"];
722  attributes["TH1/Z"];
723  attributes["TH1/label"];
724  attributes["bin/label"];
725  attributes["TH1/norm"];
726  for(auto& p : m_params)
727  {
728  attributes["bin/" + p.name];
729  attributes["table/" + p.name];
730  attributes["TH1/" + p.name];
733  }
734 }

◆ retrieveParameterValue()

bool Database::retrieveParameterValue ( const xAOD::IParticle p,
const xAOD::EventInfo eventInfo,
const Param param,
EfficiencyTable::BoundType val 
) const
protected

Definition at line 1010 of file Database.cxx.

1011 {
1012  #ifdef FAKEBKGTOOLS_ATLAS_ENVIRONMENT
1013  float energy_scale = (m_useGeV? 0.001f : 1.f);
1014  #else
1015  float energy_scale = 1;
1016  #endif
1017  if(param.level == Param::Level::PARTICLE)
1018  {
1019  if(param.type==Param::Type::PREDEFINED_FLOAT || param.type==Param::Type::PREDEFINED_INT)
1020  {
1021  if(param.name=="pt") val.as_float = energy_scale * p.pt();
1022  else if(param.name=="eta") val.as_float = p.eta();
1023  else if(param.name=="|eta|") val.as_float = fabs(p.eta());
1024  else if(param.name=="phi") val.as_float = p.phi();
1025  else return false;
1026  }
1027  else if(param.type == Param::Type::CUSTOM_FLOAT) val.as_float = p.auxdataConst<float>(param.name);
1028  else if(param.type == Param::Type::CUSTOM_INT) val.as_int = p.auxdataConst<int>(param.name);
1029  else return false;
1030  }
1031  else if(param.level == Param::Level::EVENT)
1032  {
1033  if(param.type == Param::Type::CUSTOM_FLOAT) val.as_float = eventInfo.auxdataConst<float>(param.name);
1034  else if(param.type == Param::Type::CUSTOM_INT) val.as_int = eventInfo.auxdataConst<int>(param.name);
1035  else return false;
1036  }
1037  else return false;
1038  return true;
1039 }

◆ selectEfficiency()

Efficiency * Database::selectEfficiency ( FakeBkgTools::ParticleData pd,
const xAOD::IParticle p,
EfficiencyType  type 
)
staticprotected

Methods used to fill efficiencies.

Definition at line 1041 of file Database.cxx.

1042 {
1043  switch(p.type())
1044  {
1045  case xAOD::Type::Electron:
1046  if(type==ELECTRON_FAKE_FACTOR) return &pd.fake_factor;
1047  else if(type==ELECTRON_FAKE_EFFICIENCY) return &pd.fake_efficiency;
1048  else if(type==ELECTRON_REAL_EFFICIENCY) return &pd.real_efficiency;
1049  else if(type==PHOTON_ELE_FAKE_FACTOR) return &pd.fake_factor;
1050  break;
1051  case xAOD::Type::Muon:
1052  if(type==MUON_FAKE_FACTOR) return &pd.fake_factor;
1053  else if(type==MUON_FAKE_EFFICIENCY) return &pd.fake_efficiency;
1054  else if(type==MUON_REAL_EFFICIENCY) return &pd.real_efficiency;
1055  break;
1056  case xAOD::Type::Tau:
1057  if(type==TAU_FAKE_FACTOR) return &pd.fake_factor;
1058  else if(type==TAU_FAKE_EFFICIENCY) return &pd.fake_efficiency;
1059  else if(type==TAU_REAL_EFFICIENCY) return &pd.real_efficiency;
1060  break;
1061  case xAOD::Type::Photon:
1062  if(type==PHOTON_ELE_FAKE_FACTOR_SF) return &pd.fake_factor;
1063  break;
1064  default:;
1065  }
1066  return nullptr;
1067 }

◆ selectTypesToFill()

auto Database::selectTypesToFill ( Client  client)
staticprotected

This function is only called by the Database constructor.

Definition at line 1070 of file Database.cxx.

1071 {
1072  std::bitset<N_EFFICIENCY_TYPES> result;
1074  {
1076  result[MUON_REAL_EFFICIENCY] = true;
1077  result[TAU_REAL_EFFICIENCY] = true;
1079  result[MUON_FAKE_EFFICIENCY] = true;
1080  result[TAU_FAKE_EFFICIENCY] = true;
1081  }
1083  {
1084  result[ELECTRON_FAKE_FACTOR] = true;
1085  result[MUON_FAKE_FACTOR] = true;
1086  result[TAU_FAKE_FACTOR] = true;
1087  }
1089  {
1092  }
1093  if(result.none()) throw(GenericError() << "unrecognized client type, implementation incomplete");
1094  return result;
1095 }

◆ statIndexToUID()

static constexpr unsigned short FakeBkgTools::Database::statIndexToUID ( unsigned short  index)
inlinestaticconstexpr

Definition at line 221 of file Database.h.

221 { return 0x8000 | index; }

◆ systIndexToUID()

static constexpr unsigned short FakeBkgTools::Database::systIndexToUID ( unsigned short  index)
inlinestaticconstexpr

Definition at line 220 of file Database.h.

220 { return 0x4000 | index; }

Member Data Documentation

◆ m_convertWhenMissing

const bool FakeBkgTools::Database::m_convertWhenMissing
protected

Definition at line 244 of file Database.h.

◆ m_lineOffset

std::vector<std::size_t> FakeBkgTools::Database::m_lineOffset
protected

Definition at line 255 of file Database.h.

◆ m_normFactors

std::map<std::string, float> FakeBkgTools::Database::m_normFactors
protected

Definition at line 256 of file Database.h.

◆ m_params

std::vector<Param> FakeBkgTools::Database::m_params
protected

Permanent buffers.

Definition at line 248 of file Database.h.

◆ m_stats

std::vector<StatDef> FakeBkgTools::Database::m_stats
protected

Definition at line 250 of file Database.h.

◆ m_storeAllUncertainties

bool FakeBkgTools::Database::m_storeAllUncertainties = true
protected

Definition at line 245 of file Database.h.

◆ m_systs

std::vector<SystDef> FakeBkgTools::Database::m_systs
protected

Definition at line 249 of file Database.h.

◆ m_tables

std::map<int, std::vector<EfficiencyTable> > FakeBkgTools::Database::m_tables
protected

Definition at line 251 of file Database.h.

◆ m_typesToFill

const std::bitset<N_EFFICIENCY_TYPES> FakeBkgTools::Database::m_typesToFill
protected

Definition at line 242 of file Database.h.

◆ m_useGeV

const bool FakeBkgTools::Database::m_useGeV
protected

Definition at line 241 of file Database.h.

◆ m_xmlBuffer

std::string FakeBkgTools::Database::m_xmlBuffer
protected

Temporary buffers (only used while importing data)

Definition at line 254 of file Database.h.


The documentation for this class was generated from the following files:
FakeBkgTools::Database::StatMode::GLOBAL
@ GLOBAL
NONE
@ NONE
Definition: sTGCenumeration.h:13
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
FakeBkgTools::Database::readTagAttributes
void readTagAttributes(StringRef stream, const std::string &tag, AttributesMap &attributes)
Definition: Database.cxx:257
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
FakeBkgTools::Database::addValues
void addValues(const StringRef &contents, EfficiencyTable &table, EfficiencyType type, StatMode statMode, unsigned short &globalStatUID)
Definition: Database.cxx:580
FakeBkgTools::ParticleData::fake_factor
FakeFactor fake_factor
Definition: FakeBkgInternals.h:87
FakeBkgTools::Uncertainty
Definition: FakeBkgInternals.h:27
FakeBkgTools::Uncertainty::down
float down
Definition: FakeBkgInternals.h:28
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
FakeBkgTools::Database::StatMode
StatMode
Definition: Database.h:63
PlotCalibFromCool.norm
norm
Definition: PlotCalibFromCool.py:100
FakeBkgTools::Database::m_storeAllUncertainties
bool m_storeAllUncertainties
Definition: Database.h:245
FakeBkgTools::Client::E2Y_FAKE
@ E2Y_FAKE
checkFileSG.line
line
Definition: checkFileSG.py:75
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
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
AddEmptyComponent.binning
binning
Definition: AddEmptyComponent.py:34
yodamerge_tmp.dim
dim
Definition: yodamerge_tmp.py:239
get_generator_info.result
result
Definition: get_generator_info.py:21
FakeBkgTools::Database::resetAttributes
void resetAttributes(AttributesMap &attributes)
Definition: Database.cxx:706
hotSpotInTAG.suffix
string suffix
Definition: hotSpotInTAG.py:186
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
max
#define max(a, b)
Definition: cfImp.cxx:41
FakeBkgTools::Database::importSystTH1
void importSystTH1(const TH1 *hist, EfficiencyType type, const std::string &sysname)
Definition: Database.cxx:923
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
FakeBkgTools::Efficiency
a structure to hold an efficiency together with a variable number of uncertainties
Definition: FakeBkgInternals.h:40
FakeBkgTools::Database::getSourceType
EfficiencyType getSourceType(EfficiencyType wantedType) const
Definition: Database.cxx:1097
FakeBkgTools::Database::assertNoLeftover
static void assertNoLeftover(std::stringstream &ss, const StringRef &pos)
Definition: Database.cxx:499
FakeBkgTools::Database::N_EFFICIENCY_TYPES
@ N_EFFICIENCY_TYPES
Definition: Database.h:55
index
Definition: index.py:1
FakeBkgTools::Database::m_useGeV
const bool m_useGeV
Definition: Database.h:241
FakeBkgTools::Client::FAKE_FACTOR
@ FAKE_FACTOR
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
FakeBkgTools::Database::Param::Type::PREDEFINED_INT
@ PREDEFINED_INT
plotmaker.hist
hist
Definition: plotmaker.py:148
FakeBkgTools::Database::m_xmlBuffer
std::string m_xmlBuffer
Temporary buffers (only used while importing data)
Definition: Database.h:254
extractSporadic.c1
c1
Definition: extractSporadic.py:134
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
yodamerge_tmp.axis
list axis
Definition: yodamerge_tmp.py:241
FakeBkgTools::Database::Param::Type::CUSTOM_FLOAT
@ CUSTOM_FLOAT
FakeBkgTools::Database::m_systs
std::vector< SystDef > m_systs
Definition: Database.h:249
bin
Definition: BinsDiffFromStripMedian.h:43
FakeBkgTools::Database::addStat
unsigned short addStat(EfficiencyType type, const StringRef &pos=StringRef())
Definition: Database.cxx:408
FakeBkgTools::Database::m_stats
std::vector< StatDef > m_stats
Definition: Database.h:250
FakeBkgTools::Database::addParams
void addParams(const StringRef &tag, const StringRef &contents, AttributesMap &attributes)
Definition: Database.cxx:359
athena.value
value
Definition: athena.py:122
FakeBkgTools::Database::TAU_REAL_EFFICIENCY
@ TAU_REAL_EFFICIENCY
Definition: Database.h:50
FakeBkgTools::Database::m_params
std::vector< Param > m_params
Permanent buffers.
Definition: Database.h:248
FakeBkgTools::Client::MATRIX_METHOD
@ MATRIX_METHOD
FakeBkgTools::Database::m_tables
std::map< int, std::vector< EfficiencyTable > > m_tables
Definition: Database.h:251
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
x
#define x
FakeBkgTools::Database::getWeightedAverage
float getWeightedAverage(const TH1 *hist, const StringRef &xmlStream)
Definition: Database.cxx:801
FakeBkgTools::Database::readNextTag
void readNextTag(StringRef &stream, StringRef &tag, AttributesMap &attributes, StringRef &contents)
Definition: Database.cxx:234
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
FakeBkgTools::Database::AttributesMap
std::map< std::string, StringRef > AttributesMap
Definition: Database.h:175
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
FakeBkgTools::Database::importNominalTH1
void importNominalTH1(const TH1 *hist, EfficiencyType type, const StringRef &paramX, const StringRef &paramY, const StringRef &paramZ, float scale, StatMode statMode, unsigned short &globalStatUID, const StringRef &xmlStream)
Methods used to load from ROOT files.
Definition: Database.cxx:843
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
FakeBkgTools::Database::EfficiencyType
EfficiencyType
Definition: Database.h:43
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
FakeBkgTools::Database::selectEfficiency
static FakeBkgTools::Efficiency * selectEfficiency(FakeBkgTools::ParticleData &pd, const xAOD::IParticle &p, EfficiencyType type)
Methods used to fill efficiencies.
Definition: Database.cxx:1041
rerun_display.client
client
Definition: rerun_display.py:31
python.selector.AtlRunQuerySelectorLhcOlc.sd
sd
Definition: AtlRunQuerySelectorLhcOlc.py:612
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
FakeBkgTools::Database::MUON_FAKE_EFFICIENCY
@ MUON_FAKE_EFFICIENCY
Definition: Database.h:48
ExtractEBRunDetails.xml
xml
Definition: ExtractEBRunDetails.py:239
SG::AuxElement::auxdataConst
Accessor< T, ALLOC >::const_reference_type auxdataConst(const std::string &name) const
Fetch an aux data variable, as a const reference.
cm
const double cm
Definition: Simulation/ISF/ISF_FastCaloSim/ISF_FastCaloSimParametrization/tools/FCAL_ChannelMap.cxx:25
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
FakeBkgTools::Database::Param::Level::PARTICLE
@ PARTICLE
FakeBkgTools::Database::InputType::CORRECTION
@ CORRECTION
FakeBkgTools::Database::systIndexToUID
static constexpr unsigned short systIndexToUID(unsigned short index)
Definition: Database.h:220
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
jobOptions_CavernBackground.inputType
inputType
Definition: jobOptions_CavernBackground.py:21
FakeBkgTools::Database::m_typesToFill
const std::bitset< N_EFFICIENCY_TYPES > m_typesToFill
Definition: Database.h:242
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
FakeBkgTools::Database::MUON_REAL_EFFICIENCY
@ MUON_REAL_EFFICIENCY
Definition: Database.h:47
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
lumiFormat.i
int i
Definition: lumiFormat.py:92
z
#define z
trigmenu_modify_prescale_json.fp
fp
Definition: trigmenu_modify_prescale_json.py:53
FakeBkgTools::Database::StatMode::NONE
@ NONE
FakeBkgTools::Database::addDimension
void addDimension(EfficiencyTable &table, unsigned paramUID, const StringRef &contents)
Definition: Database.cxx:510
python.selection.integer
integer
Definition: selection.py:18
Recovery.avg
def avg(a, b)
Definition: Recovery.py:79
FakeBkgTools::Database::m_convertWhenMissing
const bool m_convertWhenMissing
Definition: Database.h:244
FakeBkgTools::Database::m_lineOffset
std::vector< std::size_t > m_lineOffset
Definition: Database.h:255
FakeBkgTools::Database::TAU_FAKE_EFFICIENCY
@ TAU_FAKE_EFFICIENCY
Definition: Database.h:51
FakeBkgTools::Database::reset
void reset()
Definition: Database.cxx:33
FakeBkgTools::Database::readEfficiencyFromTable
int readEfficiencyFromTable(Efficiency &eff, const EfficiencyTable &table, std::map< unsigned, EfficiencyTable::BoundType > &cachedParamVals, const xAOD::IParticle &p, const xAOD::EventInfo &eventInfo, std::string &error) const
Definition: Database.cxx:129
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
file
TFile * file
Definition: tile_monitor.h:29
PixelAthClusterMonAlgCfg.zmax
zmax
Definition: PixelAthClusterMonAlgCfg.py:176
FakeBkgTools::Database::PHOTON_ELE_FAKE_FACTOR_SF
@ PHOTON_ELE_FAKE_FACTOR_SF
Definition: Database.h:54
FakeBkgTools::Database::PHOTON_ELE_FAKE_FACTOR
@ PHOTON_ELE_FAKE_FACTOR
Definition: Database.h:53
FakeBkgTools::Database::m_normFactors
std::map< std::string, float > m_normFactors
Definition: Database.h:256
python.xAODType.dummy
dummy
Definition: xAODType.py:4
FakeBkgTools::Database::MUON_FAKE_FACTOR
@ MUON_FAKE_FACTOR
Definition: Database.h:49
FakeBkgTools::Database::selectTypesToFill
static std::bitset< N_EFFICIENCY_TYPES > selectTypesToFill(Client client)
This function is only called by the Database constructor.
Definition: Database.cxx:1070
FakeBkgTools::Database::ELECTRON_FAKE_EFFICIENCY
@ ELECTRON_FAKE_EFFICIENCY
Definition: Database.h:45
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
compute_lumi.denom
denom
Definition: compute_lumi.py:76
FakeBkgTools::Database::Param::Level::EVENT
@ EVENT
FakeBkgTools::Database::getTypeAsString
static std::string getTypeAsString(EfficiencyType type)
Definition: Database.cxx:1127
min
#define min(a, b)
Definition: cfImp.cxx:40
python.update_ci_reference_files.mr
mr
Definition: update_ci_reference_files.py:415
FakeBkgTools::Database::getListOfNames
std::vector< std::string > getListOfNames(const StringRef &stream)
Definition: Database.cxx:318
FakeBkgTools::Database::statIndexToUID
static constexpr unsigned short statIndexToUID(unsigned short index)
Definition: Database.h:221
FakeBkgTools::Database::StatMode::UNSPECIFIED
@ UNSPECIFIED
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
FakeBkgTools::Database::Param::Type::PREDEFINED_FLOAT
@ PREDEFINED_FLOAT
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
compileRPVLLRates.c2
c2
Definition: compileRPVLLRates.py:361
FakeBkgTools::Database::isSystUID
static constexpr bool isSystUID(unsigned short uid)
Definition: Database.h:222
plotBeamSpotVxVal.bin
int bin
Definition: plotBeamSpotVxVal.py:83
FakeBkgTools::Database::retrieveParameterValue
bool retrieveParameterValue(const xAOD::IParticle &p, const xAOD::EventInfo &eventInfo, const Param &param, EfficiencyTable::BoundType &val) const
Definition: Database.cxx:1010
FakeBkgTools::Database::TAU_FAKE_FACTOR
@ TAU_FAKE_FACTOR
Definition: Database.h:52
python.ext.table_printer.table
list table
Definition: table_printer.py:81
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
FakeBkgTools::ParticleData::real_efficiency
Efficiency real_efficiency
Definition: FakeBkgInternals.h:86
FakeBkgTools::Database::maxIndex
static constexpr unsigned short maxIndex()
Definition: Database.h:209
dq_make_web_display.rv
def rv
Definition: dq_make_web_display.py:219
FakeBkgTools::Database::getAttribute
static ReturnValue getAttribute(const StringRef &tag, const AttributesMap &attributes, const std::string &type, const char *ref, ReturnValue rv, Args... args)
Helper methods.
Definition: Database.cxx:351
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
FakeBkgTools::Database::getNormalizationFactor
float getNormalizationFactor(const TH1 *hist, EfficiencyType type, const StringRef &norm, const StringRef &xmlStream)
Definition: Database.cxx:828
FakeBkgTools::Uncertainty::up
float up
Definition: FakeBkgInternals.h:28
FakeBkgTools::Database::ELECTRON_FAKE_FACTOR
@ ELECTRON_FAKE_FACTOR
Definition: Database.h:46
DeMoScan.index
string index
Definition: DeMoScan.py:362
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
a
TList * a
Definition: liststreamerinfos.cxx:10
Muon::EnumDefs::GLOBAL
@ GLOBAL
Definition: MuonEnumDefs.h:13
y
#define y
FakeBkgTools::Client::ALL_METHODS
@ ALL_METHODS
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
ref
const boost::regex ref(r_ef)
FakeBkgTools::Database::indexFromUID
static constexpr unsigned short indexFromUID(unsigned short uid)
Definition: Database.h:219
FakeBkgTools::Database::InputType::CENTRAL_VALUE
@ CENTRAL_VALUE
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:534
xmax
double xmax
Definition: listroot.cxx:61
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
FakeBkgTools::Database::Param::Type::CUSTOM_INT
@ CUSTOM_INT
LArCellBinning.step
step
Definition: LArCellBinning.py:158
FakeBkgTools::Database::addSysts
void addSysts(const StringRef &tag, const StringRef &contents, const AttributesMap &attributes)
Definition: Database.cxx:376
collListGuids.attributes
attributes
Definition: collListGuids.py:46
xAODType::Tau
@ Tau
The object is a tau (jet)
Definition: ObjectType.h:49
FakeBkgTools::Database::isStatUID
static constexpr bool isStatUID(unsigned short uid)
Definition: Database.h:223
doL1CaloHVCorrections.parts
parts
Definition: doL1CaloHVCorrections.py:334
dqt_zlumi_alleff_HIST.eff
int eff
Definition: dqt_zlumi_alleff_HIST.py:113
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
merge.status
status
Definition: merge.py:17
COOLRates.target
target
Definition: COOLRates.py:1106
FakeBkgTools::Database::dropXmlComments
void dropXmlComments(std::string &buffer)
Methods used to parse XML files.
Definition: Database.cxx:288
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
FakeBkgTools::ParticleData::fake_efficiency
Efficiency fake_efficiency
Definition: FakeBkgInternals.h:86
FakeBkgTools::Database::addTables
void addTables(const StringRef &particleType, const AttributesMap &attributes, const StringRef &contents, TFile *source=nullptr)
Definition: Database.cxx:419
FakeBkgTools::Database::importCustomROOT
void importCustomROOT(const StringRef &tag, const StringRef &contents, const AttributesMap &attributes)
Definition: Database.cxx:679
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
checkFileSG.words
words
Definition: checkFileSG.py:76
error
Definition: IImpactPoint3dEstimator.h:70
FakeBkgTools::Database::StatMode::PER_BIN
@ PER_BIN
python.compressB64.c
def c
Definition: compressB64.py:93
length
double length(const pvec &v)
Definition: FPGATrackSimLLPDoubletHoughTransformTool.cxx:26
readCCLHist.float
float
Definition: readCCLHist.py:83
FakeBkgTools::Database::ELECTRON_REAL_EFFICIENCY
@ ELECTRON_REAL_EFFICIENCY
Definition: Database.h:44
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
fitman.k
k
Definition: fitman.py:528
ymax
double ymax
Definition: listroot.cxx:64
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
FakeBkgTools::Database::dropRootTag
void dropRootTag(std::string &buffer)
Definition: Database.cxx:304