diff --git a/PhysicsAnalysis/AnalysisTrigger/AnalysisTriggerAlgs/src/RoIBResultToxAOD.cxx b/PhysicsAnalysis/AnalysisTrigger/AnalysisTriggerAlgs/src/RoIBResultToxAOD.cxx index a736c0153f3bfb90354c4585ba99ba72e9ab6c7e..879278050e7d5aaf2170b70f8d1e282fa7b74818 100644 --- a/PhysicsAnalysis/AnalysisTrigger/AnalysisTriggerAlgs/src/RoIBResultToxAOD.cxx +++ b/PhysicsAnalysis/AnalysisTrigger/AnalysisTriggerAlgs/src/RoIBResultToxAOD.cxx @@ -1,8 +1,6 @@ -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -// $Id: RoIBResultToxAOD.cxx 784984 2016-11-18 05:53:57Z ssnyder $ +// +// Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +// // STL include(s): #include <algorithm> @@ -12,131 +10,59 @@ #include "RoIBResultToxAOD.h" // Gaudi/Athena include(s): -#include "AthenaKernel/errorcheck.h" -#include "CLHEP/Units/SystemOfUnits.h" -#include "EventInfo/EventInfo.h" -#include "EventInfo/EventID.h" -#include "EventInfo/EventType.h" -#include "EventInfo/TriggerInfo.h" +#include "StoreGate/ReadHandle.h" +#include "StoreGate/WriteHandle.h" // LVL1 trigger include(s): -#include "TrigT1Interfaces/TriggerTypeWord.h" #include "TrigT1Interfaces/RecMuonRoI.h" -#include "TrigT1Interfaces/RecMuonRoiSvc.h" #include "TrigT1Interfaces/RecEmTauRoI.h" #include "TrigT1Interfaces/RecJetRoI.h" #include "TrigT1Interfaces/RecEnergyRoI.h" #include "TrigT1Interfaces/JEPRoIDecoder.h" -#include "TrigT1Result/RoIBResult.h" -#include "TrigT1Result/CTPResult.h" -#include "TrigT1CaloToolInterfaces/IL1CPMTools.h" -#include "TrigT1CaloToolInterfaces/IL1JEMJetTools.h" -#include "xAODTrigL1Calo/CPMTowerContainer.h" -#include "xAODTrigL1Calo/JetElementContainer.h" #include "TrigT1CaloEvent/JetInput.h" #include "TrigConfL1Data/L1DataDef.h" #include "TrigConfL1Data/TriggerThreshold.h" -#include "TrigT1Interfaces/TrigT1CaloDefs.h" // Trigger configuration interface includes: #include "TrigConfL1Data/CTPConfig.h" #include "TrigConfL1Data/Menu.h" #include "TrigConfL1Data/TriggerItem.h" -// Include for the configuration service: -#include "TrigConfInterfaces/ILVL1ConfigSvc.h" - -// LVL1 AOD event include(s): -#include "AnalysisTriggerEvent/CTP_Decision.h" -#include "AnalysisTriggerEvent/LVL1_ROI.h" - // xAOD include(s): -#include "xAODTrigger/MuonRoIContainer.h" #include "xAODTrigger/MuonRoIAuxContainer.h" -#include "xAODTrigger/EmTauRoI.h" -#include "xAODTrigger/EmTauRoIContainer.h" #include "xAODTrigger/EmTauRoIAuxContainer.h" -#include "xAODTrigger/EnergySumRoI.h" #include "xAODTrigger/EnergySumRoIAuxInfo.h" -#include "xAODTrigger/JetEtRoI.h" #include "xAODTrigger/JetEtRoIAuxInfo.h" -#include "xAODTrigger/JetRoI.h" -#include "xAODTrigger/JetRoIContainer.h" #include "xAODTrigger/JetRoIAuxContainer.h" +namespace { -// Local include(s): -//#include "RoIBResultToxAOD.h" - -using namespace TrigConf; -using namespace xAODMaker; -using namespace LVL1; - -RoIBResultToxAOD::RoIBResultToxAOD( const std::string& name, ISvcLocator* pSvcLocator ) - : AthAlgorithm( name, pSvcLocator ), - m_configSvc( "TrigConf::LVL1ConfigSvc/LVL1ConfigSvc", name ), - m_recRPCRoiSvc( LVL1::ID_RecRpcRoiSvc, name ), - m_recTGCRoiSvc( LVL1::ID_RecTgcRoiSvc, name ), - m_EmTauTool( "LVL1::L1CPMTools/L1CPMTools" ), - m_JetTool( "LVL1::L1JEMJetTools/L1JEMJetTools" ), - m_MuCnvTool( "xAODMaker::MuonRoICnvTool/MuonRoICnvTool", this ) - { - - // services - declareProperty( "LVL1ConfigSvc", m_configSvc, "LVL1 Config Service"); - declareProperty( "RecRpcRoiSvc", m_recRPCRoiSvc, "RPC Rec Roi Service"); - declareProperty( "RecTgcRoiSvc", m_recTGCRoiSvc, "TGC Rec Roi Service"); - - // tools - declareProperty( "L1CPMTools", m_EmTauTool, - "Tool for calculation of EmTau trigger sums per RoI"); - declareProperty( "L1JEMJetTools", m_JetTool, - "Tool for calculation of Jet cluster sums per RoI"); - - // Properties: input selection - declareProperty( "DoCalo", m_doCalo = true, "Use inputs from Calo system" ); - declareProperty( "DoMuon", m_doMuon = true, "Use inputs from Muon system" ); - - // Properties: rebuilding trigger type - declareProperty( "EGammaItem", m_egammaItem, - "List of LVL1 items for e/gamma trigger type" ); - declareProperty( "TauHadItem", m_tauhadItem, - "List of LVL1 items for tau trigger type" ); - declareProperty( "JetItem", m_jetItem, - "List of LVL1 items for jet trigger type" ); - declareProperty( "ESumItem", m_esumItem, - "List of LVL1 items for energy sum trigger type" ); - declareProperty( "HighMuItem", m_highmuItem, - "List of LVL1 items for high pt muon trigger type" ); - declareProperty( "LowMuItem", m_lowmuItem, - "List of LVL1 items for low pt muon trigger type" ); - - // Properties: StoreGate keys - m_CPMTowerLocation = LVL1::TrigT1CaloDefs::CPMTowerLocation; - m_JetElementLocation = LVL1::TrigT1CaloDefs::JetElementLocation; - declareProperty( "CPMTowerLocation", m_CPMTowerLocation ) ; - declareProperty( "JetElementLocation", m_JetElementLocation ) ; - declareProperty( "RoIBResultInputKey", m_roibInputKey = "RoIBResult" ); - declareProperty( "LVL1_ROIOutputKey", m_lvl1RoIOutputKey = "LVL1_ROI" ); - - declareProperty( "xAODKeyMu", m_xaodKeyMu = "LVL1MuonRoIs" ); - declareProperty( "xAODKeyEmTau", m_xaodKeyEmTau = "LVL1EmTauRoIs" ); - declareProperty( "xAODKeyEsum", m_xaodKeyEsum = "LVL1EnergySumRoI" ); - declareProperty( "xAODKeyJetEt", m_xaodKeyJetEt = "LVL1JetEtRoI" ); - declareProperty( "xAODKeyJet", m_xaodKeyJet = "LVL1JetRoIs" ); - - m_retrievedEmTauTool = false; - m_retrievedJetTool = false; + /// Giga-electronvolts + static const double GeV = 1000.0; + + /// Multiplier when we want to divide by GeV + static const double InvGeV = 1 / GeV; + +} // private namespace + +/// Helper macro for initialising SG keys that are allowed to be missing +#define INIT_SG_KEY(VAR) \ + do { \ + ATH_CHECK( VAR.initialize( VAR.key() != "" ) ); \ + } while( false ) + +RoIBResultToxAOD::RoIBResultToxAOD( const std::string& name, + ISvcLocator* svcLoc ) + : AthReentrantAlgorithm( name, svcLoc ) { } -// Initialize StatusCode RoIBResultToxAOD::initialize() { - ATH_MSG_INFO( "initializing " << name() - << " - package version " << PACKAGE_VERSION ); + // Greet the user. + ATH_MSG_INFO( "Initializing algorithm" ); - // Print system info + // Print system info. if( m_doCalo == false ) { ATH_MSG_WARNING( "Inputs from LVL1 Calo systems switched off" ); } @@ -144,304 +70,119 @@ StatusCode RoIBResultToxAOD::initialize() { ATH_MSG_WARNING( "Inputs from LVL1 Muon systems switched off" ); } - // Connect to the LVL1ConfigSvc for the trigger configuration: - CHECK( m_configSvc.retrieve() ); + // Connect to the LVL1ConfigSvc for the trigger configuration. + ATH_CHECK( m_configSvc.retrieve() ); ATH_MSG_DEBUG( "Connected to " << m_configSvc.typeAndName() ); if( m_doMuon ) { - // Get the RPC RecRoI service - CHECK( m_recRPCRoiSvc.retrieve() ); + ATH_CHECK( m_recRPCRoiSvc.retrieve() ); ATH_MSG_DEBUG( "Connected to " << m_recRPCRoiSvc.typeAndName() ); // Get the TGC RecRoI service - CHECK( m_recTGCRoiSvc.retrieve() ); + ATH_CHECK( m_recTGCRoiSvc.retrieve() ); ATH_MSG_DEBUG( "Connected to " << m_recTGCRoiSvc.typeAndName() ); - - } // if (m_doMuon) + } if( m_doCalo ) { - // Get tools - CHECK( m_EmTauTool.retrieve() ); - ATH_MSG_DEBUG( "Got " << m_EmTauTool.typeAndName() ); - m_retrievedEmTauTool = true; + ATH_CHECK( m_emTauTool.retrieve() ); + ATH_MSG_DEBUG( "Got " << m_emTauTool.typeAndName() ); - CHECK( m_JetTool.retrieve() ); - ATH_MSG_DEBUG( "Got " << m_JetTool.typeAndName() ); - m_retrievedJetTool = true; - - } // if (m_doCalo) - - return StatusCode::SUCCESS; -} - -// finalize -StatusCode RoIBResultToxAOD::finalize() { - - ATH_MSG_INFO( "Finalizing " << name() - << " - package version " << PACKAGE_VERSION ); - - return StatusCode::SUCCESS; -} - -// execute -StatusCode RoIBResultToxAOD::execute() { - - ATH_MSG_DEBUG( "in execute()" ); - - /////////////////////////////////////////////////////////////////////////// - // Trigger Info - - // retrieve event info - const DataHandle< EventInfo > eventInfoBeg; - const DataHandle< EventInfo > eventInfoEnd; - CHECK( evtStore()->retrieve( eventInfoBeg, eventInfoEnd ) ); - if( eventInfoBeg == eventInfoEnd ) { - ATH_MSG_ERROR( "No event info objects" ); - return StatusCode::RECOVERABLE; - } - - // get key - const std::string eventInfoKey = eventInfoBeg.key(); - - // build TriggerInfo - EventInfo* eventInfo = const_cast< EventInfo* >( eventInfoBeg.cptr() ); - TriggerInfo* tInfo = eventInfo->trigger_info(); - TriggerInfo* triggerInfo; - if( tInfo != 0 ) { - triggerInfo = new TriggerInfo( *tInfo ); - } else { - triggerInfo = new TriggerInfo( 0, 0, 0, - std::vector< TriggerInfo::number_type>( 0 ), - std::vector< TriggerInfo::number_type>( 0 ), - std::vector< TriggerInfo::StreamTag>( 0 ) ); - } - - // set TriggerInfo - eventInfo->setTriggerInfo( triggerInfo ); - - // dump - ATH_MSG_DEBUG( MSG::dec << "EventInfo:" << eventInfoKey ); - ATH_MSG_DEBUG( *( eventInfo->event_ID() ) ); - ATH_MSG_DEBUG( "[TimeStamp] = " << eventInfo->event_ID()->time_stamp() ); - ATH_MSG_DEBUG( "[Type] = " << eventInfo->event_type()->user_type() ); - ATH_MSG_DEBUG( "[BitMask]" ); - for( EventType::BitMaskIterator bitIt = eventInfo->event_type()->bit_mask_begin(); - bitIt != eventInfo->event_type()->bit_mask_end(); ++bitIt ) { - ATH_MSG_DEBUG( *bitIt ); + ATH_CHECK( m_jetTool.retrieve() ); + ATH_MSG_DEBUG( "Got " << m_jetTool.typeAndName() ); } - if( triggerInfo != 0 ) { - ATH_MSG_DEBUG( MSG::hex << "[L1ID] = "<< triggerInfo->extendedLevel1ID() ); - ATH_MSG_DEBUG( "[TriggerType] = "<< triggerInfo->level1TriggerType() ); - ATH_MSG_DEBUG( "[L1Info] = "<< triggerInfo->level1TriggerInfo() ); - ATH_MSG_DEBUG( "[L2Info] = "<< triggerInfo->level2TriggerInfo() ); - ATH_MSG_DEBUG( "[EFInfo]" ); - const std::vector< TriggerInfo::number_type >& efInfo = triggerInfo->eventFilterInfo(); - for( std::vector< TriggerInfo::number_type >::const_iterator itEF = efInfo.begin(); - itEF != efInfo.end(); ++itEF ) { - ATH_MSG_DEBUG( *itEF ); - } + // Initialise the keys. + ATH_CHECK( m_roibResultKey.initialize() ); + INIT_SG_KEY( m_cpmTowerKey ); + INIT_SG_KEY( m_jetElementKey ); + if( m_doMuon ) { + ATH_CHECK( m_muonRoIKey.initialize() ); } - - /////////////////////////////////////////////////////////////////////////// - // build LVL1 ROI - - LVL1_ROI *lvl1ROI = new LVL1_ROI; - - /////////////////////////////////////////////////////////////////////////// - // retrive L1 result - - const ROIB::RoIBResult *result = 0; - if( evtStore()->retrieve( result, m_roibInputKey ).isFailure() ) { - ATH_MSG_WARNING( "Could not retrieve RoIBResult. Building empty LVL1_ROI" ); - result = 0; + if( m_doCalo ) { + ATH_CHECK( m_emtauRoIKey.initialize() ); + ATH_CHECK( m_energysumRoIKey.initialize() ); + ATH_CHECK( m_jetetRoIKey.initialize() ); + ATH_CHECK( m_jetRoIKey.initialize() ); } - /////////////////////////////////////////////////////////////////////////// - // Muon ROI - - if( m_doMuon == true ) addMuonRoI( result, lvl1ROI ); - - /////////////////////////////////////////////////////////////////////////// - // EmTau ROI - - if( m_doCalo == true ) CHECK( addEmTauRoI( result ) ); - - /////////////////////////////////////////////////////////////////////////// - // JetEnergy ROI - - if( m_doCalo == true ) CHECK( addJetEnergyRoI( result ) ); - - /////////////////////////////////////////////////////////////////////////// - // record LVL1 ROI in xAOD format - - CHECK( convertToxAOD(lvl1ROI) ); - - /////////////////////////////////////////////////////////////////////////// - // delete LVL1 ROI - delete lvl1ROI; - + // Return gracefully. return StatusCode::SUCCESS; } -StatusCode RoIBResultToxAOD::buildCTP_Decision() { - - ATH_MSG_DEBUG( "building CTP decision" ); +StatusCode RoIBResultToxAOD::execute_r( const EventContext& ctx ) const { - CTP_Decision* ctpDecision = new CTP_Decision; - - // retrive L1 result - const ROIB::RoIBResult *result = 0; - if( evtStore()->retrieve( result, m_roibInputKey ).isSuccess() ) { - - // Trigger Type Word - bool triggerTypeLegacyFlag = false; - uint32_t triggerTypeWord = result->cTPResult().header().triggerType(); - - if( triggerTypeWord == 0 ) { // switch to legacy mode - ATH_MSG_DEBUG( "Building TriggerType word" ); - triggerTypeWord = LVL1::TriggerTypeWord::Physics | - LVL1::TriggerTypeWord::PriorityLevel; - triggerTypeLegacyFlag = true; - } + // Tell the user what's happening. + ATH_MSG_DEBUG( "in execute()" ); - // store TAV vector in CTP decision object - const std::vector< ROIB::CTPRoI > tav = result->cTPResult().TAV(); - for( size_t i( 0 ); i < tav.size(); ++i ) { - ctpDecision->setWord( i, tav[ i ].roIWord() ); - } + // Access the input object. + auto roibResult = SG::makeHandle( m_roibResultKey, ctx ); - // search for passed items in TAV vector from CTP result - const std::bitset< 512 > items = ROIB::convertToBitset( tav ); - - ATH_MSG_DEBUG( "Iterating Items on " << m_configSvc->ctpConfig() ); - for(TrigConf::ItemContainer::const_iterator item = m_configSvc->ctpConfig()->menu().items().begin(); - item != m_configSvc->ctpConfig()->menu().items().end(); ++item ) { - ATH_MSG_DEBUG( "try getting item name" ); - if( items[ ( *item )->ctpId() ] ) { - // add item name to CTP_Decision - const std::string& itemName = ( *item )->name(); - ctpDecision->setItem( itemName ); - ATH_MSG_VERBOSE( "Item : " << itemName ); - - if( triggerTypeLegacyFlag ) { - ///////// compute Trigger Type Word - ///////// This is temporary implementation for DC2 and will be moved to - ///////// CTP simulation - // e/gamma - if( m_egammaItem.end() != std::find( m_egammaItem.begin(), m_egammaItem.end(), - itemName ) ) - triggerTypeWord |= LVL1::TriggerTypeWord::Egamma; - - // tau/hadron - if( m_tauhadItem.end() != std::find( m_tauhadItem.begin(), m_tauhadItem.end(), - itemName ) ) - triggerTypeWord |= LVL1::TriggerTypeWord::TauHdr; - - // jet - if( m_jetItem.end() != std::find( m_jetItem.begin(), m_jetItem.end(), - itemName ) ) - triggerTypeWord |= LVL1::TriggerTypeWord::Jet; - - // energy sum - if( m_esumItem.end() != std::find( m_esumItem.begin(), m_esumItem.end(), - itemName ) ) - triggerTypeWord |= LVL1::TriggerTypeWord::EnergySum; - - // high pT muon - if( m_highmuItem.end() != std::find( m_highmuItem.begin(), m_highmuItem.end(), - itemName ) ) - triggerTypeWord |= LVL1::TriggerTypeWord::HighPtMuon; - - // low pT muon - if( m_lowmuItem.end() != std::find( m_lowmuItem.begin(), m_lowmuItem.end(), - itemName ) ) - triggerTypeWord |= LVL1::TriggerTypeWord::LowPtMuon; - } // if (triggerTypeLegacyFlag) - } // if (items[(*item)->ctpId()]) - } // for - - // set Trigger Type Word - ctpDecision->setTriggerTypeWord( triggerTypeWord ); - ATH_MSG_DEBUG( "CTP_Decision: \n" + ctpDecision->dump() ); - - } else { - ATH_MSG_WARNING( "Could not retrieve RoIBResult, building empty CTP_Decision" ); + // Create the muon RoIs: + if( m_doMuon ) { + ATH_CHECK( createMuonRoI( *roibResult, ctx ) ); } - // record CTP Decision - CHECK( evtStore()->record( ctpDecision, "CTP_Decision" ) ); - CHECK( evtStore()->setConst( ctpDecision ) ); + // Create the calo RoIs: + if( m_doCalo ) { + ATH_CHECK( createEmTauRoI( *roibResult, ctx ) ); + ATH_CHECK( createJetEnergyRoI( *roibResult, ctx ) ); + } + // Return gracefully. return StatusCode::SUCCESS; } -StatusCode RoIBResultToxAOD::addEmTauRoI( const ROIB::RoIBResult* result ) { +StatusCode RoIBResultToxAOD::createEmTauRoI( const ROIB::RoIBResult& result, + const EventContext& ctx ) const { + // Tell the user what's happening. ATH_MSG_DEBUG( "building EmTauRoI" ); - // empty input - if( result == 0 ) return StatusCode::SUCCESS; - - /// Containers for xAOD - xAOD::EmTauRoIAuxContainer* emtau_aux = new xAOD::EmTauRoIAuxContainer(); - xAOD::EmTauRoIContainer* emtau_xaod = new xAOD::EmTauRoIContainer(); - emtau_xaod->setStore( emtau_aux ); + /// Create the xAOD container. + auto emtau_xaod = std::make_unique< xAOD::EmTauRoIContainer >(); + auto emtau_aux = std::make_unique< xAOD::EmTauRoIAuxContainer >(); + emtau_xaod->setStore( emtau_aux.get() ); /// Digit scale for calorimeter trigger - float caloTrigScale = CLHEP::GeV/m_configSvc->thresholdConfig()->caloInfo().globalEmScale(); + const float caloTrigScale = + InvGeV * m_configSvc->thresholdConfig()->caloInfo().globalEmScale(); ATH_MSG_DEBUG( "caloTrigScale = " << caloTrigScale ); /** Get EmTau Thresholds from configSvc. Also fill a map of threshold names while we are here - will be useful later */ - std::vector< TrigConf::TriggerThreshold* > thresholds = + const std::vector< TrigConf::TriggerThreshold* >& thresholds = m_configSvc->ctpConfig()->menu().thresholdVector(); std::vector< TrigConf::TriggerThreshold* > caloThresholds; std::map< int, std::string > emThresholdNames; std::map< int, std::string > tauThresholdNames; - for( std::vector< TrigConf::TriggerThreshold* >::const_iterator it = thresholds.begin(); - it != thresholds.end(); ++it ) { - if ( ( *it )->type() == L1DataDef::emType() ) { - caloThresholds.push_back( *it ); - emThresholdNames.insert( std::map< int, std::string >::value_type( ( *it )->thresholdNumber(), ( *it )->name() ) ); + for( TrigConf::TriggerThreshold* tt : thresholds ) { + if( tt->type() == TrigConf::L1DataDef::emType() ) { + caloThresholds.push_back( tt ); + emThresholdNames[ tt->thresholdNumber() ] = tt->name(); } - else if ( ( *it )->type() == L1DataDef::tauType() ) { - caloThresholds.push_back( *it ); - tauThresholdNames.insert( std::map< int, std::string >::value_type( ( *it )->thresholdNumber(), ( *it )->name() ) ); + else if( tt->type() == TrigConf::L1DataDef::tauType() ) { + caloThresholds.push_back( tt ); + tauThresholdNames[ tt->thresholdNumber() ] = tt->name(); } } // Tool to reconstruct EM/tau cluster & isolation sums // - need to form tower map for RoI reconstruction - const DataVector< xAOD::CPMTower >* storedTTs; xAOD::CPMTowerMap_t cpmtowers; - if( m_retrievedEmTauTool ) { - if( evtStore()->contains< xAOD::CPMTowerContainer >( m_CPMTowerLocation ) ) { - StatusCode sc = evtStore()->retrieve( storedTTs, m_CPMTowerLocation ); - if( sc.isSuccess() ) m_EmTauTool->mapTowers( storedTTs, &cpmtowers ); - else ATH_MSG_WARNING( "Error retrieving CPMTowers" ); - } - else ATH_MSG_DEBUG( "No CPMTowerCollection found at " - << m_CPMTowerLocation ); + if( m_emTauTool.isEnabled() && ( m_cpmTowerKey.key() != "" ) ) { + auto cpmTower = SG::makeHandle( m_cpmTowerKey, ctx ); + m_emTauTool->mapTowers( cpmTower.cptr(), &cpmtowers ); } - // get EmTau Result - const std::vector< ROIB::EMTauResult >& emtauResult = result->eMTauResult(); - // reconstruct ROI ATH_MSG_DEBUG( "EmTau ROI" ); - std::vector< ROIB::EMTauResult >::const_iterator itEMR = emtauResult.begin(); - std::vector< ROIB::EMTauResult >::const_iterator itEMRe = emtauResult.end(); - for( ; itEMR != itEMRe; ++itEMR ) { - const std::vector< ROIB::EMTauRoI >& emtauRoIV = itEMR->roIVec(); - std::vector< ROIB::EMTauRoI >::const_iterator itEM = emtauRoIV.begin(); - std::vector< ROIB::EMTauRoI >::const_iterator itEMe = emtauRoIV.end(); - for( ; itEM != itEMe; ++itEM ) { - - uint32_t roIWord = itEM->roIWord(); + for( const ROIB::EMTauResult& emtResult : result.eMTauResult() ) { + for( const ROIB::EMTauRoI& emtRoI : emtResult.roIVec() ) { + + uint32_t roIWord = emtRoI.roIWord(); ATH_MSG_DEBUG( "About to create RecEmTauRoI : " << MSG::hex << std::setw( 8 ) << roIWord << MSG::dec ); @@ -457,74 +198,76 @@ StatusCode RoIBResultToxAOD::addEmTauRoI( const ROIB::RoIBResult* result ) { emtau_xaod->push_back( roi ); roi->initialize( roIWord, recRoI.eta(), roiPhi ); roi->setEtScale( caloTrigScale ); - //roi->setET( recRoI.et() ); - //roi->setIsol( recRoI.isolation() ); roi->setThrPattern( recRoI.thresholdPattern() ); // fired thresholds - std::vector< unsigned int >* thrV = recRoI.thresholdsPassed(); - std::vector< unsigned int >::const_iterator itTh = thrV->begin(); - std::vector< unsigned int >::const_iterator itThE = thrV->end(); - for( ; itTh != itThE; ++itTh ) { - float thrValue = recRoI.triggerThreshold(*itTh)* CLHEP::GeV; + std::unique_ptr< std::vector< unsigned int > > thrV( + recRoI.thresholdsPassed() ); + for( unsigned int thr : *thrV ) { + const float thrValue = recRoI.triggerThreshold( thr ) * GeV; + auto thrType = recRoI.thresholdType( thr ); + auto emNameItr = emThresholdNames.find( thr ); + auto tauNameItr = tauThresholdNames.find( thr ); std::string thrName = "NameNotFound"; - if ( recRoI.thresholdType(*itTh) == TrigT1CaloDefs::EMAlg && emThresholdNames.find( *itTh ) != emThresholdNames.end() ) { - thrName = emThresholdNames[ *itTh ]; + if( ( thrType == LVL1::TrigT1CaloDefs::EMAlg ) && + ( emNameItr != emThresholdNames.end() ) ) { + thrName = emNameItr->second; } - else if ( recRoI.thresholdType(*itTh) == TrigT1CaloDefs::TauAlg && tauThresholdNames.find( *itTh ) != tauThresholdNames.end() ) { - thrName = tauThresholdNames[ *itTh ]; + else if( ( thrType == LVL1::TrigT1CaloDefs::TauAlg ) && + ( tauNameItr != tauThresholdNames.end() ) ) { + thrName = tauNameItr->second; } roi->addThreshold( thrName, thrValue ); - ATH_MSG_DEBUG( "EmTau Thr : " << *itTh << ", name = " << thrName + ATH_MSG_DEBUG( "EmTau Thr : " << thr << ", name = " << thrName << ", value = " << thrValue ); } - delete thrV; // Cluster ET values, reconstructed from TriggerTowers - if( m_retrievedEmTauTool ) { - m_EmTauTool->formSums( roIWord, &cpmtowers ); - roi->setCore( m_EmTauTool->Core() * caloTrigScale ); - roi->setEmClus( m_EmTauTool->EMClus() * caloTrigScale ); - roi->setTauClus( m_EmTauTool->TauClus() * caloTrigScale ); - roi->setEmIsol( m_EmTauTool->EMIsol() * caloTrigScale ); - roi->setHadIsol( m_EmTauTool->HadIsol() * caloTrigScale ); - roi->setHadCore( m_EmTauTool->HadCore() * caloTrigScale ); + if( m_emTauTool.isEnabled() ) { + m_emTauTool->formSums( roIWord, &cpmtowers ); + roi->setCore( m_emTauTool->Core() * caloTrigScale ); + roi->setEmClus( m_emTauTool->EMClus() * caloTrigScale ); + roi->setTauClus( m_emTauTool->TauClus() * caloTrigScale ); + roi->setEmIsol( m_emTauTool->EMIsol() * caloTrigScale ); + roi->setHadIsol( m_emTauTool->HadIsol() * caloTrigScale ); + roi->setHadCore( m_emTauTool->HadCore() * caloTrigScale ); } - } } - /// Record the results - CHECK( evtStore()->record( emtau_aux, m_xaodKeyEmTau + "Aux." ) ); - CHECK( evtStore()->record( emtau_xaod, m_xaodKeyEmTau ) ); + // Record the results. + auto emtauRoI = SG::makeHandle( m_emtauRoIKey, ctx ); + ATH_CHECK( emtauRoI.record( std::move( emtau_xaod ), + std::move( emtau_aux ) ) ); + // Return gracefully. return StatusCode::SUCCESS; } -StatusCode RoIBResultToxAOD::addJetEnergyRoI( const ROIB::RoIBResult* result ) { +StatusCode +RoIBResultToxAOD::createJetEnergyRoI( const ROIB::RoIBResult& result, + const EventContext& ctx ) const { ATH_MSG_DEBUG( "building JetEnergyRoI" ); - - // empty input - if( result == 0 ) return StatusCode::SUCCESS; // Containers for xAOD - xAOD::JetRoIAuxContainer* jet_aux = new xAOD::JetRoIAuxContainer(); - xAOD::JetRoIContainer* jet_xaod = new xAOD::JetRoIContainer(); - jet_xaod->setStore( jet_aux ); - - xAOD::EnergySumRoIAuxInfo* esum_aux = new xAOD::EnergySumRoIAuxInfo(); - xAOD::EnergySumRoI* esum_xaod = new xAOD::EnergySumRoI(); - esum_xaod->setStore( esum_aux ); - - xAOD::JetEtRoIAuxInfo* jetet_aux = new xAOD::JetEtRoIAuxInfo(); - xAOD::JetEtRoI* jetet_xaod = new xAOD::JetEtRoI(); - jetet_xaod->setStore( jetet_aux ); + auto jet_xaod = std::make_unique< xAOD::JetRoIContainer >(); + auto jet_aux = std::make_unique< xAOD::JetRoIAuxContainer >(); + jet_xaod->setStore( jet_aux.get() ); + + auto esum_xaod = std::make_unique< xAOD::EnergySumRoI >(); + auto esum_aux = std::make_unique< xAOD::EnergySumRoIAuxInfo >(); + esum_xaod->setStore( esum_aux.get() ); + + auto jetet_xaod = std::make_unique< xAOD::JetEtRoI >(); + auto jetet_aux = std::make_unique< xAOD::JetEtRoIAuxInfo >(); + jetet_xaod->setStore( jetet_aux.get() ); // Digit scale for calorimeter trigger - float caloTrigScale = CLHEP::GeV/m_configSvc->thresholdConfig()->caloInfo().globalJetScale(); + const float caloTrigScale = + InvGeV * m_configSvc->thresholdConfig()->caloInfo().globalJetScale(); ATH_MSG_DEBUG( "caloTrigScale = " << caloTrigScale ); /** Get Jet/Energy Thresholds from configSvc. Also fill maps of threshold names while @@ -533,7 +276,7 @@ StatusCode RoIBResultToxAOD::addJetEnergyRoI( const ROIB::RoIBResult* result ) { Unfortunately there are 3 types of jet threshold and 3 types of ET trigger threshold, so this bit doesn't look very elegant */ - std::vector< TrigConf::TriggerThreshold* > thresholds = + const std::vector< TrigConf::TriggerThreshold* >& thresholds = m_configSvc->ctpConfig()->menu().thresholdVector(); std::vector<TrigConf::TriggerThreshold*> jetThresholds; std::vector<TrigConf::TriggerThreshold*> energyThresholds; @@ -546,71 +289,63 @@ StatusCode RoIBResultToxAOD::addJetEnergyRoI( const ROIB::RoIBResult* result ) { std::map<int, std::string> xsNames; std::map<int, std::string> jeNames; - for( std::vector<TrigConf::TriggerThreshold*>::const_iterator it = thresholds.begin(); - it != thresholds.end(); ++it ) { - if( ( *it )->type() == L1DataDef::jetType() ) { - jetThresholds.push_back( *it ); - jetNames.insert(std::map<int, std::string>::value_type((*it)->thresholdNumber(),(*it)->name())); + for( TrigConf::TriggerThreshold* tt : thresholds ) { + if( tt->type() == TrigConf::L1DataDef::jetType() ) { + jetThresholds.push_back( tt ); + jetNames[ tt->thresholdNumber() ] = tt->name(); } - else if( ( *it )->type() == L1DataDef::jfType() ) { - jetThresholds.push_back( *it ); - jfNames.insert(std::map<int, std::string>::value_type((*it)->thresholdNumber(),(*it)->name())); + else if( tt->type() == TrigConf::L1DataDef::jfType() ) { + jetThresholds.push_back( tt ); + jfNames[ tt->thresholdNumber() ] = tt->name(); } - else if( ( *it )->type() == L1DataDef::jbType() ) { - jetThresholds.push_back( *it ); - jbNames.insert(std::map<int, std::string>::value_type((*it)->thresholdNumber(),(*it)->name())); + else if( tt->type() == TrigConf::L1DataDef::jbType() ) { + jetThresholds.push_back( tt ); + jbNames[ tt->thresholdNumber() ] = tt->name(); } - else if( ( *it )->type() == L1DataDef::xeType() ) { - energyThresholds.push_back( *it ); - xeNames.insert(std::map<int, std::string>::value_type((*it)->thresholdNumber(),(*it)->name())); + else if( tt->type() == TrigConf::L1DataDef::xeType() ) { + energyThresholds.push_back( tt ); + xeNames[ tt->thresholdNumber() ] = tt->name(); } - else if( ( *it )->type() == L1DataDef::teType() ) { - energyThresholds.push_back( *it ); - teNames.insert(std::map<int, std::string>::value_type((*it)->thresholdNumber(),(*it)->name())); + else if( tt->type() == TrigConf::L1DataDef::teType() ) { + energyThresholds.push_back( tt ); + teNames[ tt->thresholdNumber() ] = tt->name(); } - else if( ( *it )->type() == L1DataDef::xsType() ) { - energyThresholds.push_back( *it ); - xsNames.insert(std::map<int, std::string>::value_type((*it)->thresholdNumber(),(*it)->name())); + else if( tt->type() == TrigConf::L1DataDef::xsType() ) { + energyThresholds.push_back( tt ); + xsNames[ tt->thresholdNumber() ] = tt->name(); } - else if( ( *it )->type() == L1DataDef::jeType() ) { - jetEnergyThresholds.push_back( *it ); - jeNames.insert(std::map<int, std::string>::value_type((*it)->thresholdNumber(),(*it)->name())); + else if( tt->type() == TrigConf::L1DataDef::jeType() ) { + jetEnergyThresholds.push_back( tt ); + jeNames[ tt->thresholdNumber() ] = tt->name(); } } // Tool to reconstruct Jet cluster ET sums // - form input map ready for analysis - const DataVector< xAOD::JetElement >* storedJEs; std::map< int, LVL1::JetInput* > jetInputs; - if( m_retrievedJetTool ) { - if( evtStore()->contains< xAOD::JetElementContainer >( m_JetElementLocation ) ) { - StatusCode sc = evtStore()->retrieve( storedJEs, m_JetElementLocation ); - if( sc.isSuccess() ) m_JetTool->mapJetInputs( storedJEs, &jetInputs ); - else ATH_MSG_WARNING( "Error retrieving JetElements" ); - } - else ATH_MSG_DEBUG( "No JetElementContainer found at " - << m_JetElementLocation ); + if( m_jetTool.isEnabled() && ( m_jetElementKey.key() != "" ) ) { + auto jetElement = SG::makeHandle( m_jetElementKey, ctx ); + m_jetTool->mapJetInputs( jetElement.cptr(), &jetInputs ); + } + std::vector< std::unique_ptr< LVL1::JetInput > > jetInputsHolder; + for( auto pair : jetInputs ) { + jetInputsHolder.emplace_back( pair.second ); } - - // get JetEnergy Result - const std::vector< ROIB::JetEnergyResult >& jetenergyResult = result->jetEnergyResult(); // reconstruct ROI - std::vector< ROIB::JetEnergyResult >::const_iterator itJETR = jetenergyResult.begin(); - std::vector< ROIB::JetEnergyResult >::const_iterator itJETRe = jetenergyResult.end(); - for( ; itJETR != itJETRe; ++itJETR ) { - const std::vector< ROIB::JetEnergyRoI >& jetenergyRoIV = itJETR->roIVec(); - std::vector< ROIB::JetEnergyRoI >::const_iterator itJET = jetenergyRoIV.begin(); - std::vector< ROIB::JetEnergyRoI >::const_iterator itJETe = jetenergyRoIV.end(); - for( ; itJET != itJETe; ++itJET ) { - uint32_t roIWord = itJET->roIWord(); + for( const ROIB::JetEnergyResult& jeteResult : result.jetEnergyResult() ) { + auto itJET = jeteResult.roIVec().begin(); + auto endJET = jeteResult.roIVec().end(); + for( ; itJET != endJET; ++itJET ) { + + const uint32_t roIWord = itJET->roIWord(); ATH_MSG_DEBUG( "Jet RoI, RoIWord = " << MSG::hex << std::setw( 8 ) << roIWord << MSG::dec ); // RoI type LVL1::JEPRoIDecoder conv; - int roiType = conv.roiType( roIWord ); + const int roiType = conv.roiType( roIWord ); // Jet ROI if( roiType == LVL1::TrigT1CaloDefs::JetRoIWordType ) { @@ -626,25 +361,32 @@ StatusCode RoIBResultToxAOD::addJetEnergyRoI( const ROIB::RoIBResult* result ) { jet_xaod->push_back( roi ); roi->initialize( roIWord, recRoI.eta(), roiPhi ); roi->setEtScale( caloTrigScale ); - //roi->setEtLarge( recRoI.etLarge() ); - //roi->setEtSmall( recRoI.etSmall() ); roi->setThrPattern( recRoI.thresholdPattern() ); // fired Jet thresholds - std::vector< unsigned int >* thrV = recRoI.thresholdsPassed(); - std::vector< unsigned int >::const_iterator itTh = thrV->begin(); - std::vector< unsigned int >::const_iterator itThE = thrV->end(); - for( ; itTh != itThE; ++itTh ) { - double thrValue = recRoI.triggerThreshold(*itTh)* CLHEP::GeV; + std::unique_ptr< std::vector< unsigned int > > thrV( + recRoI.thresholdsPassed() ); + for( unsigned int thr : *thrV ) { + + const double thrValue = recRoI.triggerThreshold( thr ) * GeV; + auto jetNameItr = jetNames.find( thr ); + auto jfNameItr = jfNames.find( thr ); + auto jbNameItr = jbNames.find( thr ); std::string thrName = "NameNotFound"; - if (!recRoI.isForwardJet()) { - if (jetNames.find(*itTh) != jetNames.end()) thrName = jetNames[*itTh]; + if( ! recRoI.isForwardJet() ) { + if( jetNameItr != jetNames.end() ) { + thrName = jetNameItr->second; + } } - else if (recRoI.eta() > 0) { - if (jfNames.find(*itTh) != jfNames.end()) thrName = jfNames[*itTh]; + else if( recRoI.eta() > 0 ) { + if( jfNameItr != jfNames.end() ) { + thrName = jfNameItr->second; + } } else { - if (jbNames.find(*itTh) != jbNames.end()) thrName = jbNames[*itTh]; + if( jbNameItr != jbNames.end() ) { + thrName = jbNameItr->second; + } } roi->addThreshold( thrName, thrValue ); @@ -652,25 +394,25 @@ StatusCode RoIBResultToxAOD::addJetEnergyRoI( const ROIB::RoIBResult* result ) { ATH_MSG_DEBUG( "Jet Thr : " << thrName << ", value = " << thrValue ); } - delete thrV; // Jet Cluster ET sums - if (m_retrievedJetTool) { - m_JetTool->formSums(roIWord, &jetInputs); - roi->setEt4x4(m_JetTool->ET4x4() * caloTrigScale); - roi->setEt6x6(m_JetTool->ET6x6() * caloTrigScale); - roi->setEt8x8(m_JetTool->ET8x8() * caloTrigScale); + if( m_jetTool.isEnabled() ) { + m_jetTool->formSums( roIWord, &jetInputs ); + roi->setEt4x4( m_jetTool->ET4x4() * caloTrigScale ); + roi->setEt6x6( m_jetTool->ET6x6() * caloTrigScale ); + roi->setEt8x8( m_jetTool->ET8x8() * caloTrigScale ); } } // Jet ET ROI else if( roiType == LVL1::TrigT1CaloDefs::JetEtRoIWordType ) { + // xAOD component - jetet_xaod->setRoIWord( roIWord ); // fired Jet ET thresholds - for( unsigned int i = 0; i < TrigT1CaloDefs::numOfJetEtSumThresholds; ++i ) { + for( unsigned int i = 0; + i < LVL1::TrigT1CaloDefs::numOfJetEtSumThresholds; ++i ) { if( ( roIWord >> i ) & 0x1 ) { std::string thrName = "NameNotFound"; if (jeNames.find(i) != jeNames.end()) thrName = jeNames[i]; @@ -684,20 +426,21 @@ StatusCode RoIBResultToxAOD::addJetEnergyRoI( const ROIB::RoIBResult* result ) { else if ( roiType == LVL1::TrigT1CaloDefs::EnergyRoIWordType0 ) { // Extract information and fill EnergySumRoI - uint32_t roiWord0 = roIWord; + const uint32_t roiWord0 = roIWord; ATH_MSG_DEBUG( "ET RoIWord 0 : " << MSG::hex << std::setw( 8 ) << roiWord0 << MSG::dec ); ++itJET; - uint32_t roiWord1 = itJET->roIWord(); + const uint32_t roiWord1 = itJET->roIWord(); ATH_MSG_DEBUG( "ET RoIWord 1 : " << MSG::hex << std::setw( 8 ) << roiWord1 << MSG::dec ); ++itJET; - uint32_t roiWord2 = itJET->roIWord(); + const uint32_t roiWord2 = itJET->roIWord(); ATH_MSG_DEBUG( "ET RoIWord 2 : " << MSG::hex << std::setw( 8 ) << roiWord2 << MSG::dec ); // RecRoI - LVL1::RecEnergyRoI recRoI( roiWord0, roiWord1, roiWord2, &energyThresholds ); + LVL1::RecEnergyRoI recRoI( roiWord0, roiWord1, roiWord2, + &energyThresholds ); // Overflow bits unsigned int overflows = 0; @@ -710,143 +453,121 @@ StatusCode RoIBResultToxAOD::addJetEnergyRoI( const ROIB::RoIBResult* result ) { recRoI.energyX() * caloTrigScale, recRoI.energyY() * caloTrigScale, recRoI.energyT() * caloTrigScale ); - // fired summed ET thresholds - std::vector< unsigned int >* thrEtMiss = recRoI.etMissThresholdsPassed(); - std::vector< unsigned int >::const_iterator itThEtMiss = thrEtMiss->begin(); - for( ; itThEtMiss != thrEtMiss->end(); ++itThEtMiss ) { - std::string thrName = "NameNotFound"; - if( xeNames.find( *itThEtMiss - 1 ) != xeNames.end() ) { - thrName = xeNames[ *itThEtMiss - 1 ]; - } + std::unique_ptr< std::vector< unsigned int > > thrEtMiss( + recRoI.etMissThresholdsPassed() ); + for( unsigned int thr : *thrEtMiss ) { + auto xeNameItr = xeNames.find( thr - 1 ); + const std::string thrName = ( xeNameItr != xeNames.end() ? + xeNameItr->second : + "NameNotFound" ); esum_xaod->addThreshold( thrName ); ATH_MSG_DEBUG( "ETmiss threshold : " << thrName ); } - delete thrEtMiss; // fired missing ET thresholds - std::vector< unsigned int >* thrSumEt = recRoI.sumEtThresholdsPassed(); - std::vector< unsigned int >::const_iterator itThSumEt = thrSumEt->begin(); - for( ; itThSumEt != thrSumEt->end(); ++itThSumEt ) { - std::string thrName = "NameNotFound"; - if( teNames.find( *itThSumEt - 1 ) != teNames.end() ) { - thrName = teNames[ *itThSumEt - 1 ]; - } + std::unique_ptr< std::vector< unsigned int > > thrSumEt( + recRoI.sumEtThresholdsPassed() ); + for( unsigned int thr : *thrSumEt ) { + auto teNameItr = teNames.find( thr - 1 ); + const std::string thrName = ( teNameItr != teNames.end() ? + teNameItr->second : + "NameNotFound" ); esum_xaod->addThreshold( thrName ); ATH_MSG_DEBUG( "SumET threshold : " << thrName ); } - delete thrSumEt; // fired missing ET significance thresholds - std::vector< unsigned int >* thrMETSig = recRoI.mEtSigThresholdsPassed(); - std::vector< unsigned int >::const_iterator itThMETSig = thrMETSig->begin(); - for( ; itThMETSig != thrMETSig->end(); ++itThMETSig ) { - std::string thrName = "NameNotFound"; - if( xsNames.find( *itThMETSig - 1 ) != xsNames.end() ) { - thrName = xsNames[ *itThMETSig - 1 ]; - } + std::unique_ptr< std::vector< unsigned int > > thrMETSig( + recRoI.mEtSigThresholdsPassed() ); + for( unsigned int thr : *thrMETSig ) { + auto xsNameItr = xsNames.find( thr - 1 ); + const std::string thrName = ( xsNameItr != xsNames.end() ? + xsNameItr->second : + "NameNotFound" ); esum_xaod->addThreshold( thrName ); ATH_MSG_DEBUG( "METSig threshold : " << thrName ); } - delete thrMETSig; - } } } /// Record the results - CHECK( evtStore()->record( jet_aux, m_xaodKeyJet + "Aux." ) ); - CHECK( evtStore()->record( jet_xaod, m_xaodKeyJet ) ); + auto jetRoI = SG::makeHandle( m_jetRoIKey, ctx ); + ATH_CHECK( jetRoI.record( std::move( jet_xaod ), std::move( jet_aux ) ) ); - CHECK( evtStore()->record( jetet_aux, m_xaodKeyJetEt + "Aux." ) ); - CHECK( evtStore()->record( jetet_xaod, m_xaodKeyJetEt ) ); + auto jetetRoI = SG::makeHandle( m_jetetRoIKey, ctx ); + ATH_CHECK( jetetRoI.record( std::move( jetet_xaod ), + std::move( jetet_aux ) ) ); - CHECK( evtStore()->record( esum_aux, m_xaodKeyEsum + "Aux." ) ); - CHECK( evtStore()->record( esum_xaod, m_xaodKeyEsum ) ); + auto energysumRoI = SG::makeHandle( m_energysumRoIKey, ctx ); + ATH_CHECK( energysumRoI.record( std::move( esum_xaod ), + std::move( esum_aux ) ) ); - /// Clean up - for ( std::map< int, LVL1::JetInput* >::iterator i = jetInputs.begin(); - i != jetInputs.end(); ++i ) delete i->second; - + // Return gracefully. return StatusCode::SUCCESS; } -void RoIBResultToxAOD::addMuonRoI( const ROIB::RoIBResult* result, LVL1_ROI* lvl1ROI ) { +StatusCode RoIBResultToxAOD::createMuonRoI( const ROIB::RoIBResult& result, + const EventContext& ctx ) const { ATH_MSG_DEBUG( "in buildMuonRoI()" ); - // empty input - if( result == 0 ) return; + // Create the xAOD container. + auto mu_xaod = std::make_unique< xAOD::MuonRoIContainer >(); + auto mu_aux = std::make_unique< xAOD::MuonRoIAuxContainer >(); + mu_xaod->setStore( mu_aux.get() ); /** Get Muon Thresholds from configSvc. Also fill a map of threshold names while we are here - will be useful later */ - std::vector< TrigConf::TriggerThreshold* > thresholds = + const std::vector< TrigConf::TriggerThreshold* >& thresholds = m_configSvc->ctpConfig()->menu().thresholdVector(); std::vector< TrigConf::TriggerThreshold* > muonThresholds; std::map< int, std::string > thresholdNames; - for( std::vector< TrigConf::TriggerThreshold* >::const_iterator it = thresholds.begin(); - it != thresholds.end(); ++it ) { - if( ( *it )->type() == L1DataDef::muonType() ) { - muonThresholds.push_back( *it ); - thresholdNames.insert(std::map<int, std::string>::value_type((*it)->thresholdNumber(),(*it)->name())); + for( TrigConf::TriggerThreshold* tt : thresholds ) { + if( tt->type() == TrigConf::L1DataDef::muonType() ) { + muonThresholds.push_back( tt ); + thresholdNames[ tt->thresholdNumber() ] = tt->name(); } } // get Muon ROI - const std::vector< ROIB::MuCTPIRoI >& muonRoIV = result->muCTPIResult().roIVec(); + const std::vector< ROIB::MuCTPIRoI >& muonRoIV = + result.muCTPIResult().roIVec(); // reconstruct ROI ATH_MSG_DEBUG( "Muon ROI" ); - std::vector< ROIB::MuCTPIRoI >::const_iterator itMU = muonRoIV.begin(); - std::vector< ROIB::MuCTPIRoI >::const_iterator itMUe = muonRoIV.end(); - for ( ; itMU != itMUe; ++itMU ) { + for( const ROIB::MuCTPIRoI& roi : muonRoIV ) { - uint32_t roIWord = itMU->roIWord(); + uint32_t roIWord = roi.roIWord(); ATH_MSG_DEBUG( MSG::hex << std::setw( 8 ) << roIWord ); - if( ( m_recRPCRoiSvc == false ) || ( m_recTGCRoiSvc == false ) ) { - continue; - } - // RecRoI - LVL1::RecMuonRoI recRoI( roIWord, m_recRPCRoiSvc.operator->(), - m_recTGCRoiSvc.operator->(), &muonThresholds ); - - double thrValue = recRoI.getThresholdValue() * CLHEP::GeV; - int index = recRoI.getThresholdNumber() - 1; - std::string thrName = "NameNotFound"; - if( thresholdNames.find(index) != thresholdNames.end() ) { - thrName = thresholdNames[ index ]; - } - - // AOD component - Muon_ROI roi( roIWord, recRoI.eta(), recRoI.phi(), thrName, thrValue ); + const LVL1::RecMuonRoI recRoI( roIWord, m_recRPCRoiSvc.get(), + m_recTGCRoiSvc.get(), &muonThresholds ); - lvl1ROI->addMuonROI( roi ); - ATH_MSG_DEBUG( "Muon Thr : " << thrName << ", value = " << thrValue ); - - } // for ( ; itMU != itMUe; ++itMU ) + const double thrValue = recRoI.getThresholdValue() * GeV; + const int index = recRoI.getThresholdNumber() - 1; + auto thrNameItr = thresholdNames.find( index ); + const std::string thrName = ( thrNameItr != thresholdNames.end() ? + thrNameItr->second : + "NameNotFound" ); - return; -} + xAOD::MuonRoI* xaod_roi = new xAOD::MuonRoI(); + mu_xaod->push_back( xaod_roi ); + xaod_roi->initialize( roIWord, recRoI.eta(), recRoI.phi(), thrName, + thrValue ); -StatusCode RoIBResultToxAOD::convertToxAOD(LVL1_ROI* aod){ - - ATH_MSG_DEBUG( "converting to xAOD" ); - ATH_MSG_DEBUG( "number of Muon RoIs: " << aod->getMuonROIs().size() ); - - //////////////////////////////// - /// Muon RoIs - xAOD::MuonRoIAuxContainer* mu_aux = new xAOD::MuonRoIAuxContainer(); - xAOD::MuonRoIContainer* mu_xaod = new xAOD::MuonRoIContainer(); - mu_xaod->setStore( mu_aux ); + ATH_MSG_DEBUG( "Muon Thr : " << thrName << ", value = " << thrValue ); + } - CHECK( m_MuCnvTool->convert( aod, mu_xaod ) ); - CHECK( evtStore()->record( mu_aux, m_xaodKeyMu + "Aux." ) ); - CHECK( evtStore()->record( mu_xaod, m_xaodKeyMu ) ); + // Record the muon RoIs. + auto muonRoI = SG::makeHandle( m_muonRoIKey, ctx ); + ATH_CHECK( muonRoI.record( std::move( mu_xaod ), std::move( mu_aux ) ) ); - return StatusCode::SUCCESS; + // Return gracefully. + return StatusCode::SUCCESS; } diff --git a/PhysicsAnalysis/AnalysisTrigger/AnalysisTriggerAlgs/src/RoIBResultToxAOD.h b/PhysicsAnalysis/AnalysisTrigger/AnalysisTriggerAlgs/src/RoIBResultToxAOD.h index 02f1a810a1a2bccb24179f1b26a674b6d425ccb2..746b47061d4a6aa95d29d1bd069d8687bda92c46 100644 --- a/PhysicsAnalysis/AnalysisTrigger/AnalysisTriggerAlgs/src/RoIBResultToxAOD.h +++ b/PhysicsAnalysis/AnalysisTrigger/AnalysisTriggerAlgs/src/RoIBResultToxAOD.h @@ -1,35 +1,33 @@ // Dear emacs, this is -*- c++ -*- - -/* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration -*/ - -// $Id: RoIBResultToxAOD.h 679933 2015-07-02 21:37:29Z watsona $ +// +// Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration +// #ifndef ANALYSISTRIGGERALGS_ROIBRESULTTOXAOD_H #define ANALYSISTRIGGERALGS_ROIBRESULTTOXAOD_H // Gaudi/Athena include(s): -#include "AthenaBaseComps/AthAlgorithm.h" +#include "AthenaBaseComps/AthReentrantAlgorithm.h" #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/ToolHandle.h" -#include "StoreGate/DataHandle.h" - -// xAOD include(s): -#include "xAODTriggerCnv/IMuonRoICnvTool.h" +#include "StoreGate/ReadHandleKey.h" +#include "StoreGate/WriteHandleKey.h" -#include "TrigT1CaloToolInterfaces/IL1JEMJetTools.h" +// Tool/service include(s): +#include "TrigConfInterfaces/ILVL1ConfigSvc.h" #include "TrigT1Interfaces/RecMuonRoiSvc.h" +#include "TrigT1Interfaces/TrigT1CaloDefs.h" #include "TrigT1CaloToolInterfaces/IL1CPMTools.h" +#include "TrigT1CaloToolInterfaces/IL1JEMJetTools.h" -// Forward declaration(s): -class StoreGateSvc; -class LVL1_ROI; -namespace TrigConf { - class ILVL1ConfigSvc; -} -namespace ROIB { - class RoIBResult; -} +// EDM include(s): +#include "TrigT1Result/RoIBResult.h" +#include "xAODTrigL1Calo/CPMTowerContainer.h" +#include "xAODTrigL1Calo/JetElementContainer.h" +#include "xAODTrigger/MuonRoIContainer.h" +#include "xAODTrigger/EmTauRoIContainer.h" +#include "xAODTrigger/EnergySumRoI.h" +#include "xAODTrigger/JetEtRoI.h" +#include "xAODTrigger/JetRoIContainer.h" /** * @short RoIB result to xAOD converter @@ -45,74 +43,149 @@ namespace ROIB { * * The CTP_Decision and LVL1_ROI objects are stored in ESD/AOD. * - * $Id: RoIBResultToxAOD.h 679933 2015-07-02 21:37:29Z watsona $ - * * @author Tadashi Maeno <Tadashi.Maeno@cern.ch> * @author Attila Kraznahorkay Jr. <Attila.Krasznahorkay@cern.ch> * @author Alan Watson <Alan.Watson@cern.ch> * @author Wolfgang Ehrenfeld <Wolfgang.Menges@desy.de> - * @author last commit \$Author: watsona $ - * */ -class RoIBResultToxAOD : public AthAlgorithm { +class RoIBResultToxAOD : public AthReentrantAlgorithm { public: - RoIBResultToxAOD( const std::string& name, ISvcLocator* pSvcLocator ); + /// Algorithm constructor + RoIBResultToxAOD( const std::string& name, ISvcLocator* svcLoc ); + + /// @name Function(s) implementing the @c Algorithm interface + /// @{ + + /// Function initialising the algorithm + virtual StatusCode initialize() override; + + /// Function executing the algorithm + virtual StatusCode execute_r( const EventContext& ctx ) const override; - StatusCode initialize(); - StatusCode finalize(); - StatusCode execute(); + /// @} private: - /// build CTP_Decision from CTPResult stored in ROIB::RoIBResult - StatusCode buildCTP_Decision(); - /// add EmTauRoi to LVL1_ROI from EmTauResult stored in ROIB::RoIBResult - StatusCode addEmTauRoI(const ROIB::RoIBResult*); - /// add JetEnergyRoi to LVL1_ROI from JetEnergyResult stored in ROIB::RoIBResult - StatusCode addJetEnergyRoI(const ROIB::RoIBResult*); - /// add MuonRoi to LVL1_ROI from MuCTPIResult stored in ROIB::RoIBResult - void addMuonRoI(const ROIB::RoIBResult*, LVL1_ROI*); - /// convert AOD ROI objects to xAOD objects - StatusCode convertToxAOD(LVL1_ROI*); - - // services - ServiceHandle<TrigConf::ILVL1ConfigSvc> m_configSvc; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink - - ServiceHandle<LVL1::RecMuonRoiSvc> m_recRPCRoiSvc; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink - ServiceHandle<LVL1::RecMuonRoiSvc> m_recTGCRoiSvc; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink - - // tools - ToolHandle<LVL1::IL1CPMTools> m_EmTauTool; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink - ToolHandle<LVL1::IL1JEMJetTools> m_JetTool; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink - bool m_retrievedEmTauTool; - bool m_retrievedJetTool; - - // xAOD conversion tools: - std::string m_xaodKeyMu; - std::string m_xaodKeyEmTau; - std::string m_xaodKeyEsum; - std::string m_xaodKeyJetEt; - std::string m_xaodKeyJet; - - ToolHandle< xAODMaker::IMuonRoICnvTool > m_MuCnvTool; - - // Data object StoreGate keys - std::string m_CPMTowerLocation; - std::string m_JetElementLocation; - std::string m_roibInputKey; - std::string m_lvl1RoIOutputKey; - - // properties - bool m_doCalo; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink - bool m_doMuon; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink - - // trigger items for each TTW bit - std::vector< std::string > m_egammaItem; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink - std::vector< std::string > m_tauhadItem; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink - std::vector< std::string > m_jetItem; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink - std::vector< std::string > m_esumItem; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink - std::vector< std::string > m_highmuItem; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink - std::vector< std::string > m_lowmuItem; //!< property, see @link RoIBResultToxAOD::RoIBResultToxAOD @endlink + /// Create the EmTau RoI objects + StatusCode createEmTauRoI( const ROIB::RoIBResult& roib, + const EventContext& ctx ) const; + /// Create the JetEnergy RoI object + StatusCode createJetEnergyRoI( const ROIB::RoIBResult& roib, + const EventContext& ctx ) const; + /// Create the Muon RoI objects + StatusCode createMuonRoI( const ROIB::RoIBResult& roib, + const EventContext& ctx ) const; + + /// @name Services + /// @{ + + /// The trigger configuration service + ServiceHandle< TrigConf::ILVL1ConfigSvc > m_configSvc { + this, "LVL1ConfigSvc", "TrigConf::LVL1ConfigSvc/LVL1ConfigSvc", + "Service providing the LVL1 trigger configuration" }; + + /// The RPC RoI reconstruction service + ServiceHandle< LVL1::RecMuonRoiSvc > m_recRPCRoiSvc { + this, "RecRpcRoiSvc", LVL1::ID_RecRpcRoiSvc, + "RPC RoI reconstruction service" }; + /// The TGC RoI reconstruction service + ServiceHandle< LVL1::RecMuonRoiSvc > m_recTGCRoiSvc { + this, "RecTgcRoiSvc", LVL1::ID_RecTgcRoiSvc, + "TGC RoI reconstruction service" }; + + /// @} + + /// @name Tools + /// @{ + + /// Tool for calculation of EmTau trigger sums per RoI + ToolHandle< LVL1::IL1CPMTools > m_emTauTool { + this, "L1CPMTools", "LVL1::L1CPMTools/L1CPMTools", + "Tool for calculation of EmTau trigger sums per RoI" }; + /// Tool for calculation of Jet cluster sums per RoI + ToolHandle< LVL1::IL1JEMJetTools > m_jetTool { + this, "L1JEMJetTools", "LVL1::L1JEMJetTools/L1JEMJetTools", + "Tool for calculation of Jet cluster sums per RoI" }; + + /// @} + + /// @name Read handle keys + /// @{ + + /// Read key for the ROIB::RoIBResult object + SG::ReadHandleKey< ROIB::RoIBResult > m_roibResultKey { + this, "RoIBResultInputKey", "RoIBResult", + "Key for the ROIB::RoIBResult input object" }; + + /// Read key for the xAOD::CPMTowerContainer object + SG::ReadHandleKey< xAOD::CPMTowerContainer > m_cpmTowerKey { + this, "CPMTowerLocation", LVL1::TrigT1CaloDefs::CPMTowerLocation, + "Key for the xAOD::CPMTowerContainer input object" }; + /// Read key for the xAOD::JetElementContainer object + SG::ReadHandleKey< xAOD::JetElementContainer > m_jetElementKey { + this, "JetElementLocation", LVL1::TrigT1CaloDefs::JetElementLocation, + "Key for the xAOD::JetElementContainer input object" }; + + /// @} + + /// @name Write handle keys + /// @{ + + /// Write key for the xAOD::MuonRoIContainer object + SG::WriteHandleKey< xAOD::MuonRoIContainer > m_muonRoIKey { + this, "xAODKeyMuon", "LVL1MuonRoIs", + "Key for the xAOD::MuonRoIContainer output object" }; + /// Write key for the xAOD::EmTauRoIContainer object + SG::WriteHandleKey< xAOD::EmTauRoIContainer > m_emtauRoIKey { + this, "xAODKeyEmTau", "LVL1EmTauRoIs", + "Key for the xAOD::EmTauRoIContainer output object" }; + /// Write key for the xAOD::EnergySumRoI object + SG::WriteHandleKey< xAOD::EnergySumRoI > m_energysumRoIKey { + this, "xAODKeyEsum", "LVL1EnergySumRoI", + "Key for the xAOD::EnergySumRoI output object" }; + /// Write key for the xAOD::JetEtRoI object + SG::WriteHandleKey< xAOD::JetEtRoI > m_jetetRoIKey { + this, "xAODKeyJetEt", "LVL1JetEtRoI", + "Key for the xAOD::JetEtRoI output object" }; + /// Write key for the xAOD::JetRoIContainer object + SG::WriteHandleKey< xAOD::JetRoIContainer > m_jetRoIKey { + this, "xAODKeyJet", "LVL1JetRoIs", + "Key for the xAOD::JetRoIContainer output object" }; + + /// @} + + /// @name Other properties + /// @{ + + /// Use inputs from the Calo system + Gaudi::Property< bool > m_doCalo { + this, "DoCalo", true, "Use inputs from the Calo system" }; + /// Use inputs from the Muon system + Gaudi::Property< bool > m_doMuon { + this, "DoMuon", true, "Use inputs from the Muon system" }; + + /// List of LVL1 items for e/gamma trigger type + Gaudi::Property< std::vector< std::string > > m_egammaItem { + this, "EGammaItem", {}, "List of LVL1 items for e/gamma trigger type" }; + /// List of LVL1 items for tau trigger type + Gaudi::Property< std::vector< std::string > > m_tauhadItem { + this, "TauHadItem", {}, "List of LVL1 items for tau trigger type" }; + /// List of LVL1 items for jet trigger type + Gaudi::Property< std::vector< std::string > > m_jetItem { + this, "JetItem", {}, "List of LVL1 items for jet trigger type" }; + /// List of LVL1 items for energy sum trigger type + Gaudi::Property< std::vector< std::string > > m_esumItem { + this, "ESumItem", {}, "List of LVL1 items for energy sum trigger type" }; + /// List of LVL1 items for high pt muon trigger type + Gaudi::Property< std::vector< std::string > > m_highmuItem { + this, "HighMuItem", {}, + "List of LVL1 items for high pt muon trigger type" }; + /// List of LVL1 items for low pt muon trigger type + Gaudi::Property< std::vector< std::string > > m_lowmuItem { + this, "LowMuItem", {}, + "List of LVL1 items for low pt muon trigger type" }; + + /// @} }; // class RoIBResultToxAOD