36 "list of XML/ROOT files storing the efficiencies [default = {}]. If left empty, the tool "
37 "assumes that efficiencies are provided by the user as decorations (xAOD) or class "
38 "members (standalone) of the lepton objects");
41 "Selection used to increment total yield / fill histograms [default = \""
45 "Process used to increment total yield / fill histograms [default = \""
49 "MeV or GeV -- keep consistent between the input (IParticle decorations/members) "
50 "and the configuration files! [default = \"MeV\"]");
53 "set to 'true' to compute fake factors from fake efficiencies if only the latter "
54 "are provided in the config files (and vice-versa) [default = false]");
57 "Name (and type) of the decoration used to indicate whether leptons pass the 'tight' "
58 "requirements or not [default = \"Tight,as_char\"]");
61 "Name of ntuple file with results from a subset of the data");
64 "complementary to ProgressFileName, specifies the directory inside the file where the "
65 "results are stored [default = \"\"]");
83 return StatusCode::FAILURE;
95 return StatusCode::FAILURE;
98 std::unique_ptr<CP::ISelectionReadAccessor> tightAccessor;
104 ATH_MSG_WARNING(
"no input file(s) provided with the reference efficiencies, will try reading the efficiencies directly from the IParticle");
110 if(!db)
return StatusCode::FAILURE;
114 return StatusCode::FAILURE;
122 return StatusCode::SUCCESS;
128 std::string filename;
134 auto pos = filename.rfind(
".xml");
135 if(pos == filename.length()-4)
140 pos = filename.rfind(
".root");
141 if(pos == filename.length()-5)
146 ATH_MSG_ERROR(
"File extension not supported for " << filename);
152 unsigned line1 =
m_database->getXmlLineNumber(err.location.ptr);
153 unsigned line2 =
m_database->getXmlLineNumber(err.location.endptr);
154 ATH_MSG_INFO(
"Exception caught while reading file " << filename <<
", details follow");
155 std::string fullmsg =
"(while parsing XML, line";
156 if(line2 != line1) fullmsg +=
"s " + std::to_string(line1) +
" - " + std::to_string(line2);
157 else fullmsg +=
" " + std::to_string(line1);
158 fullmsg +=
"): " + err.reason;
164 ATH_MSG_INFO(
"Exception caught while reading file " << filename <<
", details follow");
177 return StatusCode::FAILURE;
185 #ifdef FAKEBKGTOOLS_ATLAS_ENVIRONMENT
188 eventInfo = &iparticles.eventInfo;
192 for(
const auto& pp : iparticles)
215 return StatusCode::FAILURE;
217 ATH_MSG_DEBUG(
"particle has fake fact. = " << d.fake_factor.value(
this) <<
", fake eff. = " << d.fake_efficiency.value(
this) <<
", real eff. = " << d.real_efficiency.value(
this));
272 return StatusCode::FAILURE;
274 const std::string
name = h1->GetName();
277 for(;itr!=enditr;++itr)
282 return StatusCode::FAILURE;
284 if(
name == itr->first->GetName())
break;
294 return StatusCode::SUCCESS;
302 return StatusCode::FAILURE;
304 const std::string
name = h2->GetName();
307 for(;itr!=enditr;++itr)
312 return StatusCode::FAILURE;
314 if(
name == itr->first->GetName())
break;
324 return StatusCode::SUCCESS;
332 return StatusCode::FAILURE;
334 const std::string
name = h3->GetName();
337 for(;itr!=enditr;++itr)
342 return StatusCode::FAILURE;
344 if(
name == itr->first->GetName())
break;
354 return StatusCode::SUCCESS;
360 if(std::string(lhs->GetName()) != rhs->GetName())
error =
"names";
361 else if(lhs->GetDimension() != rhs->GetDimension())
error =
"dimensions";
362 else if(lhs->GetNbinsX()!=rhs->GetNbinsX() || lhs->GetNbinsY()!=rhs->GetNbinsY() || lhs->GetNbinsZ()!=rhs->GetNbinsZ())
error =
"number of bins";
365 for(
auto getAxis : std::initializer_list<
const TAxis*(TH1::*)()
const>{&TH1::GetXaxis, &TH1::GetYaxis, &TH1::GetZaxis})
367 auto lhsAxis=(lhs->*getAxis)(), rhsAxis=(rhs->*getAxis)();
368 for(
int i=0;i<=lhsAxis->GetNbins();++i)
370 auto x=lhsAxis->GetBinUpEdge(i),
y=rhsAxis->GetBinUpEdge(i),
width=lhsAxis->GetBinWidth(i?i:1);
377 ATH_MSG_ERROR(
"the registered histogram \"" << lhs->GetName() <<
"\" is not compatible with the one saved in the in-progress ROOT file (mismatching " <<
error <<
"). Or, you tried registering two different histograms with the same name.");
378 return StatusCode::FAILURE;
380 return StatusCode::SUCCESS;
387 ATH_MSG_ERROR(
"This function can be called only once the tool has been initialized");
390 std::bitset<Database::N_EFFICIENCY_TYPES> affects;
392 if(stat) affects = stat->affects;
396 if(syst) affects = syst->affects;
399 ATH_MSG_ERROR(
"uncertainty with UID " << std::hex <<
uid << std::dec <<
" not found in database");
412 return info.substr(0, info.size()-2);
419 ATH_MSG_ERROR(
"This function can be called only once the tool has been initialized, since the number of systematic variations depends on the configuration...");
420 throw std::logic_error(
"BaseFakeBkgTool::identifyCpSystematicVariation() called before initialization");
424 if(!std::regex_match(bn, smr, std::regex(
"FAKEBKG_(STAT|SYST)_VAR(\\d+)")))
return {{0}, 0.f};
425 unsigned index = std::stol(smr[2].
str());
440 ATH_MSG_ERROR(
"This function can be called only once the tool has been initialized, since the number of systematic variations depends on the configuration...");
441 throw std::logic_error(
"BaseFakeBkgTool::affectingSystematics() called before initialization");
444 for(
int step=0;step<2;++step)
446 std::string
type = step?
"STAT" :
"SYST";
448 for(
int i=0;i<
imax;++i)
450 std::string
name =
"FAKEBKG_" +
type +
"_VAR" + std::to_string(i);
467 ATH_MSG_ERROR(
"This function can be called only once the tool has been initialized");
468 throw std::logic_error(
"BaseFakeBkgTool::applySystematicVariation() called before initialization");
472 ATH_MSG_ERROR(
"this particular method doesn't support multiple calls to applySystematicVariation(), or after the first call to addEvent(). Please use a separate instance of the tool for each variation.");
473 throw std::logic_error(
"BaseFakeBkgTool::applySystematicVariation() called at a wrong time");
476 if(!systConfig.
size())
479 return StatusCode::SUCCESS;
485 return StatusCode::SUCCESS;
489 if(
sc != StatusCode::SUCCESS)
return sc;
490 std::unique_ptr<UncertaintyList> uncertainties;
491 for(
auto& sysvar : mysys)
496 ATH_MSG_ERROR(
"The systematic variation " << sysvar.name() <<
" is not recognized, despite being present in affectingSystematics()...");
497 return StatusCode::FAILURE;
499 if(!uncertainties) uncertainties.reset(
new UncertaintyList(var.first, var.second));
500 else uncertainties->extraVariation(var.first, var.second);
504 auto emplaced =
m_systSetDict.emplace(systConfig, std::move(*uncertainties));
508 return StatusCode::SUCCESS;
521 ATH_MSG_ERROR(
"This function can be called only once the tool has been initialized");
528 ATH_MSG_WARNING(
"Systematic variation " + systematic.
name() +
" is not recognized by BaseFakeBkgTool");
537 info =
"Statistical uncertainty affecting ";
545 info =
"Systematic uncertainty \"" + syst->name +
"\" affecting ";
549 ATH_MSG_ERROR(
"uncertainty with UID " << std::hex << UID << std::dec <<
" not found in database");
618 ATH_MSG_ERROR(
"This function can be called only once the tool has been initialized, since the number of systematic variations depends on the configuration...");
621 bool up=
true, down=
true;
622 auto pos1=nuisanceParameter.find(
"__up"), pos2=nuisanceParameter.find(
"__down");
623 if(pos1!=std::string::npos && pos1+4==nuisanceParameter.length()) down =
false;
624 else if(pos2!=std::string::npos && pos2+6==nuisanceParameter.length()) up =
false;
625 std::string np = nuisanceParameter.substr(0, std::min(pos1, pos2));
626 for(
unsigned i=0;i<
m_database->numberOfSysts();++i)
629 if(syst && syst->name==np)
631 std::string
name =
"FAKEBKG_SYST_VAR" + std::to_string(i);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_INFO(x,...)
std::string PathResolverFindDataFile(const std::string &logical_file_name)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
Class to wrap a set of SystematicVariations.
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
size_t size() const
returns: size of the set
static StatusCode filterForAffectingSystematics(const SystematicSet &systConfig, const SystematicSet &affectingSystematics, SystematicSet &filteredSystematics)
description: filter the systematics for the affected systematics returns: success guarantee: strong f...
float parameter() const
description: the numeric parameter contained in the subvariation(), or 0 if the subvariation can't be...
std::string basename() const
description: the base name, i.e.
const std::string & name() const
description: the full systematics name, for use in strings, etc.
DataVector adapter that acts like it holds const pointers.
Select isolated Photons, Electrons and Muons.
StatusCode makeSelectionReadAccessor(const std::string &expr, std::unique_ptr< ISelectionReadAccessor > &accessor, bool defaultToChar)
make the ISelectionReadAccessor for the given name
@ Photon
The object is a photon.
@ Muon
The object is a muon.
@ Electron
The object is an electron.
@ Tau
The object is a tau (jet).
EventInfo_v1 EventInfo
Definition of the latest event info version.
TauJet_v3 TauJet
Definition of the current "tau version".
Muon_v1 Muon
Reference the current persistent version:
Electron_v1 Electron
Definition of the current "egamma version".
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.