From 2e1461a62e3491c3a931ca49919a0e357581f285 Mon Sep 17 00:00:00 2001 From: Julien Maurer <julien.maurer@cern.ch> Date: Thu, 13 Sep 2018 22:00:52 +0300 Subject: [PATCH] fixed faulty run number reading when running on data (needed for checkTriggerMatching()), and added new function getRelevantTriggers() for ATR-18743 Former-commit-id: 868e504dbf1e8ce7e2e79a294c2a54ef4b28898c --- .../ITrigGlobalEfficiencyCorrectionTool.h | 3 ++ .../Root/Calculator.cxx | 36 +++++++++++++++++-- .../TrigGlobalEfficiencyCorrectionTool.cxx | 28 ++++++++++++--- .../Calculator.h | 1 + .../TrigGlobalEfficiencyCorrectionTool.h | 1 + 5 files changed, 62 insertions(+), 7 deletions(-) diff --git a/PhysicsAnalysis/Interfaces/TriggerAnalysisInterfaces/TriggerAnalysisInterfaces/ITrigGlobalEfficiencyCorrectionTool.h b/PhysicsAnalysis/Interfaces/TriggerAnalysisInterfaces/TriggerAnalysisInterfaces/ITrigGlobalEfficiencyCorrectionTool.h index 5e32f609453..f454d5a8363 100644 --- a/PhysicsAnalysis/Interfaces/TriggerAnalysisInterfaces/TriggerAnalysisInterfaces/ITrigGlobalEfficiencyCorrectionTool.h +++ b/PhysicsAnalysis/Interfaces/TriggerAnalysisInterfaces/TriggerAnalysisInterfaces/ITrigGlobalEfficiencyCorrectionTool.h @@ -41,6 +41,9 @@ public: template<typename... Args> auto checkTriggerMatching(bool& matched, Args&... args) -> std::enable_if_t<validArgs<Args...>(0), CP::CorrectionCode>; + /// This will fill the 'triggers' argument with the names of the triggers relevant for the current run number, among those specified in the tool configuration + virtual CP::CorrectionCode getRelevantTriggers(std::vector<std::string>& triggers) = 0; + /// These should in principle not be used (except by unit tests), as the CP tools require the EventInfo decoration "RandomRunNumber" to be present virtual CP::CorrectionCode getEfficiencyScaleFactor(unsigned runNumber, const std::vector<const xAOD::IParticle*>& particles, double& efficiencyScaleFactor) = 0; virtual CP::CorrectionCode getEfficiency(unsigned runNumber, const std::vector<const xAOD::IParticle*>& particles, double& efficiencyData, double& efficiencyMc) = 0; diff --git a/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/Root/Calculator.cxx b/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/Root/Calculator.cxx index 44ed309cea9..f7feade5f1f 100644 --- a/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/Root/Calculator.cxx +++ b/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/Root/Calculator.cxx @@ -66,12 +66,15 @@ bool Calculator::addPeriod(ImportData& data, const std::pair<unsigned,unsigned>& } if(success) { - if(m_parent->m_validTrigMatchTool) + if(data.adaptTriggerListForTriggerMatching(triggers)) { - if(!data.adaptTriggerListForTriggerMatching(triggers)) return false; m_periods.emplace_back(boundaries, std::move(helper.m_formula), std::move(triggers)); } - else m_periods.emplace_back(boundaries, std::move(helper.m_formula)); + else + { + if(m_parent->m_validTrigMatchTool) return false; + m_periods.emplace_back(boundaries, std::move(helper.m_formula)); + } } else { @@ -201,6 +204,33 @@ bool Calculator::checkTriggerMatching(TrigGlobalEfficiencyCorrectionTool& parent return true; } +bool Calculator::getRelevantTriggersForUser(TrigGlobalEfficiencyCorrectionTool& parent, std::vector<std::string>& triggers, unsigned runNumber) +{ + triggers.clear(); + m_parent = &parent; + auto period = getPeriod(runNumber); + if(!period) return false; + if(!period->m_triggers.size()) + { + ATH_MSG_ERROR("Empty list of triggers for run number " << runNumber << " (was there a configuration issue? please check for warnings during initialization)"); + return false; + } + bool success = true; + auto notfound = parent.m_dictionary.end(); + for(auto& trig : period->m_triggers) + { + auto itr = parent.m_dictionary.find(trig.name); + if(itr == notfound) + { + ATH_MSG_ERROR("can't retrieve name of trigger with hash " << trig.name << " (shouldn't happen; contact tool developers!)"); + success = false; + } + else triggers.push_back(itr->second); + } + if(!success) triggers.clear(); + return success; +} + Efficiencies Calculator::getCachedTriggerLegEfficiencies(const Lepton& lepton, unsigned runNumber, std::size_t leg, bool& success) { auto insertion = m_cachedEfficiencies.emplace(std::make_pair(&lepton, leg), Efficiencies()); diff --git a/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/Root/TrigGlobalEfficiencyCorrectionTool.cxx b/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/Root/TrigGlobalEfficiencyCorrectionTool.cxx index ed6933de003..513c3dc528f 100644 --- a/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/Root/TrigGlobalEfficiencyCorrectionTool.cxx +++ b/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/Root/TrigGlobalEfficiencyCorrectionTool.cxx @@ -647,14 +647,23 @@ bool TrigGlobalEfficiencyCorrectionTool::getTriggerLegEfficiencies(const xAOD::M bool TrigGlobalEfficiencyCorrectionTool::retrieveRunNumber(unsigned& runNumber) { + runNumber = 0; auto eventInfo = evtStore()->retrieve<const xAOD::EventInfo>("EventInfo"); - if(!eventInfo || !m_runNumberDecorator.isAvailable(*eventInfo)) + if(!eventInfo) { - ATH_MSG_ERROR("Can't retrieve run number from evtStore()"); - runNumber = 0; + ATH_MSG_ERROR("Can't retrieve 'EventInfo' from evtStore()"); return false; } - runNumber = m_runNumberDecorator(*eventInfo); + if(eventInfo->eventType(xAOD::EventInfo::IS_SIMULATION)) + { + if(!m_runNumberDecorator.isAvailable(*eventInfo)) + { + ATH_MSG_ERROR("Can't retrieve 'RandomRunNumber' from EventInfo"); + return false; + } + runNumber = m_runNumberDecorator(*eventInfo); + } + else runNumber = eventInfo->runNumber(); return true; } @@ -805,6 +814,17 @@ CP::CorrectionCode TrigGlobalEfficiencyCorrectionTool::checkTriggerMatching(bool return m_calculator->checkTriggerMatching(*this, matched, leptons, runNumber)? CP::CorrectionCode::Ok : CP::CorrectionCode::Error; } +CP::CorrectionCode TrigGlobalEfficiencyCorrectionTool::getRelevantTriggers(std::vector<std::string>& triggers) +{ + unsigned runNumber; + if(!retrieveRunNumber(runNumber)) + { + ATH_MSG_ERROR("Unable to retrieve run number, aborting getRelevantTriggers()"); + return CP::CorrectionCode::Error; + } + return m_calculator->getRelevantTriggersForUser(*this, triggers, runNumber)? CP::CorrectionCode::Ok : CP::CorrectionCode::Error; +} + bool TrigGlobalEfficiencyCorrectionTool::aboveThreshold(const Lepton& lepton, std::size_t leg) const { bool decision = (lepton.pt() >= m_thresholds.at(leg)); diff --git a/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrection/Calculator.h b/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrection/Calculator.h index f3947e2d6a4..df75a556271 100644 --- a/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrection/Calculator.h +++ b/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrection/Calculator.h @@ -34,6 +34,7 @@ public: bool useToys, std::size_t& uniqueElectronLeg, std::size_t& uniquePhotonLeg); bool compute(TrigGlobalEfficiencyCorrectionTool& parent, const LeptonList& leptons, unsigned runNumber, Efficiencies& efficiencies); bool checkTriggerMatching(TrigGlobalEfficiencyCorrectionTool& parent, bool& matched, const LeptonList& leptons, unsigned runNumber); + bool getRelevantTriggersForUser(TrigGlobalEfficiencyCorrectionTool& parent, std::vector<std::string>& triggers, unsigned runNumber); struct Period { diff --git a/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrectionTool.h b/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrectionTool.h index ef259a3044f..8d45ddc7f33 100644 --- a/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrectionTool.h +++ b/Trigger/TrigAnalysis/TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrection/TrigGlobalEfficiencyCorrectionTool.h @@ -54,6 +54,7 @@ public: virtual CP::SystematicCode applySystematicVariation(const CP::SystematicSet& systConfig) override; virtual CP::CorrectionCode checkTriggerMatching(bool& matched, const std::vector<const xAOD::IParticle*>& particles) override; + virtual CP::CorrectionCode getRelevantTriggers(std::vector<std::string>& triggers) override; static CP::CorrectionCode suggestElectronMapKeys(const std::map<std::string,std::string>& triggerCombination, const std::string& version, std::map<std::string,std::string>& legsPerKey); -- GitLab