Loading [MathJax]/extensions/tex2jax.js
 |
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 511 of file Database.cxx.
515 const bool integer = param.integer();
516 const std::string
fp =
"[+-]?[0-9]*\\.?[0-9]+(?:[Ee][+-]?[0-9]+)?";
517 const std::string
pattern =
"^\\s*\\[\\s*(?:(?:-inf\\s*,\\s*|-?)inf|(?:-inf\\s*,\\s*)?"
518 +
fp +
"(?:\\s*,\\s*" +
fp +
")*(?:\\s*,\\s*inf)?)\\s*\\]\\s*$";
524 throw(XmlError(
contents) <<
"invalid format for the range of the parameter " << param.name);
528 auto& bounds =
table.m_bounds;
529 table.m_dimensions.emplace_back();
530 auto&
dim =
table.m_dimensions.back();
531 dim.paramUID = paramUID;
532 dim.iMinBound =
table.m_bounds.size();
535 if(
integer &&
dim.nBounds < 1)
throw(XmlError(
contents) <<
"should specify at least one bin boundary for parameter " << param.name);
536 if(!
integer && (
dim.nBounds < 2))
throw(XmlError(
contents) <<
"should specify at least two bin boundaries for parameter " << param.name);
537 for(
auto&
c :
line)
if(
c==
',' ||
c==
'[' ||
c==
']')
c =
' ';
538 std::stringstream
ss(
line);
539 for(
int i=0;
i<
dim.nBounds;++
i)
541 EfficiencyTable::BoundType
x;
543 else ss >>
x.as_float;
546 if(
i==0 ||
i==(
dim.nBounds-1))
553 if(x_s==
"inf" || x_s==
"-inf")
555 bool defMax = (x_s.front() !=
'-');
559 else throw(XmlError(
contents) <<
"parsing error (invalid 'inf' string)");
561 if(
ss.fail())
throw(XmlError(
contents) <<
"parsing error (can't read int/float boundary)");
565 if(
integer ? (bounds.back().as_int >
x.as_int) : (bounds.back().as_float >
x.as_float))
567 throw(XmlError(
contents) <<
"bin boundaries must be sorted in increasing order");
576 bounds.push_back(bounds.back());
577 bounds.back().as_int += 1;
◆ addParams()
Definition at line 360 of file Database.cxx.
367 if(std::any_of(
m_params.begin(),
m_params.end(), [&](
const Param&
p){ return p.name == name; }))
369 throw(XmlError(
contents) <<
"parameter \"" <<
name <<
"\" was already declared");
◆ addStat()
Definition at line 409 of file Database.cxx.
413 if(
pos)
throw(XmlError(
pos) <<
"exceeded max number of statistical uncertainties");
414 else throw(GenericError() <<
"exceeded max number of statistical uncertainties");
◆ addSysts()
Definition at line 377 of file Database.cxx.
379 std::bitset<N_EFFICIENCY_TYPES> affects;
382 auto targetMatches = [&](
const char*
a,
const char*
b) ->
bool
394 if(!
matched)
throw(XmlError(
tag) <<
"the value \"" <<
target <<
"\" specified for the attribute \"affects\" is not recognized");
396 if(affects.none())
throw(XmlError(
tag) <<
"missing or empty attribute \"affects\"");
399 if(
name ==
"stat")
throw(XmlError(
contents) <<
"systematics can't be named \"stat\"");
400 if(std::any_of(
m_systs.begin(),
m_systs.end(), [&](
const SystDef&
s){ return s.name==name && (affects&s.affects).any(); }))
402 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");
404 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 420 of file Database.cxx.
429 else throw(XmlError(
particle) <<
"unexpected error: unsupported particle type " <<
particle.str());
434 unsigned short globalStatUID = 0;
443 const TH1*
hist =
nullptr;
444 if(
tag==
"bin" ||
tag==
"table" ||
tag==
"TH1")
448 if(!
source)
throw(XmlError(
tag) <<
"histograms can only be imported inside <ROOT>...</ROOT> blocks!");
449 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)");
450 auto name = subcontents.trim();
452 if(!
hist)
throw(XmlError(subcontents) <<
"can't find any histogram named \"" <<
name <<
"\" in the file " <<
source->GetName());
453 auto&
norm = subattributes.at(
"TH1/norm");
455 throw(XmlError(
norm) <<
"normalization of input histograms is only accepted for 'input=\"correction\"'");
457 importNominalTH1(
hist,
type, subattributes.at(
"TH1/X"), subattributes.at(
"TH1/Y"), subattributes.at(
"TH1/Z"),
scale, statMode, globalStatUID, subcontents);
463 auto initialNumberOfBins =
table.numberOfBins();
464 std::map<StringRef, unsigned> dimBins;
465 for(
unsigned uid=0; uid<
m_params.size(); ++uid)
474 if(
tag ==
"bin" &&
table.numberOfBins() > 1)
throw(XmlError(
tag) <<
"use a <table> instead of a <bin> tag to hold several values");
477 else if(
table.numberOfBins() != initialNumberOfBins)
throw(XmlError(
tag) <<
"extra binned dimensions do not make sense");
478 if(
tag==
"TH1" ||
tag==
"bin")
480 auto&
label = subattributes.at(
tag +
"/label");
483 float normFactor {0};
487 assert (
tag ==
"bin");
488 normFactor = 1.f /
table.m_efficiencies[0].nominal;
490 if(!std::isnormal(normFactor) || normFactor<=0.)
throw(XmlError(
label) <<
"computed normalization factor is 0 / NaN / infinite / negative");
492 throw(XmlError(
label) <<
"label \"" <<
label.str() <<
"\" has already been used");
496 else throw(XmlError(
tag) <<
"unknown/unexpected XML tag \"" <<
tag.str() <<
"\"");
◆ addValues()
Definition at line 581 of file Database.cxx.
583 const std::string fpv =
"(?:[0-9]+\\.)?[0-9]+(?:[Ee][+-]?[0-9]+)?", fpu = fpv +
"\\s*\\%?";
584 const std::string
pattern =
"^\\s*" + fpv +
"(?:\\s*(?:\\+(?:\\s*" + fpu +
"\\s*)?-|-(?:\\s*" + fpu +
"\\s*)?\\+)\\s*" + fpu +
"\\s*\\([_[:alnum:]]+\\))*\\s*";
594 if(!std::regex_search(
ptr,
contents.endptr,
cm, rxValidFormat))
597 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) <<
" [...]");
599 StringRef valref{
ptr,
static_cast<std::size_t
>(
cm.length())};
601 std::string
value = valref.str();
602 value.erase(std::remove_if(
value.begin(),
value.end(), [](
char c){ return std::isspace(c); }),
value.end());
604 for(
auto&
c :
value)
if(
c==
'(' ||
c==
')')
c =
' ';
607 table.m_efficiencies.emplace_back();
608 auto&
eff =
table.m_efficiencies.back();
610 bool foundStat =
false;
611 for(
unsigned i=0;
i<nErrs;++
i)
618 if(
c2==
'+' ||
c2==
'-')
620 ss >>
c2 >> uncval.
up >> sysname;
623 uncval.
up *= 0.01f *
eff.nominal;
633 uncval.
up *= 0.01f *
eff.nominal;
636 ss >> uncval.
down >> sysname;
639 uncval.
down *= 0.01f *
eff.nominal;
643 if(
ss.bad())
throw(XmlError(valref) <<
"unexpected parsing error");
644 if(std::signbit(uncval.
up) != std::signbit(uncval.
down))
throw(XmlError(valref) <<
"one-sided up/down errors");
647 uncval.
up = -uncval.
up;
652 if(sysname ==
"stat")
654 if(foundStat)
throw(XmlError(valref) <<
"there can be only one source of statistical uncertainty per bin");
655 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\")");
662 [&](
const SystDef&
sd){ return sd.name==sysname && sd.affects[type]; });
663 if(
sys ==
m_systs.end())
throw(XmlError(valref) <<
"the systematic \"" << sysname <<
"\" has either not been defined, or does not affect this type of efficiency");
667 if(!
eff.uncertainties.emplace(uid, uncval).second)
669 throw(XmlError(valref) <<
"source of uncertainty \"" << sysname <<
"\" specified twice");
674 if(
table.m_efficiencies.size() !=
table.numberOfBins())
676 throw(XmlError(
contents) <<
"the number of tabulated efficiencies (" <<
table.m_efficiencies.size()
677 <<
") is inconsistent with the number of bins (" <<
table.numberOfBins() <<
")");
◆ assertNoLeftover()
void Database::assertNoLeftover |
( |
std::stringstream & |
ss, |
|
|
const StringRef & |
pos |
|
) |
| |
|
inlinestaticprotected |
Definition at line 500 of file Database.cxx.
507 throw(XmlError(
pos) <<
"unexpected parsing error (leftover data \"" <<
line <<
"\")");
◆ dropRootTag()
void Database::dropRootTag |
( |
std::string & |
buffer | ) |
|
|
protected |
Definition at line 305 of file Database.cxx.
307 const std::vector<std::string>
keys = {
"<efficiencies>",
"</efficiencies>"};
311 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 289 of file Database.cxx.
293 while(std::regex_search(
buffer, smr, rx))
301 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 65 of file Database.cxx.
67 std::map<unsigned, EfficiencyTable::BoundType> cachedParamVals;
79 bool found_central =
false;
81 eff->uncertainties.clear();
91 for(
auto&
table : relevantTables->second)
94 if(
status < 0)
return false;
99 error =
"while retrieving " +
getTypeAsString(
type) +
", found two non-orthogonal tables providing the central value";
102 found_central =
true;
111 if(
type != wantedType)
113 if(
eff == &
pd.fake_factor)
117 for(
auto& kv :
eff->uncertainties) kv.second *=
k;
119 else if(
eff == &
pd.fake_efficiency)
123 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 338 of file Database.cxx.
340 if(attr.str() ==
ref)
return rv;
341 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 352 of file Database.cxx.
354 std::string attrname =
tag.str() +
"/" +
type;
356 if(!attr)
throw(XmlError(
tag) <<
"unspecified value for attribute \"" <<
type <<
"\"");
◆ getListOfNames()
std::vector< std::string > Database::getListOfNames |
( |
const StringRef & |
stream | ) |
|
|
protected |
Definition at line 319 of file Database.cxx.
321 std::vector<std::string>
words;
324 while(std::getline(
ss,
w,
','))
326 std::size_t
i =
w.find_first_not_of(
" \t");
327 std::size_t j =
w.find_last_not_of(
" \t");
328 if(
i == std::string::npos)
330 throw(XmlError(
stream) <<
"this should be a comma-separated list of names");
332 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 830 of file Database.cxx.
833 if(!
norm)
return 1.f;
834 auto normType =
norm.str();
836 else if(normType !=
"none")
839 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 1141 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 803 of file Database.cxx.
806 if(
hist->GetNbinsX()!=1 ||
hist->GetNbinsY()!=1 ||
hist->GetNbinsZ()!=1)
810 for(
int i=1;
i<=
hist->GetNbinsX();++
i)
811 for(
int j=1;j<=
hist->GetNbinsY();++j)
812 for(
int k=1;
k<=
hist->GetNbinsZ();++
k)
814 double x =
hist->GetBinContent(
i, j,
k);
815 if(
x == 0.)
continue;
816 double w =
hist->GetBinError(
i, j,
k);
817 if(
w == 0.)
throw(XmlError(xmlStream) <<
"bin with error = 0 encountered when trying to normalize histogram " <<
hist->GetName() <<
" to weighted bins average");
824 else avg = 1. /
hist->GetBinContent(1);
825 if(!std::isnormal(
avg) ||
avg<=0.)
throw(XmlError(xmlStream) <<
"something bad happened when trying to compute the weighted average of histogram \""
826 <<
hist->GetName() <<
"\" bins, the result ended up 0 / NaN / infinite / negative");
◆ getXmlLineNumber()
unsigned Database::getXmlLineNumber |
( |
const char * |
pos | ) |
const |
◆ importCustomROOT()
Definition at line 681 of file Database.cxx.
684 if(!
filename.length())
throw(XmlError(rootTag) <<
"the 'file' attribute must be specified!");
691 throw(XmlError(rootTag) <<
"unable to locate/open the file " <<
filename);
701 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 742 of file Database.cxx.
744 const std::string
prefix =
"^(FakeFactor|FakeEfficiency|RealEfficiency|FakeRate|FakeRateSF)",
suffix =
"_([[:w:]][^_]+)(__[[:w:]]+)?$";
753 throw(GenericError() <<
"unable to locate/open the file " <<
filename);
757 if(!
keys)
throw(GenericError() <<
"unable to list keys in the file " <<
filename <<
" (corrupted?)");
759 const StringRef nullStream;
760 unsigned short dummy;
765 for(
int i=0;
i<
keys->GetSize();++
i)
767 TKey*
key =
static_cast<TKey*
>(
keys->At(
i));
769 std::string keyType =
key->GetClassName();
771 if(keyType==
"TH1F" || keyType==
"TH1D") nDims = 1 * std::regex_match(
key->GetName(),
mr, rxTH1);
772 else if(keyType==
"TH2F" || keyType==
"TH2D") nDims = 2 * std::regex_match(
key->GetName(),
mr, rxTH2);
773 else if(keyType==
"TH3F" || keyType==
"TH3D") nDims = 3 * std::regex_match(
key->GetName(),
mr, rxTH3);
775 if(nDims < 1)
throw(GenericError() <<
"don't know what to do with histogram named \"" <<
key->GetName() <<
"\" (please check naming conventions)");
776 TH1*
hist =
static_cast<TH1*
>(
key->ReadObj());
778 std::string sss =
mr[1].str() +
"-" +
mr[2].str();
785 bool systTH1 = (
mr[
mr.size()-1].str() !=
"");
786 if(
step==0 && !systTH1)
789 StringRef paramY = (nDims>1) ? StringRef(
mr[4].
first,
mr[4].
second) : StringRef();
790 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 845 of file Database.cxx.
848 const bool useDefaults = !xmlStream;
850 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");
854 const int nDims = paramZ? 3 : paramY? 2 : 1;
855 if(
hist->GetDimension() != nDims)
857 if(xmlStream)
throw(XmlError(xmlStream) <<
"histogram " <<
hist->GetName() <<
" doesn't have the expected dimension");
858 else throw(GenericError() <<
"histogram " <<
hist->GetName() <<
" doesn't have the expected dimension");
862 for(
int j=0;j<nDims;++j)
864 std::string
name = ((j==2)? paramZ : (j==1)? paramY : paramX).
str();
865 const TAxis*
axis = (j==2)?
hist->GetZaxis() : (j==1)?
hist->GetYaxis() :
hist->GetXaxis();
866 if(useDefaults &&
name ==
"eta" &&
axis->GetBinLowEdge(1) >= 0)
name =
"|eta|";
867 table.m_dimensions.emplace_back();
868 auto&
dim =
table.m_dimensions.back();
869 auto itr = std::find_if(
m_params.begin(),
m_params.end(), [&](
const Param&
p){ return p.name == name; });
879 else throw(XmlError(j? paramY : paramX) <<
"parameter \"" <<
name <<
"\" has not been defined beforehand");
886 dim.iMinBound =
table.m_bounds.size();
887 dim.nBounds =
axis->GetNbins() + 1;
889 table.m_bounds.emplace_back();
891 else table.m_bounds.back().as_float = std::numeric_limits<float>::lowest();
892 for(
int k=1;
k<
dim.nBounds-1;++
k)
894 table.m_bounds.emplace_back();
896 else table.m_bounds.back().as_float =
axis->GetBinUpEdge(
k);
898 table.m_bounds.emplace_back();
905 const unsigned xmax =
table.m_dimensions.front().nBounds;
906 const unsigned ymax =
table.m_dimensions.size()>1?
table.m_dimensions[1].nBounds : 2;
907 const unsigned zmax =
table.m_dimensions.size()>2?
table.m_dimensions[2].nBounds : 2;
912 table.m_efficiencies.emplace_back();
913 auto&
eff =
table.m_efficiencies.back();
920 eff.uncertainties.emplace(uid, uncdata);
◆ importSystTH1()
Definition at line 925 of file Database.cxx.
927 if(!
m_tables[
type].
size())
throw(GenericError() <<
"there should be another histogram containing central values to accompany the histogram " <<
hist->GetName());
929 const int xmax =
table.m_dimensions.front().nBounds;
930 const int ymax =
table.m_dimensions.size()>1?
table.m_dimensions[1].nBounds : 2;
931 const int zmax =
table.m_dimensions.size()>2?
table.m_dimensions[2].nBounds : 2;
934 throw(GenericError() <<
"binning mismatch between the nominal histogram and " <<
hist->GetName());
938 auto itr = std::find_if(
m_systs.begin(),
m_systs.end(), [&](
const SystDef&
sys){ return sys.name==sysname; });
942 itr->affects.set(
type);
953 bool syst_central_equal_nom_central =
true;
954 bool syst_errors_equal_zero =
true;
955 bool syst_errors_equal_nom_errors =
true;
957 auto eff =
table.m_efficiencies.begin();
962 if (fabs ((
float)
eff->nominal - (
float)
hist->GetBinContent(
x,
y,
z)) > 0.001 ){ syst_central_equal_nom_central =
false;}
963 if (
hist->GetBinError(
x,
y,
z) != 0 ) { syst_errors_equal_zero =
false;}
965 for(
auto& kv :
eff->uncertainties)
968 stat_up = kv.second.up;
break;
970 if ( fabs((
float)
hist->GetBinError(
x,
y,
z) - (
float) stat_up ) > 0.001) { syst_errors_equal_nom_errors =
false;}
990 if (syst_central_equal_nom_central){
991 if (syst_errors_equal_nom_errors ){
992 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. ");
993 }
else if (syst_errors_equal_zero ) {
1004 if(!
eff->uncertainties.emplace(uid, uncdata).second)
1006 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 186 of file Database.cxx.
192 auto begpos =
xml.tellg();
194 std::size_t
bufferSize = 1.05 *
static_cast<std::size_t
>(
xml.tellg() - begpos);
200 if(!
xml.is_open())
throw(GenericError() <<
"unable to open file " <<
filename);
208 while(
line.length() && (
line.back()==
'\n' ||
line.back()==
'\r'))
line.pop_back();
227 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 56 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 130 of file Database.cxx.
134 for(
const auto&
dim :
table.m_dimensions)
137 auto ins = cachedParamVals.emplace(
dim.paramUID, EfficiencyTable::BoundType{});
138 auto&
val = ins.first->second;
143 error =
"can't retrieve value of parameter \"" + param.name +
"\"";
148 auto ubound = std::upper_bound(
first, last,
val,
149 [=](
auto x,
auto y){
return param.integer() ? (
x.as_int<
y.as_int) : (
x.as_float<
y.as_float); });
150 if(ubound==
first || ubound==last)
157 if(
bin < 0)
return 0;
162 error =
"unknown table type (tool implementation incomplete!)";
166 for(
auto& kv :
eff.uncertainties) kv.second *=
ref.nominal;
167 for(
auto& kv :
ref.uncertainties)
171 if(!
eff.uncertainties.emplace(kv.first,
eff.nominal*kv.second).second)
173 error =
"central values and corrections must use different systematic uncertainties";
178 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 235 of file Database.cxx.
241 std::string
pattern =
"^\\s*(<([[:alnum:]]+)((?:\\s+\\|?[_[:alnum:]]+\\|?\\s*=\\s*\"[_[:alnum:]\\s,-\\[\\]\\.\\|]+\")*)\\s*>)(.*?)</\\2>\\s*";
246 throw(XmlError(
stream) <<
"unable to find next tag");
248 tag.set(
stream.ptr+cmr.position(2), cmr.length(2));
252 auto cpos = cmr.size()-1;
255 stream.ptr += cmr.length();
◆ readTagAttributes()
Definition at line 258 of file Database.cxx.
264 for(
int i=0;
i<nAttr;++
i)
pattern +=
"\\s+(\\|?[_[:alnum:]]+\\|?)\\s*=\\s*\"([_[:alnum:]\\s,-\\[\\]\\.\\|]+)\"";
269 throw(XmlError(
stream) <<
"unexpected error (internal))");
271 for(
unsigned i=1;
i<cmr.size();
i+=2)
273 auto attr = cmr[
i].str();
277 throw(XmlError(
stream.ptr+cmr.position(
i), attr.length()) <<
"invalid attribute \"" << attr <<
"\"");
281 throw(XmlError(
stream.ptr+cmr.position(
i), attr.length()) <<
"empty value for attribute \"" << attr <<
"\"");
283 auto& attrVal = itr->second;
284 if(attrVal)
throw(XmlError(
stream.ptr+cmr.position(
i), attr.length()) <<
"the attribute \"" << attr <<
"\" has already been specified for that tag");
285 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 46 of file Database.cxx.
51 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 708 of file Database.cxx.
715 const std::vector<std::string>
parts = {
"electron",
"muon",
"tau"};
716 for(
const auto&
p :
parts)
◆ retrieveParameterValue()
Definition at line 1012 of file Database.cxx.
1014 #ifdef FAKEBKGTOOLS_ATLAS_ENVIRONMENT
1015 float energy_scale = (
m_useGeV? 0.001f : 1.f);
1017 float energy_scale = 1;
1023 if(param.name==
"pt")
val.as_float = energy_scale *
p.pt();
1024 else if(param.name==
"eta")
val.as_float =
p.eta();
1025 else if(param.name==
"|eta|")
val.as_float = fabs(
p.eta());
1026 else if(param.name==
"phi")
val.as_float =
p.phi();
1043 val.as_float =
acc(eventInfo);
1047 val.as_int =
acc(eventInfo);
◆ selectEfficiency()
Methods used to fill efficiencies.
Definition at line 1055 of file Database.cxx.
◆ selectTypesToFill()
auto Database::selectTypesToFill |
( |
Client |
client | ) |
|
|
staticprotected |
This function is only called by the Database constructor.
Definition at line 1084 of file Database.cxx.
1086 std::bitset<N_EFFICIENCY_TYPES>
result;
1107 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".
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)
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)
constexpr int pow(int base, int exp) noexcept