diff --git a/Trigger/TrigT1/TrigT1CaloTools/TrigT1CaloTools/L1TriggerTowerTool.h b/Trigger/TrigT1/TrigT1CaloTools/TrigT1CaloTools/L1TriggerTowerTool.h index 0e89ea1b839152c576d8b072400b984f133b7ecf..a82a9ec78d7b960b8192e4b55d8ce34f56aa7612 100644 --- a/Trigger/TrigT1/TrigT1CaloTools/TrigT1CaloTools/L1TriggerTowerTool.h +++ b/Trigger/TrigT1/TrigT1CaloTools/TrigT1CaloTools/L1TriggerTowerTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ /////////////////////////////////////////////////////////////////// // L1TriggerTowerTool.h, @@ -21,6 +21,8 @@ #include "GaudiKernel/ServiceHandle.h" #include "TrigT1CaloToolInterfaces/IL1TriggerTowerTool.h" #include "xAODTrigL1Calo/TriggerTowerContainer.h" +#include "xAODEventInfo/EventInfo.h" +#include "StoreGate/ReadHandleKey.h" class CaloIdManager; class CaloLVL1_ID; @@ -127,6 +129,7 @@ namespace LVL1 virtual StatusCode loadFTRefs(); private: + bool isRun2() const; /** Print a vector to debug */ template <typename T> @@ -156,7 +159,6 @@ namespace LVL1 ServiceHandle<TrigConf::ILVL1ConfigSvc> m_configSvc; // one of L1CaloPprConditionsContainer{,Run2}* - bool m_isRun2; /// For Run2 strategy (LowMu, HighMu) L1CaloPprChanStrategyContainer* m_strategyContainer; @@ -178,6 +180,9 @@ namespace LVL1 bool m_correctFir; ToolHandle<LVL1::IL1DynamicPedestalProvider> m_dynamicPedestalProvider; + SG::ReadHandleKey<xAOD::EventInfo> m_eventInfoKey + { this, "EventInfoKey", "EventInfo", "" }; + ///Parameters static const int s_saturationValue = 255; static const int s_maxTowers = 7168; diff --git a/Trigger/TrigT1/TrigT1CaloTools/src/L1TriggerTowerTool.cxx b/Trigger/TrigT1/TrigT1CaloTools/src/L1TriggerTowerTool.cxx index 1aa2b23b44e4b0bc3700335706a218dc65106749..838f600d60ad6fe18761964f5fe7c55556af3884 100644 --- a/Trigger/TrigT1/TrigT1CaloTools/src/L1TriggerTowerTool.cxx +++ b/Trigger/TrigT1/TrigT1CaloTools/src/L1TriggerTowerTool.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ ////////////////////////////////////////////////////////////////////// // L1TriggerTowerTool.cxx @@ -45,6 +45,9 @@ #include "TrigT1CaloMappingToolInterfaces/IL1CaloMappingTool.h" #include "TrigT1CaloToolInterfaces/IL1DynamicPedestalProvider.h" +#include "StoreGate/ReadHandle.h" +#include "GaudiKernel/ThreadLocalContext.h" + #include <cstdint> #include <tuple> @@ -70,7 +73,6 @@ L1TriggerTowerTool::L1TriggerTowerTool(const std::string& t, m_mappingTool("LVL1::PpmCoolOrBuiltinMappingTool/PpmCoolOrBuiltinMappingTool"), m_l1CondSvc("L1CaloCondSvc", n), m_configSvc("TrigConf::TrigConfigSvc/TrigConfigSvc", n), - m_isRun2(false), m_dbFineTimeRefsTowers(0), m_correctFir(false) { @@ -134,6 +136,8 @@ StatusCode L1TriggerTowerTool::initialize() //start listening to "BeginRun" if (incSvc) incSvc->addListener(this, "BeginRun"); + + ATH_CHECK( m_eventInfoKey.initialize() ); ATH_MSG_INFO( "Initialization completed" ); @@ -155,28 +159,7 @@ void L1TriggerTowerTool::handle(const Incident& inc) ATH_MSG_DEBUG( "Resetting mapping table at start of run" ); m_idTable.clear(); - - const EventInfo* pevt = 0; // pointer for the event - StatusCode status = evtStore()->retrieve(pevt); // retrieve the pointer to the event - if(!status.isSuccess() || pevt == 0) { - ATH_MSG_WARNING("Cannot determine run"); - return; - } - // determine whether this is Run-1 or Run-2 to get the correct conditions later on - const EventID* pei = pevt->event_ID(); - const EventType* pet = pevt->event_type(); - if(pei == 0 || pet == 0) { - ATH_MSG_WARNING("Cannot determine run"); - return; - } - if(pet->test(EventType::IS_SIMULATION) || pei->run_number() >= 253377) { - m_isRun2 = true; - } else { - m_isRun2 = false; - } - ATH_MSG_INFO("Determined run to be from " << (m_isRun2 ? "Run-2" : "Run-1")); } - return; } //================= Now the actual user calls =================================== @@ -208,7 +191,9 @@ StatusCode L1TriggerTowerTool::retrieveConditions() ATH_MSG_VERBOSE( "Retrieving Conditions Containers" ); bool verbose = msgLvl(MSG::VERBOSE); - if(m_isRun2) { + bool is_run2 = isRun2(); + + if(is_run2) { CHECK_WITH_CONTEXT(m_l1CondSvc->retrieve(m_derivedRunParsContainer), "L1TriggerTowerTool"); if (std::cbegin(*m_derivedRunParsContainer) == std::cend(*m_derivedRunParsContainer)) { ATH_MSG_WARNING("Empty L1CaloDerivedRunParsContainer"); @@ -263,7 +248,7 @@ StatusCode L1TriggerTowerTool::retrieveConditions() if(verbose) { ATH_MSG_VERBOSE( "Retrieved ConditionsContainer" ); - if(m_isRun2){ + if(is_run2){ boost::any_cast<L1CaloPprConditionsContainerRun2*>(m_conditionsContainer)->dump(); } else{ boost::any_cast<L1CaloPprConditionsContainer*>(m_conditionsContainer)->dump(); @@ -271,7 +256,7 @@ StatusCode L1TriggerTowerTool::retrieveConditions() } if(verbose) { - if(m_isRun2){ + if(is_run2){ ATH_MSG_VERBOSE( "Retrieved DerivedRunParsContainer" ); m_derivedRunParsContainer->dump(); ATH_MSG_VERBOSE( "Retrieved RunParametersContainer" ); @@ -283,7 +268,7 @@ StatusCode L1TriggerTowerTool::retrieveConditions() ATH_MSG_VERBOSE( "Retrieved DisabledChannelContainer" ); if (verbose) { - if(m_isRun2) + if(is_run2) boost::any_cast<L1CaloPprDisabledChannelContainerRun2*>(m_disabledChannelContainer)->dump(); else boost::any_cast<L1CaloPprDisabledChannelContainer*>(m_disabledChannelContainer)->dump(); @@ -353,7 +338,7 @@ void L1TriggerTowerTool::process(const std::vector<int> &digits, const L1CaloCoo /// LUT ET calculation std::vector<int> lutOutput; - if(m_isRun2) { + if(isRun2()) { if(useJepLut) jepLut(lutInput, channelId, lutOutput); else cpLut(lutInput, channelId, lutOutput); } else { @@ -598,7 +583,7 @@ void L1TriggerTowerTool::fir(const std::vector<int> &digits, const L1CaloCoolCha std::vector<int> firCoeffs; if(!m_conditionsContainer.empty()) { const std::vector<short int>* hwCoeffs; - if(m_isRun2) + if(isRun2()) hwCoeffs = getFirCoefficients<L1CaloPprConditionsContainerRun2>(channelId.id(), m_conditionsContainer); else hwCoeffs = getFirCoefficients<L1CaloPprConditionsContainer>(channelId.id(), m_conditionsContainer); @@ -669,7 +654,7 @@ void L1TriggerTowerTool::peakBcid(const std::vector<int> &fir, const L1CaloCoolC { unsigned int strategy = 0; if(!m_conditionsContainer.empty()) { - if(m_isRun2) + if(isRun2()) strategy = getStrategy<L1CaloPprConditionsContainerRun2>(m_conditionsContainer); else strategy = getStrategy<L1CaloPprConditionsContainer>(m_conditionsContainer); @@ -724,7 +709,7 @@ void L1TriggerTowerTool::satBcid(const std::vector<int> &digits, const L1CaloCoo int satHigh = 0; if (!m_conditionsContainer.empty()) { bool available = false; - if(m_isRun2) + if(isRun2()) std::tie(available, satLevel, satLow, satHigh) = getSaturation<L1CaloPprConditionsContainerRun2>(channelId.id(), m_conditionsContainer); else std::tie(available, satLevel, satLow, satHigh) = getSaturation<L1CaloPprConditionsContainer>(channelId.id(), m_conditionsContainer); @@ -796,7 +781,7 @@ void L1TriggerTowerTool::bcidDecisionRange(const std::vector<int>& lutInput, con { int decisionSource = 0; if (!m_conditionsContainer.empty()) { - if(m_isRun2) decisionSource = getDecisionSource<L1CaloPprConditionsContainerRun2>(m_conditionsContainer); + if(isRun2()) decisionSource = getDecisionSource<L1CaloPprConditionsContainerRun2>(m_conditionsContainer); else decisionSource = getDecisionSource<L1CaloPprConditionsContainer>(m_conditionsContainer); } else ATH_MSG_WARNING( "::bcidDecisionRange: No Conditions Container retrieved" ); @@ -825,7 +810,7 @@ void L1TriggerTowerTool::bcidDecision(const std::vector<int> &bcidResults, const unsigned int decision2 = 0; unsigned int decision3 = 0; if(!m_conditionsContainer.empty()) { - if(m_isRun2) + if(isRun2()) std::tie(decision1, decision2, decision3) = getBcidDecision<L1CaloPprConditionsContainerRun2>(m_conditionsContainer); else std::tie(decision1, decision2, decision3) = getBcidDecision<L1CaloPprConditionsContainer>(m_conditionsContainer); @@ -871,7 +856,7 @@ void L1TriggerTowerTool::lut(const std::vector<int> &fir, const L1CaloCoolChanne int cut = 0; int ped = 0; - if(m_isRun2) { + if(isRun2()) { // assert instead ?! ATH_MSG_WARNING("::lut: Run-2 data - behaviour undefined!"); } @@ -913,7 +898,7 @@ void L1TriggerTowerTool::cpLut(const std::vector<int> &fir, const L1CaloCoolChan int hwCoeffSum = 0; const std::vector<short int>* hwCoeffs; - if(!m_isRun2) { + if(!isRun2()) { // assert instead ?! ATH_MSG_WARNING("::cpLut: Run-1 data - behaviour undefined!"); } @@ -983,7 +968,7 @@ void L1TriggerTowerTool::jepLut(const std::vector<int> &fir, const L1CaloCoolCha short par3 = 0; short par4 = 0; - if(!m_isRun2) { + if(!isRun2()) { // assert instead ?! ATH_MSG_WARNING("::jepLut: Run-1 data - behaviour undefined!"); } @@ -1150,7 +1135,7 @@ void L1TriggerTowerTool::etRange(const std::vector<int> &et, const L1CaloCoolCha int energyHigh = 0; if (!m_conditionsContainer.empty()) { bool available = false; - if(m_isRun2) + if(isRun2()) std::tie(available, energyLow, energyHigh) = getBcidEnergyRange<L1CaloPprConditionsContainerRun2>(channelId.id(), m_conditionsContainer); else std::tie(available, energyLow, energyHigh) = getBcidEnergyRange<L1CaloPprConditionsContainer>(channelId.id(), m_conditionsContainer); @@ -1197,7 +1182,7 @@ void L1TriggerTowerTool::dropBits(const std::vector<int> &fir, const L1CaloCoolC unsigned int start = 0; if(!m_conditionsContainer.empty()) { bool available = false; - if(m_isRun2) + if(isRun2()) std::tie(available, start) = getFirStartBit<L1CaloPprConditionsContainerRun2>(channelId.id(), m_conditionsContainer); else std::tie(available, start) = getFirStartBit<L1CaloPprConditionsContainer>(channelId.id(), m_conditionsContainer); @@ -1240,7 +1225,7 @@ void L1TriggerTowerTool::firParams(const L1CaloCoolChannelId& channelId, std::ve firCoeffs.clear(); if(!m_conditionsContainer.empty()) { const std::vector<short int>* hwCoeffs = nullptr; - if(m_isRun2) + if(isRun2()) hwCoeffs = getFirCoefficients<L1CaloPprConditionsContainerRun2>(channelId.id(), m_conditionsContainer); else hwCoeffs = getFirCoefficients<L1CaloPprConditionsContainer>(channelId.id(), m_conditionsContainer); @@ -1280,7 +1265,7 @@ void L1TriggerTowerTool::bcidParams(const L1CaloCoolChannelId& channelId, int &e std::tuple<unsigned int, unsigned int, unsigned int> bcidDecision; std::tuple<bool, int, int> bcidEnergyRange; std::tuple<bool, int, int, int> saturation; - if(m_isRun2) { + if(isRun2()) { using Cont = L1CaloPprConditionsContainerRun2; bcidDecision = getBcidDecision<Cont>(m_conditionsContainer); peakFinderStrategy = getStrategy<Cont>(m_conditionsContainer); @@ -1328,7 +1313,7 @@ void L1TriggerTowerTool::lutParams(const L1CaloCoolChannelId& channelId, int &st pedMean = 0.; disabled = true; - if(m_isRun2) { + if(isRun2()) { // assert instead ?! ATH_MSG_WARNING("::lutParams: Run-2 data - behaviour undefined!"); } @@ -1369,7 +1354,7 @@ void L1TriggerTowerTool::cpLutParams(const L1CaloCoolChannelId& channelId, int& int hwCoeffSum = 0; const std::vector<short int>* hwCoeffs; - if(!m_isRun2) { + if(!isRun2()) { // assert instead ?! ATH_MSG_WARNING("::cpLutParams: Run-1 data - behaviour undefined!"); } @@ -1426,7 +1411,7 @@ void L1TriggerTowerTool::jepLutParams(const L1CaloCoolChannelId& channelId, int& int hwCoeffSum = 0; const std::vector<short int>* hwCoeffs; - if(!m_isRun2) { + if(!isRun2()) { // assert instead ?! ATH_MSG_WARNING("::jepLutParams: Run-1 data - behaviour undefined!"); } @@ -1570,7 +1555,7 @@ bool L1TriggerTowerTool::satOverride(int range, const L1CaloCoolChannelId& /*cha bool override = false; if(!m_conditionsContainer.empty()) { std::tuple<bool, bool, bool> satOverride; - if(m_isRun2) + if(isRun2()) satOverride = getSatOverride<L1CaloPprConditionsContainerRun2>(m_conditionsContainer); else satOverride = getSatOverride<L1CaloPprConditionsContainer>(m_conditionsContainer); @@ -1601,7 +1586,7 @@ bool L1TriggerTowerTool::disabledChannel(const L1CaloCoolChannelId& channelId, u noiseCut = 0; if(!m_disabledChannelContainer.empty()) { const L1CaloPprDisabledChannel* disabledChan = nullptr; - if(m_isRun2) disabledChan = boost::any_cast<L1CaloPprDisabledChannelContainerRun2*>(m_disabledChannelContainer)->pprDisabledChannel(channelId.id()); + if(isRun2()) disabledChan = boost::any_cast<L1CaloPprDisabledChannelContainerRun2*>(m_disabledChannelContainer)->pprDisabledChannel(channelId.id()); else disabledChan = boost::any_cast<L1CaloPprDisabledChannelContainer*>(m_disabledChannelContainer)->pprDisabledChannel(channelId.id()); if (disabledChan) { @@ -1788,4 +1773,14 @@ void L1TriggerTowerTool::pedestalCorrection(std::vector<int>& firInOut, int firP } } +bool L1TriggerTowerTool::isRun2() const +{ + const EventContext& ctx = Gaudi::Hive::currentContext(); + if (ctx.eventID().run_number() >= 253377) return true; + + SG::ReadHandle<xAOD::EventInfo> eventInfo (m_eventInfoKey, ctx); + if (eventInfo->eventType (xAOD::EventInfo::IS_SIMULATION)) return true; + return false; +} + } // end of namespace