![Logo](../../ATLAS-Logo-Square-Blue-RGB.png) |
ATLAS Offline Software
|
#include <Database.h>
|
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...
|
|
|
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
} |
|
|
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) |
|
|
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 ¶mX, const StringRef ¶mY, const StringRef ¶mZ, 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 ¶m, 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) |
|
Definition at line 28 of file Database.h.
◆ AttributesMap
◆ 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.
60 CENTRAL_VALUE, CORRECTION
◆ StatMode
Enumerator |
---|
GLOBAL | |
PER_BIN | |
NONE | |
UNSPECIFIED | |
Definition at line 62 of file Database.h.
◆ Database()
Database::Database |
( |
Client |
client, |
|
|
bool |
useGeV, |
|
|
bool |
convertWhenMissing |
|
) |
| |
◆ addDimension()
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.
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*$";
523 throw(XmlError(
contents) <<
"invalid format for the range of the parameter " << param.name);
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();
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)
540 EfficiencyTable::BoundType
x;
542 else ss >>
x.as_float;
545 if(
i==0 ||
i==(
dim.nBounds-1))
552 if(x_s==
"inf" || x_s==
"-inf")
554 bool defMax = (x_s.front() !=
'-');
558 else throw(XmlError(
contents) <<
"parsing error (invalid 'inf' string)");
560 if(
ss.fail())
throw(XmlError(
contents) <<
"parsing error (can't read int/float boundary)");
564 if(
integer ? (bounds.back().as_int >
x.as_int) : (bounds.back().as_float >
x.as_float))
566 throw(XmlError(
contents) <<
"bin boundaries must be sorted in increasing order");
575 bounds.push_back(bounds.back());
576 bounds.back().as_int += 1;
◆ addParams()
Definition at line 359 of file Database.cxx.
366 if(std::any_of(
m_params.begin(),
m_params.end(), [&](
const Param&
p){ return p.name == name; }))
368 throw(XmlError(
contents) <<
"parameter \"" <<
name <<
"\" was already declared");
◆ addStat()
Definition at line 408 of file Database.cxx.
412 if(
pos)
throw(XmlError(
pos) <<
"exceeded max number of statistical uncertainties");
413 else throw(GenericError() <<
"exceeded max number of statistical uncertainties");
◆ addSysts()
Definition at line 376 of file Database.cxx.
378 std::bitset<N_EFFICIENCY_TYPES> affects;
381 auto targetMatches = [&](
const char*
a,
const char*
b) ->
bool
393 if(!
matched)
throw(XmlError(
tag) <<
"the value \"" <<
target <<
"\" specified for the attribute \"affects\" is not recognized");
395 if(affects.none())
throw(XmlError(
tag) <<
"missing or empty attribute \"affects\"");
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(); }))
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");
403 if(
m_systs.size() >=
maxIndex())
throw(XmlError(
contents) <<
"exceeded max number of systematic uncertainties");
◆ addTables()
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.
428 else throw(XmlError(
particle) <<
"unexpected error: unsupported particle type " <<
particle.str());
433 unsigned short globalStatUID = 0;
442 const TH1*
hist =
nullptr;
443 if(
tag==
"bin" ||
tag==
"table" ||
tag==
"TH1")
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");
454 throw(XmlError(
norm) <<
"normalization of input histograms is only accepted for 'input=\"correction\"'");
456 importNominalTH1(
hist,
type, subattributes.at(
"TH1/X"), subattributes.at(
"TH1/Y"), subattributes.at(
"TH1/Z"),
scale, statMode, globalStatUID, subcontents);
462 auto initialNumberOfBins =
table.numberOfBins();
463 std::map<StringRef, unsigned> dimBins;
464 for(
unsigned uid=0; uid<
m_params.size(); ++uid)
473 if(
tag ==
"bin" &&
table.numberOfBins() > 1)
throw(XmlError(
tag) <<
"use a <table> instead of a <bin> tag to hold several values");
476 else if(
table.numberOfBins() != initialNumberOfBins)
throw(XmlError(
tag) <<
"extra binned dimensions do not make sense");
477 if(
tag==
"TH1" ||
tag==
"bin")
479 auto&
label = subattributes.at(
tag +
"/label");
482 float normFactor {0};
486 assert (
tag ==
"bin");
487 normFactor = 1.f /
table.m_efficiencies[0].nominal;
489 if(!std::isnormal(normFactor) || normFactor<=0.)
throw(XmlError(
label) <<
"computed normalization factor is 0 / NaN / infinite / negative");
491 throw(XmlError(
label) <<
"label \"" <<
label.str() <<
"\" has already been used");
495 else throw(XmlError(
tag) <<
"unknown/unexpected XML tag \"" <<
tag.str() <<
"\"");
◆ addValues()
Definition at line 580 of file Database.cxx.
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*";
593 if(!std::regex_search(ptr,
contents.endptr,
cm, rxValidFormat))
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) <<
" [...]");
598 StringRef valref{ptr,
static_cast<std::size_t
>(
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());
603 for(
auto&
c :
value)
if(
c==
'(' ||
c==
')')
c =
' ';
606 table.m_efficiencies.emplace_back();
607 auto&
eff =
table.m_efficiencies.back();
609 bool foundStat =
false;
610 for(
unsigned i=0;
i<nErrs;++
i)
616 if(
c2==
'+' ||
c2==
'-')
618 ss >>
c2 >> uncval.
up >> sysname;
621 uncval.
up *= 0.01f *
eff.nominal;
631 uncval.
up *= 0.01f *
eff.nominal;
634 ss >> uncval.
down >> sysname;
637 uncval.
down *= 0.01f *
eff.nominal;
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");
645 uncval.
up = -uncval.
up;
650 if(sysname ==
"stat")
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\")");
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");
665 if(!
eff.uncertainties.emplace(uid, uncval).second)
667 throw(XmlError(valref) <<
"source of uncertainty \"" << sysname <<
"\" specified twice");
672 if(
table.m_efficiencies.size() !=
table.numberOfBins())
674 throw(XmlError(
contents) <<
"the number of tabulated efficiencies (" <<
table.m_efficiencies.size()
675 <<
") is inconsistent with the number of bins (" <<
table.numberOfBins() <<
")");
◆ assertNoLeftover()
void Database::assertNoLeftover |
( |
std::stringstream & |
ss, |
|
|
const StringRef & |
pos |
|
) |
| |
|
inlinestaticprotected |
Definition at line 499 of file Database.cxx.
506 throw(XmlError(
pos) <<
"unexpected parsing error (leftover data \"" <<
line <<
"\")");
◆ dropRootTag()
void Database::dropRootTag |
( |
std::string & |
buffer | ) |
|
|
protected |
Definition at line 304 of file Database.cxx.
306 const std::vector<std::string>
keys = {
"<efficiencies>",
"</efficiencies>"};
310 while((ipos =
buffer.find(
key)) != std::string::npos)
◆ dropXmlComments()
void Database::dropXmlComments |
( |
std::string & |
buffer | ) |
|
|
protected |
Methods used to parse XML files.
Definition at line 288 of file Database.cxx.
292 while(std::regex_search(
buffer, smr, rx))
300 buffer = smr.prefix().str() + smr.suffix().str();
◆ fillEfficiencies()
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.
66 std::map<unsigned, EfficiencyTable::BoundType> cachedParamVals;
78 bool found_central =
false;
80 eff->uncertainties.clear();
90 for(
auto&
table : relevantTables->second)
93 if(
status < 0)
return false;
98 error =
"while retrieving " +
getTypeAsString(
type) +
", found two non-orthogonal tables providing the central value";
101 found_central =
true;
110 if(
type != wantedType)
116 for(
auto& kv :
eff->uncertainties) kv.second *=
k;
122 for(
auto& kv :
eff->uncertainties) kv.second *=
k;
◆ findStat()
const StatDef* FakeBkgTools::Database::findStat |
( |
unsigned short |
uid | ) |
const |
|
inline |
◆ findSyst()
const SystDef* FakeBkgTools::Database::findSyst |
( |
unsigned short |
uid | ) |
const |
|
inline |
◆ 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.
339 if(attr.str() ==
ref)
return rv;
340 throw(XmlError(attr) <<
"unsupported parameter type \"" << attr.str() <<
"\"");
◆ getAttribute() [2/3]
template<typename ReturnValue , typename... Args>
ReturnValue Database::getAttribute |
( |
const StringRef & |
attr, |
|
|
const char * |
ref, |
|
|
ReturnValue |
rv, |
|
|
Args... |
args |
|
) |
| |
|
inlinestaticprivate |
◆ getAttribute() [3/3]
template<typename ReturnValue , typename... Args>
Helper methods.
Definition at line 351 of file Database.cxx.
353 std::string attrname =
tag.str() +
"/" +
type;
355 if(!attr)
throw(XmlError(
tag) <<
"unspecified value for attribute \"" <<
type <<
"\"");
◆ getListOfNames()
std::vector< std::string > Database::getListOfNames |
( |
const StringRef & |
stream | ) |
|
|
protected |
Definition at line 318 of file Database.cxx.
320 std::vector<std::string>
words;
323 while(std::getline(
ss,
w,
','))
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)
329 throw(XmlError(
stream) <<
"this should be a comma-separated list of names");
331 words.push_back(
w.substr(
i, j-
i+1));
◆ getNormalizationFactor()
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.
831 if(!
norm)
return 1.f;
832 auto normType =
norm.str();
834 else if(normType !=
"none")
837 if(itr ==
m_normFactors.end())
throw(XmlError(
norm) <<
"unknown normalization tag \"" << normType <<
"\"");
◆ getSourceType()
◆ getTypeAsString()
This function is only meant to be used to display meaningful error messages
Definition at line 1127 of file Database.cxx.
◆ getWeightedAverage()
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.
804 if(
hist->GetNbinsX()!=1 ||
hist->GetNbinsY()!=1 ||
hist->GetNbinsZ()!=1)
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)
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");
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");
◆ getXmlLineNumber()
unsigned Database::getXmlLineNumber |
( |
const char * |
pos | ) |
const |
◆ importCustomROOT()
Definition at line 679 of file Database.cxx.
682 if(!
filename.length())
throw(XmlError(rootTag) <<
"the 'file' attribute must be specified!");
689 throw(XmlError(rootTag) <<
"unable to locate/open the file " <<
filename);
699 else throw(XmlError(
stream) <<
"unknown/unexpected XML tag \"" <<
tag <<
"\"");
◆ 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.
742 const std::string
prefix =
"^(FakeFactor|FakeEfficiency|RealEfficiency|FakeRate|FakeRateSF)",
suffix =
"_([[:w:]][^_]+)(__[[:w:]]+)?$";
751 throw(GenericError() <<
"unable to locate/open the file " <<
filename);
755 if(!
keys)
throw(GenericError() <<
"unable to list keys in the file " <<
filename <<
" (corrupted?)");
757 const StringRef nullStream;
758 unsigned short dummy;
763 for(
int i=0;
i<
keys->GetSize();++
i)
765 TKey*
key =
static_cast<TKey*
>(
keys->At(
i));
767 std::string keyType =
key->GetClassName();
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);
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();
783 bool systTH1 = (
mr[
mr.size()-1].str() !=
"");
784 if(
step==0 && !systTH1)
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();
◆ importNominalTH1()
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.
846 const bool useDefaults = !xmlStream;
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");
852 const int nDims = paramZ? 3 : paramY? 2 : 1;
853 if(
hist->GetDimension() != nDims)
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");
860 for(
int j=0;j<nDims;++j)
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; });
877 else throw(XmlError(j? paramY : paramX) <<
"parameter \"" <<
name <<
"\" has not been defined beforehand");
884 dim.iMinBound =
table.m_bounds.size();
885 dim.nBounds =
axis->GetNbins() + 1;
887 table.m_bounds.emplace_back();
889 else table.m_bounds.back().as_float = std::numeric_limits<float>::lowest();
890 for(
int k=1;
k<
dim.nBounds-1;++
k)
892 table.m_bounds.emplace_back();
894 else table.m_bounds.back().as_float =
axis->GetBinUpEdge(
k);
896 table.m_bounds.emplace_back();
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;
910 table.m_efficiencies.emplace_back();
911 auto&
eff =
table.m_efficiencies.back();
918 eff.uncertainties.emplace(uid, uncdata);
◆ importSystTH1()
Definition at line 923 of file Database.cxx.
925 if(!
m_tables[
type].
size())
throw(GenericError() <<
"there should be another histogram containing central values to accompany the histogram " <<
hist->GetName());
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;
932 throw(GenericError() <<
"binning mismatch between the nominal histogram and " <<
hist->GetName());
936 auto itr = std::find_if(
m_systs.begin(),
m_systs.end(), [&](
const SystDef&
sys){ return sys.name==sysname; });
940 itr->affects.set(
type);
951 bool syst_central_equal_nom_central =
true;
952 bool syst_errors_equal_zero =
true;
953 bool syst_errors_equal_nom_errors =
true;
955 auto eff =
table.m_efficiencies.begin();
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;}
963 for(
auto& kv :
eff->uncertainties)
966 stat_up = kv.second.up;
break;
968 if ( fabs((
float)
hist->GetBinError(
x,
y,
z) - (
float) stat_up ) > 0.001) { syst_errors_equal_nom_errors =
false;}
988 if (syst_central_equal_nom_central){
989 if (syst_errors_equal_nom_errors ){
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 ) {
1002 if(!
eff->uncertainties.emplace(uid, uncdata).second)
1004 throw(GenericError() <<
"unexpected error: tried filling twice the same systematic");
◆ 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.
191 auto begpos =
xml.tellg();
193 std::size_t bufferSize = 1.05 *
static_cast<std::size_t
>(
xml.tellg() - begpos);
195 if(bufferSize > 0x100000) bufferSize = 0x100000;
199 if(!
xml.is_open())
throw(GenericError() <<
"unable to open file " <<
filename);
207 while(
line.length() && (
line.back()==
'\n' ||
line.back()==
'\r'))
line.pop_back();
226 else throw(XmlError(
stream) <<
"unknown/unexpected XML tag \"" <<
tag.str() <<
"\"");
◆ 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 |
◆ needEventInfo()
bool Database::needEventInfo |
( |
| ) |
const |
will no longer work if some event-level parameteres are predefined
Definition at line 55 of file Database.cxx.
◆ numberOfStats()
unsigned FakeBkgTools::Database::numberOfStats |
( |
| ) |
const |
|
inline |
◆ numberOfSysts()
unsigned FakeBkgTools::Database::numberOfSysts |
( |
| ) |
const |
|
inline |
◆ readEfficiencyFromTable()
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.
133 for(
const auto&
dim :
table.m_dimensions)
136 auto ins = cachedParamVals.emplace(
dim.paramUID, EfficiencyTable::BoundType{});
137 auto&
val = ins.first->second;
142 error =
"can't retrieve value of parameter \"" + param.name +
"\"";
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)
156 if(
bin < 0)
return 0;
161 error =
"unknown table type (tool implementation incomplete!)";
165 for(
auto& kv :
eff.uncertainties) kv.second *=
ref.nominal;
166 for(
auto& kv :
ref.uncertainties)
170 if(!
eff.uncertainties.emplace(kv.first,
eff.nominal*kv.second).second)
172 error =
"central values and corrections must use different systematic uncertainties";
177 eff.nominal *=
ref.nominal;
◆ readNextTag()
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.
240 std::string
pattern =
"^\\s*(<([[:alnum:]]+)((?:\\s+\\|?[_[:alnum:]]+\\|?\\s*=\\s*\"[_[:alnum:]\\s,-\\[\\]\\.\\|]+\")*)\\s*>)(.*?)</\\2>\\s*";
245 throw(XmlError(
stream) <<
"unable to find next tag");
247 tag.set(
stream.ptr+cmr.position(2), cmr.length(2));
251 auto cpos = cmr.size()-1;
254 stream.ptr += cmr.length();
◆ readTagAttributes()
Definition at line 257 of file Database.cxx.
263 for(
int i=0;
i<nAttr;++
i)
pattern +=
"\\s+(\\|?[_[:alnum:]]+\\|?)\\s*=\\s*\"([_[:alnum:]\\s,-\\[\\]\\.\\|]+)\"";
268 throw(XmlError(
stream) <<
"unexpected error (internal))");
270 for(
unsigned i=1;
i<cmr.size();
i+=2)
272 auto attr = cmr[
i].str();
276 throw(XmlError(
stream.ptr+cmr.position(
i), attr.length()) <<
"invalid attribute \"" << attr <<
"\"");
280 throw(XmlError(
stream.ptr+cmr.position(
i), attr.length()) <<
"empty value for attribute \"" << attr <<
"\"");
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));
◆ 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.
50 if(kv.second.size())
return true;
◆ reset()
◆ resetAttributes()
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.
713 const std::vector<std::string>
parts = {
"electron",
"muon",
"tau"};
714 for(
const auto&
p :
parts)
◆ retrieveParameterValue()
Definition at line 1010 of file Database.cxx.
1012 #ifdef FAKEBKGTOOLS_ATLAS_ENVIRONMENT
1013 float energy_scale = (
m_useGeV? 0.001f : 1.f);
1015 float energy_scale = 1;
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();
◆ selectEfficiency()
Methods used to fill efficiencies.
Definition at line 1041 of file Database.cxx.
◆ selectTypesToFill()
auto Database::selectTypesToFill |
( |
Client |
client | ) |
|
|
staticprotected |
This function is only called by the Database constructor.
Definition at line 1070 of file Database.cxx.
1072 std::bitset<N_EFFICIENCY_TYPES>
result;
1093 if(
result.none())
throw(GenericError() <<
"unrecognized client type, implementation incomplete");
◆ statIndexToUID()
static constexpr unsigned short FakeBkgTools::Database::statIndexToUID |
( |
unsigned short |
index | ) |
|
|
inlinestaticconstexpr |
◆ systIndexToUID()
static constexpr unsigned short FakeBkgTools::Database::systIndexToUID |
( |
unsigned short |
index | ) |
|
|
inlinestaticconstexpr |
◆ m_convertWhenMissing
const bool FakeBkgTools::Database::m_convertWhenMissing |
|
protected |
◆ m_lineOffset
std::vector<std::size_t> FakeBkgTools::Database::m_lineOffset |
|
protected |
◆ m_normFactors
std::map<std::string, float> FakeBkgTools::Database::m_normFactors |
|
protected |
◆ m_params
std::vector<Param> FakeBkgTools::Database::m_params |
|
protected |
◆ m_stats
std::vector<StatDef> FakeBkgTools::Database::m_stats |
|
protected |
◆ m_storeAllUncertainties
bool FakeBkgTools::Database::m_storeAllUncertainties = true |
|
protected |
◆ m_systs
std::vector<SystDef> FakeBkgTools::Database::m_systs |
|
protected |
◆ m_tables
std::map<int, std::vector<EfficiencyTable> > FakeBkgTools::Database::m_tables |
|
protected |
◆ m_typesToFill
◆ m_useGeV
const bool FakeBkgTools::Database::m_useGeV |
|
protected |
◆ 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:
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Electron_v1 Electron
Definition of the current "egamma version".
Accessor< T, ALLOC >::const_reference_type auxdataConst(const std::string &name) const
Fetch an aux data variable, as a const reference.
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory, const std::string &pattern, const std::string &path)
std::string to_string(const DetectorType &type)
Efficiency real_efficiency
Photon_v1 Photon
Definition of the current "egamma version".
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
struct TBPatternUnitContext Muon
const boost::regex ref(r_ef)
@ Tau
The object is a tau (jet)
Efficiency fake_efficiency