38 "list of XML/ROOT files storing the efficiencies [default = {}]. If left empty, the tool "
39 "assumes that efficiencies are provided by the user as decorations (xAOD) or class "
40 "members (standalone) of the lepton objects");
43 "Selection used to increment total yield / fill histograms [default = \""
47 "Process used to increment total yield / fill histograms [default = \""
51 "MeV or GeV -- keep consistent between the input (IParticle decorations/members) "
52 "and the configuration files! [default = \"MeV\"]");
55 "set to 'true' to compute fake factors from fake efficiencies if only the latter "
56 "are provided in the config files (and vice-versa) [default = false]");
59 "Name (and type) of the decoration used to indicate whether leptons pass the 'tight' "
60 "requirements or not [default = \"Tight,as_char\"]");
63 "Name of ntuple file with results from a subset of the data");
66 "complementary to ProgressFileName, specifies the directory inside the file where the "
67 "results are stored [default = \"\"]");
85 return StatusCode::FAILURE;
97 return StatusCode::FAILURE;
100 std::unique_ptr<CP::ISelectionReadAccessor> tightAccessor;
106 ATH_MSG_WARNING(
"no input file(s) provided with the reference efficiencies, will try reading the efficiencies directly from the IParticle");
112 if(!db)
return StatusCode::FAILURE;
116 return StatusCode::FAILURE;
124 return StatusCode::SUCCESS;
130 std::string filename;
136 auto pos = filename.rfind(
".xml");
137 if(pos == filename.length()-4)
142 pos = filename.rfind(
".root");
143 if(pos == filename.length()-5)
148 ATH_MSG_ERROR(
"File extension not supported for " << filename);
154 unsigned line1 =
m_database->getXmlLineNumber(err.location.ptr);
155 unsigned line2 =
m_database->getXmlLineNumber(err.location.endptr);
156 ATH_MSG_INFO(
"Exception caught while reading file " << filename <<
", details follow");
157 std::string fullmsg =
"(while parsing XML, line";
158 if(line2 != line1) fullmsg +=
"s " + std::to_string(line1) +
" - " + std::to_string(line2);
159 else fullmsg +=
" " + std::to_string(line1);
160 fullmsg +=
"): " + err.reason;
166 ATH_MSG_INFO(
"Exception caught while reading file " << filename <<
", details follow");
179 return StatusCode::FAILURE;
187 #ifdef FAKEBKGTOOLS_ATLAS_ENVIRONMENT
190 eventInfo = &iparticles.eventInfo;
194 for(
const auto& pp : iparticles)
217 return StatusCode::FAILURE;
219 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));
274 return StatusCode::FAILURE;
276 const std::string
name = h1->GetName();
279 for(;itr!=enditr;++itr)
284 return StatusCode::FAILURE;
286 if(
name == itr->first->GetName())
break;
296 return StatusCode::SUCCESS;
304 return StatusCode::FAILURE;
306 const std::string
name = h2->GetName();
309 for(;itr!=enditr;++itr)
314 return StatusCode::FAILURE;
316 if(
name == itr->first->GetName())
break;
326 return StatusCode::SUCCESS;
334 return StatusCode::FAILURE;
336 const std::string
name = h3->GetName();
339 for(;itr!=enditr;++itr)
344 return StatusCode::FAILURE;
346 if(
name == itr->first->GetName())
break;
356 return StatusCode::SUCCESS;
362 if(std::string(lhs->GetName()) != rhs->GetName())
error =
"names";
363 else if(lhs->GetDimension() != rhs->GetDimension())
error =
"dimensions";
364 else if(lhs->GetNbinsX()!=rhs->GetNbinsX() || lhs->GetNbinsY()!=rhs->GetNbinsY() || lhs->GetNbinsZ()!=rhs->GetNbinsZ())
error =
"number of bins";
367 for(
auto getAxis : std::initializer_list<
const TAxis*(TH1::*)()
const>{&TH1::GetXaxis, &TH1::GetYaxis, &TH1::GetZaxis})
369 auto lhsAxis=(lhs->*getAxis)(), rhsAxis=(rhs->*getAxis)();
370 for(
int i=0;i<=lhsAxis->GetNbins();++i)
372 auto x=lhsAxis->GetBinUpEdge(i),
y=rhsAxis->GetBinUpEdge(i),
width=lhsAxis->GetBinWidth(i?i:1);
379 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.");
380 return StatusCode::FAILURE;
382 return StatusCode::SUCCESS;
389 ATH_MSG_ERROR(
"This function can be called only once the tool has been initialized");
392 std::bitset<Database::N_EFFICIENCY_TYPES> affects;
394 if(stat) affects = stat->affects;
398 if(syst) affects = syst->affects;
401 ATH_MSG_ERROR(
"uncertainty with UID " << std::hex <<
uid << std::dec <<
" not found in database");
414 return info.substr(0, info.size()-2);
421 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...");
422 throw std::logic_error(
"BaseFakeBkgTool::identifyCpSystematicVariation() called before initialization");
426 if(!std::regex_match(bn, smr, std::regex(
"FAKEBKG_(STAT|SYST)_VAR(\\d+)")))
return {{0}, 0.f};
427 unsigned index = std::stol(smr[2].
str());
442 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...");
443 throw std::logic_error(
"BaseFakeBkgTool::affectingSystematics() called before initialization");
446 for(
int step=0;step<2;++step)
448 std::string
type = step?
"STAT" :
"SYST";
450 for(
int i=0;i<
imax;++i)
452 std::string
name =
"FAKEBKG_" +
type +
"_VAR" + std::to_string(i);
469 ATH_MSG_ERROR(
"This function can be called only once the tool has been initialized");
470 throw std::logic_error(
"BaseFakeBkgTool::applySystematicVariation() called before initialization");
474 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.");
475 throw std::logic_error(
"BaseFakeBkgTool::applySystematicVariation() called at a wrong time");
478 if(!systConfig.
size())
481 return StatusCode::SUCCESS;
487 return StatusCode::SUCCESS;
491 if(
sc != StatusCode::SUCCESS)
return sc;
492 std::unique_ptr<UncertaintyList> uncertainties;
493 for(
auto& sysvar : mysys)
498 ATH_MSG_ERROR(
"The systematic variation " << sysvar.name() <<
" is not recognized, despite being present in affectingSystematics()...");
499 return StatusCode::FAILURE;
501 if(!uncertainties) uncertainties.reset(
new UncertaintyList(var.first, var.second));
502 else uncertainties->extraVariation(var.first, var.second);
506 auto emplaced =
m_systSetDict.emplace(systConfig, std::move(*uncertainties));
510 return StatusCode::SUCCESS;
523 ATH_MSG_ERROR(
"This function can be called only once the tool has been initialized");
530 ATH_MSG_WARNING(
"Systematic variation " + systematic.
name() +
" is not recognized by BaseFakeBkgTool");
536 return "Total statistical uncertainty in the event yield";
542 info =
"Statistical uncertainty affecting ";
550 info =
"Systematic uncertainty \"" + syst->name +
"\" affecting ";
554 ATH_MSG_ERROR(
"uncertainty with UID " << std::hex << UID << std::dec <<
" not found in database");
623 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...");
626 bool up=
true, down=
true;
627 auto pos1=nuisanceParameter.find(
"__up"), pos2=nuisanceParameter.find(
"__down");
628 if(pos1!=std::string::npos && pos1+4==nuisanceParameter.length()) down =
false;
629 else if(pos2!=std::string::npos && pos2+6==nuisanceParameter.length()) up =
false;
630 std::string np = nuisanceParameter.substr(0, std::min(pos1, pos2));
631 for(
unsigned i=0;i<
m_database->numberOfSysts();++i)
634 if(syst && syst->name==np)
636 std::string
name =
"FAKEBKG_SYST_VAR" + std::to_string(i);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(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.