30 using ColumnarTool::ColumnarTool;
133 if (sf.get() == coll)
return i;
146 ATH_MSG_INFO(
"The tool using working point " <<
m_wp <<
" is already initialized.");
147 return StatusCode::SUCCESS;
149 if (
m_wp.find(
"Iso") != std::string::npos) {
152 }
else if (
m_wp.find(
"BadMuon") != std::string::npos) {
156 }
else if (
m_wp.find(
"TTVA") != std::string::npos) {
161 ATH_MSG_FATAL(Form(
"Only Medium identification WP is supported for LRT muons. You chose %s.",
m_wp.c_str()));
162 return StatusCode::FAILURE;
179 ATH_MSG_DEBUG(
"We are running Isolation or TTVA or High Pt reco SF, so we use Zmumu based SF for the whole pt range!");
182 ATH_MSG_INFO(
"Low pt SF turned off as crossover threshold is negative! Using Zmumu based SF for all pt values.");
187 std::set<std::string> decorations{
195 if (decorations.size() != 6){
196 ATH_MSG_FATAL(
"At least one of the decoration names for scale-factor/ data-efficiency / mc-efficiency is not uniquely defined... Please check your properties");
197 return StatusCode::FAILURE;
219 ATH_MSG_ERROR(
"loading the central value systematic set failed");
220 return StatusCode::FAILURE;
227 return StatusCode::FAILURE;
232 addSubtool (*sf_set);
234 return StatusCode::SUCCESS;
239 info = evtInfo.operator->();
241 ATH_MSG_ERROR(
"Could not retrieve the xAOD::EventInfo. Return 999999");
250 ATH_MSG_DEBUG(
"The current event is a data event. Return runNumber instead.");
251 return acc.runNumberAcc (info);
253 if (!
acc.acc_rnd.isAvailable(info)) {
254 ATH_MSG_WARNING(
"Failed to find the RandomRunNumber decoration. Please call the apply() method from the PileupReweightingTool before hand in order to get period dependent SFs. You'll receive SFs from the most recent period.");
256 }
else if (
acc.acc_rnd(info) == 0) {
257 ATH_MSG_DEBUG(
"Pile up tool has given runNumber 0. Return SF from latest period.");
260 return acc.acc_rnd(info);
269 info = evtInfo.operator->();
271 ATH_MSG_ERROR(
"Could not retrieve the xAOD::EventInfo. Return 999999");
283 return m_current_sf->retrieveSF(mu, RunNumber)->ScaleFactor(mu, sf);
291 return m_current_sf->retrieveSF(mu, RunNumber)->ApplyScaleFactor(mu);
300 return m_current_sf->retrieveSF(mu, RunNumber)->ScaleFactorReplicas(mu, sfs);
308 return m_current_sf->retrieveSF(mu, RunNumber)->ApplyScaleFactorReplicas(mu, nreplicas);
316 return m_current_sf->retrieveSF(mu, RunNumber)->DataEfficiency(mu, eff);
324 return m_current_sf->retrieveSF(mu, RunNumber)->ApplyDataEfficiency(mu);
332 return m_current_sf->retrieveSF(mu, RunNumber)->DataEfficiencyReplicas(mu, sf_err);
340 return m_current_sf->retrieveSF(mu, RunNumber)->ApplyDataEfficiencyReplicas(mu, nreplicas);
348 return m_current_sf->retrieveSF(mu, RunNumber)->MCEfficiency(mu, eff);
356 return m_current_sf->retrieveSF(mu, RunNumber)->ApplyMCEfficiency(mu);
364 return m_current_sf->retrieveSF(mu, RunNumber)->MCEfficiencyReplicas(mu, sf_err);
372 return m_current_sf->retrieveSF(mu, RunNumber)->ApplyMCEfficiencyReplicas(mu, nreplicas);
380 if (fullPathToFile.empty()) {
383 return fullPathToFile;
459 return StatusCode::SUCCESS;
465 ATH_MSG_FATAL(
"No valid systematic could be loaded. Not even the statistical uncertainties");
466 return StatusCode::FAILURE;
470 m_sf_sets.push_back( std::make_unique<EffiCollection>(*
this));
473 std::function<
unsigned int(
unsigned int,
unsigned int)> not_inB = [](
unsigned int a ,
unsigned int b){
474 unsigned int b_flipped = ~b;
475 return a & b_flipped;
488 m_sf_sets.push_back(std::make_unique < EffiCollection > (nominal, *
this, syst.first, syst.second,
false));
489 m_sf_sets.push_back(std::make_unique < EffiCollection > (nominal, *
this, syst.first, syst.second,
true));
493 if (!sf->CheckConsistency()) {
494 ATH_MSG_FATAL(
"Inconsistent scalefactor maps have been found for "<<(sf->getSystSet() ?sf->getSystSet()->name() :
"UNKOWN"));
495 return StatusCode::FAILURE;
499 addSubtool (*sf_set);
500 return StatusCode::SUCCESS;
503 std::map<std::string, unsigned int> syst_map;
506 std::set<std::string> files_to_look_up{
517 std::function<
int(
const std::string&)> get_bit = [
this](
const std::string& file_name){
530 std::function<void(
const std::string&,
int)> insert_bit =[&syst_map](
const std::string& key,
unsigned int bit){
531 if (syst_map.find(key) == syst_map.end()) syst_map.insert(std::pair<std::string, unsigned int>(key,bit));
532 else syst_map[key] = syst_map[key] | bit;
534 for (
const auto& look_up : files_to_look_up){
535 std::unique_ptr<TFile> root_file(TFile::Open(look_up.c_str(),
"READ"));
536 if (!root_file || !root_file->IsOpen()){
544 insert_bit(
"STAT", get_bit(look_up));
549 TTree* syst_tree =
nullptr;
550 root_file->GetObject(
"Systematics", syst_tree);
555 ATH_MSG_DEBUG(
"The file "<<look_up<<
" does not contain any systematic tree. No break down for that one will be considered");
556 insert_bit(
"SYS",get_bit(look_up));
564 std::string* syst_name =
nullptr;
565 bool is_symmetric(0), has_pt_sys(0), uncorrelated(0);
566 if (syst_tree->SetBranchAddress(
"Name", &syst_name) != 0 ||
567 syst_tree->SetBranchAddress(
"IsSymmetric", &is_symmetric) != 0 ||
568 syst_tree->SetBranchAddress(
"HasPtDependentSys", &has_pt_sys) !=0 ||
569 syst_tree->SetBranchAddress(
"CanBeUncorrelated", &uncorrelated) !=0){
572 ATH_MSG_FATAL(
"Although "<<look_up<<
" has a systematic tree. There is no proper connection to the branches");
576 for (
int i =0; syst_tree->GetEntry(i); ++i){
577 insert_bit( *syst_name, get_bit(look_up));
595 if (!collection->getSystSet()){
596 ATH_MSG_FATAL(
"No systematic defined for scale-factor map. ");
599 result.insert(*collection->getSystSet());
615 return StatusCode::FAILURE;
619 std::unordered_map<CP::SystematicSet, EffiCollection*>::const_iterator itr =
m_filtered_sys_sets.find (systConfig);
625 ATH_MSG_ERROR(
"Unsupported combination of systematics passed to the tool! ");
626 return StatusCode::FAILURE;
633 std::vector<std::unique_ptr<EffiCollection>>
::const_iterator coll_itr = std::find_if(
m_sf_sets.begin(),
m_sf_sets.end(),[&mySysConf](
const std::unique_ptr<EffiCollection>&
a){return a->isAffectedBySystematic(mySysConf);});
636 return StatusCode::FAILURE;
638 m_filtered_sys_sets.insert(std::pair<SystematicSet, EffiCollection*>(systConfig, coll_itr->get()));
644 for (std::set<SystematicVariation>::const_iterator t = mySysConf.
begin(); t != mySysConf.
end(); ++t) {
645 if ((*t).isToyVariation()) {
649 std::pair<unsigned, float>
pair = (*t).getToyVariation();
651 ATH_MSG_WARNING(
"Could not apply systematic " << (*t).name() <<
" for bin " <<
pair.first);
652 return StatusCode::FAILURE;
654 return StatusCode::SUCCESS;
658 return StatusCode::SUCCESS;
662 throw std::runtime_error(
"No systematic has been loaded. Cannot return any syst-bin") ;
663 ATH_MSG_FATAL(
"No systematic has been loaded. Cannot return any syst-bin");
670 ATH_MSG_WARNING(
"No systematic has been loaded. Cannot return any syst-bin");
676 for (std::set<SystematicVariation>::const_iterator t = systConfig.
begin(); t != systConfig.
end(); ++t) {
677 if ((*t).isToyVariation()) {
678 std::pair<unsigned, float>
pair = (*t).getToyVariation();
682 ATH_MSG_ERROR(
"The given systematic " << systConfig.
name() <<
" is not an unfolded one. Return unknown bin ");
683 return "unknown bin";
703 throw std::runtime_error(
"Error in getEfficiencyScaleFactor");
712 auto eventInfo =
acc.eventInfoCol(event);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
static const std::vector< std::string > systematics
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Return value from object correction CP tools.
@ Error
Some error happened during the object correction.
@ OutOfValidityRange
Input object is out of validity range.
@ Ok
The correction was done successfully.
The EffiCollection class handles the 5 different scale-factor maps binned in time.
@ JPsiAnalysis
Distinguish these two because the systematics are named with an extra LOWPT.
@ Central
The five different scale-factor maps.
std::string filename_LRTCentral() const
LRT muons have their own efficiency maps.
std::string m_custom_file_Calo
bool uncorrelate_sys() const
Returns a boolean whether the uncorrelation of systematics has been switched on.
std::string m_custom_file_LRTLowPt
std::string filename_HighEta() const
High-eta reconstruction scale-factors are not obtained by the means of are not obtained by the means ...
std::string m_custom_file_LowPtCalo
std::string m_efficiency_decoration_name_data
std::string resolve_file_location(const std::string &filename) const
utility method to 'dress' a filename using the path resolver
virtual SystematicSet recommendedSystematics() const override
returns: the list of all systematics this tool recommends to use
virtual int getUnCorrelatedSystBin(const xAOD::Muon &mu) const override
virtual CorrectionCode getDataEfficiencyReplicas(const xAOD::Muon &mu, std::vector< float > &sf_err, const xAOD::EventInfo *info=0) const
virtual CorrectionCode getMCEfficiency(const xAOD::Muon &mu, float &eff, const xAOD::EventInfo *info=0) const override
Obtain the muon efficiency measured using the MC.
virtual StatusCode applySystematicVariation(const SystematicSet &systConfig) override
effects: configure this tool for the given list of systematic variations.
virtual CorrectionCode getMCEfficiencyReplicas(const xAOD::Muon &mu, std::vector< float > &sf_err, const xAOD::EventInfo *info=0) const
virtual CorrectionCode applyEfficiencyScaleFactorReplicas(const xAOD::Muon &mu, int nreplicas=50, const xAOD::EventInfo *info=0) const override
decorate the muon with a set of SF replica weights.
std::string mc_effi_replica_deocration() const
CP::MuonEfficiencyType m_Type
std::string m_sf_decoration_name
virtual std::string getUncorrelatedSysBinName(unsigned int Bin) const override
float m_lowpt_threshold
threshold below which low-pt SF (i.e. from JPsi) should be used
virtual CorrectionCode applyMCEfficiency(const xAOD::Muon &mu, const xAOD::EventInfo *info=0) const override
std::string filename_Calo() const
Reconstruction scale-factors have a dedicated map for calo-tag muons around |\eta|<0....
std::string m_custom_file_HighEta
std::map< std::string, unsigned int > lookUpSystematics()
Scale-factor files since Moriond2019 contain the breakdown of systematics into their individual compo...
std::string m_wp
the working point to operate on
std::string sf_decoration() const
The apply<Blah> methods decorate their result directly to the muon.
std::string m_custom_file_LowPt
virtual SystematicSet affectingSystematics() const override
returns: the list of all systematics this tool can be affected by
std::unique_ptr< Accessors > m_accessors
std::unordered_map< CP::SystematicSet, EffiCollection * > m_filtered_sys_sets
It turned out that the code spends a large time in the look up of the systematics.
bool use_2D_iso_corrections() const
option to set if we want to use 1D or 2D isolation SFs
void callSingleEvent(columnar::MuonRange muons, columnar::EventInfoId event) const
virtual CorrectionCode applyDataEfficiency(const xAOD::Muon &mu, const xAOD::EventInfo *info=0) const override
decorate a muon with the efficiency information
virtual CorrectionCode applyEfficiencyScaleFactor(const xAOD::Muon &mu, const xAOD::EventInfo *info=0) const override
decorate the muon with scale factor information
std::string sf_replica_decoration() const
std::vector< std::unique_ptr< EffiCollection > > m_sf_sets
This vector stores all scale-factor maps.
unsigned int getRandomRunNumber(const xAOD::EventInfo *info) const
std::string filename_Central() const
The following methods are meant to propagate information from the central tool to the subtool managin...
virtual ~MuonEfficiencyScaleFactors()
std::string m_custom_file_Combined
std::string data_effi_replica_decoration() const
virtual CorrectionCode getEfficiencyScaleFactorReplicas(const xAOD::Muon &mu, std::vector< float > &sf_err, const xAOD::EventInfo *info=0) const override
replica generation
virtual StatusCode initialize() override
initialize the tool once all settings are in place!
size_t getNCollections() const
Returns the number of EffiCollections stored in this class.
std::string filename_LowPtCalo() const
std::string m_iso_jet_dR
Name of the decoration to catch up the close by jets.
float lowPtTransition() const
If the pt of the muon is below that threshold the J/Psi or Upsilon map is used given that it's availa...
std::string m_custom_file_LRTCombined
EffiCollection * m_current_sf
Pointer to the current active map in terms of systematics.
virtual bool isAffectedBySystematic(const SystematicVariation &systematic) const override
returns: whether this tool is affected by the given systematis
virtual CorrectionCode applyDataEfficiencyReplicas(const xAOD::Muon &mu, int nreplicas=50, const xAOD::EventInfo *info=0) const
std::string mc_effi_decoration() const
std::string filename_LRTLowPt() const
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
size_t getPosition(const EffiCollection *coll) const
Returns the position of the collection in the syst set vector.
std::string data_effi_decoration() const
virtual CorrectionCode getDataEfficiency(const xAOD::Muon &mu, float &eff, const xAOD::EventInfo *info=0) const override
Obtain the muon efficiency measured using the data.
CP::MuonEfficiencyType measurement() const
Returns the type of the measurement to be carried out... E.g. Reco/TTVA/Iso.
virtual void callEvents(columnar::EventContextRange events) const override
virtual CorrectionCode applyMCEfficiencyReplicas(const xAOD::Muon &mu, int nreplicas=50, const xAOD::EventInfo *info=0) const
std::string m_efficiency_decoration_name_mc
bool use_lrt() const
option to set if we want to use LRT muons
std::string filename_LowPt() const
Returns the scale-factor maps from a complementary scale-factor measurement using the J/Psi or Upsilo...
virtual CorrectionCode getEfficiencyScaleFactor(const xAOD::Muon &mu, float &sf, const xAOD::EventInfo *info=0) const override
Retrieve the Scale factor and decorate the muon.
std::string m_calibration_version
subfolder to load from the calibration db
const std::string & close_by_jet_decoration() const
Returns the string telling the tool in which float AuxElement the information of the separation to th...
bool m_useLRT
Turn on if using LRT objects.
MuonEfficiencyScaleFactors(const std::string &name)
StatusCode LoadInputs()
load the SF histos
CP::SystematicSet m_affectingSys
This module implements the central registry for handling systematic uncertainties with CP tools.
static SystematicRegistry & getInstance()
Get the singleton instance of the registry for the curren thread.
StatusCode registerSystematics(const IReentrantSystematicsTool &tool)
effects: register all the systematics from the tool
Class to wrap a set of SystematicVariations.
std::string name() const
returns: the systematics joined into a single string.
const_iterator end() const
description: const iterator to the end of the set
const_iterator begin() const
description: const iterator to the beginning 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...
@ IS_SIMULATION
true: simulation, false: data
Select isolated Photons, Electrons and Muons.
static std::string EfficiencyTypeName(CP::MuonEfficiencyType M)
ObjectId< ContainerId::muon > MuonId
AccessorTemplate< ContainerId::eventInfo, CT, ColumnAccessMode::input, CM > EventInfoAccessor
AccessorTemplate< ContainerId::muon, CT, ColumnAccessMode::output, CM > MuonDecorator
ObjectRange< ContainerId::eventContext > EventContextRange
ObjectId< ContainerId::eventContext > EventContextId
ObjectRange< ContainerId::muon > MuonRange
ObjectId< ContainerId::eventInfo > EventInfoId
AccessorTemplate< ContainerId::muon, CT, ColumnAccessMode::input, CM > MuonAccessor
EventInfo_v1 EventInfo
Definition of the latest event info version.
Muon_v1 Muon
Reference the current persistent version:
static const SG::AuxElement::Accessor< ElementLink< IParticleContainer > > acc("originalObjectLink")
Object used for setting/getting the dynamic decoration in question.
columnar::EventInfoAccessor< uint32_t > runNumberAcc
columnar::MuonDecorator< char > validDec
columnar::EventInfoAccessor< unsigned int > acc_rnd
columnar::EventInfoHelpers::EventTypeAccessor eventTypeAcc
columnar::EventInfoAccessor< columnar::ObjectColumn > eventInfoCol
columnar::MuonAccessor< columnar::ObjectColumn > muons
columnar::MuonDecorator< float > sfDec