From a162f547e3444ff56cdf7af092af837ede975e70 Mon Sep 17 00:00:00 2001 From: Teng Jian Khoo <teng.jian.khoo@cern.ch> Date: Tue, 4 Oct 2016 17:36:54 +0200 Subject: [PATCH] 'TruthParticles retrieval via TruthEvent' (METReconstruction-00-03-19) * Retrieve truth particles from TruthEvent rather than from TruthParticles * Tagged as METReconstruction-00-03-19 2016-09-24 scott snyder <snyder@bnl.gov> * Tagging METReconstruction-00-03-18. * Comply with ATLAS naming conventions. * Tagging METReconstruction-00-03-17. * Root/METJetAssocTool.cxx: Fix duplicated property warning. --- .../METReconstruction/METCaloRegionsTool.h | 2 +- .../METReconstruction/METTruthAssociator.h | 2 +- .../Root/METCaloRegionsTool.cxx | 6 +-- .../Root/METJetAssocTool.cxx | 1 - .../Root/METTruthAssociator.cxx | 53 +++++++++++++------ .../METReconstruction/Root/METTruthTool.cxx | 30 ++++++++--- .../python/METAssocConfig.py | 2 +- .../METReconstruction/python/METRecoConfig.py | 2 +- 8 files changed, 67 insertions(+), 31 deletions(-) diff --git a/Reconstruction/MET/METReconstruction/METReconstruction/METCaloRegionsTool.h b/Reconstruction/MET/METReconstruction/METReconstruction/METCaloRegionsTool.h index 9185f40be22c..6b898d45ba6e 100644 --- a/Reconstruction/MET/METReconstruction/METReconstruction/METCaloRegionsTool.h +++ b/Reconstruction/MET/METReconstruction/METReconstruction/METCaloRegionsTool.h @@ -113,7 +113,7 @@ namespace met{ REGIONS_TOTAL }; // CaloRegions human-readable names for enums - const static std::string CaloRegionNames[]; + const static std::string s_CaloRegionNames[]; private: // Default constructor: diff --git a/Reconstruction/MET/METReconstruction/METReconstruction/METTruthAssociator.h b/Reconstruction/MET/METReconstruction/METReconstruction/METTruthAssociator.h index fc5e952721ce..8a748a654220 100644 --- a/Reconstruction/MET/METReconstruction/METReconstruction/METTruthAssociator.h +++ b/Reconstruction/MET/METReconstruction/METReconstruction/METTruthAssociator.h @@ -91,7 +91,7 @@ namespace met{ std::string m_recoMuKey; std::string m_recoGamKey; std::string m_recoTauKey; - std::string m_truthPartKey; + std::string m_truthEventKey; /// Default constructor: METTruthAssociator(); diff --git a/Reconstruction/MET/METReconstruction/Root/METCaloRegionsTool.cxx b/Reconstruction/MET/METReconstruction/Root/METCaloRegionsTool.cxx index afc8070a30bc..09ba9ad41448 100644 --- a/Reconstruction/MET/METReconstruction/Root/METCaloRegionsTool.cxx +++ b/Reconstruction/MET/METReconstruction/Root/METCaloRegionsTool.cxx @@ -33,8 +33,8 @@ namespace met { using xAOD::MissingET; using xAOD::MissingETContainer; - // Initialize CaloRegionNames - const std::string METCaloRegionsTool::CaloRegionNames[METCaloRegionsTool::REGIONS_TOTAL] = + // Initialize s_CaloRegionNames + const std::string METCaloRegionsTool::s_CaloRegionNames[METCaloRegionsTool::REGIONS_TOTAL] = { "EMB", "EME", @@ -127,7 +127,7 @@ namespace met { metCont->push_back( new MissingET(0.,0.,0.) ); } // Set Name and Source - metCont->at(i)->setName( CaloRegionNames[i] ); + metCont->at(i)->setName( s_CaloRegionNames[i] ); metCont->at(i)->setSource( source ); } // The last term is Trigger MET if asked for by the user diff --git a/Reconstruction/MET/METReconstruction/Root/METJetAssocTool.cxx b/Reconstruction/MET/METReconstruction/Root/METJetAssocTool.cxx index 47ed05704730..bc64c6b431eb 100644 --- a/Reconstruction/MET/METReconstruction/Root/METJetAssocTool.cxx +++ b/Reconstruction/MET/METReconstruction/Root/METJetAssocTool.cxx @@ -39,7 +39,6 @@ namespace met { AsgTool(name), METAssociator(name) { - declareProperty( "IgnoreJetConst", m_skipconst = false ); declareProperty( "MatchRadius", m_matchRadius = 0.4 ); } diff --git a/Reconstruction/MET/METReconstruction/Root/METTruthAssociator.cxx b/Reconstruction/MET/METReconstruction/Root/METTruthAssociator.cxx index 99d358763453..f48f1915a9c2 100644 --- a/Reconstruction/MET/METReconstruction/Root/METTruthAssociator.cxx +++ b/Reconstruction/MET/METReconstruction/Root/METTruthAssociator.cxx @@ -22,7 +22,8 @@ #include "xAODEgamma/ElectronContainer.h" #include "xAODEgamma/PhotonContainer.h" #include "xAODTau/TauJetContainer.h" -#include "xAODTruth/TruthParticleContainer.h" +#include "xAODTruth/TruthEventContainer.h" +#include "AthContainers/ConstDataVector.h" // Helpers #include "xAODEgamma/EgammaxAODHelpers.h" @@ -49,7 +50,7 @@ namespace met { declareProperty("RecoGamKey", m_recoGamKey = "Photons" ); declareProperty("RecoTauKey", m_recoTauKey = "TauJets" ); - declareProperty("TruthPartKey", m_truthPartKey = "TruthParticles" ); + declareProperty("TruthEventKey", m_truthEventKey = "TruthEvents" ); } // Destructor @@ -211,14 +212,22 @@ namespace met { ATH_MSG_VERBOSE("Added core terms."); - const TruthParticleContainer* truthParticleCont(0); - if( evtStore()->retrieve(truthParticleCont, m_truthPartKey).isFailure() ) { - ATH_MSG_WARNING("Unable to retrieve input truthParticle container " << m_truthPartKey); + const TruthEventContainer* truthEventCont(0); + if( evtStore()->retrieve(truthEventCont, m_truthEventKey).isFailure() ) { + ATH_MSG_WARNING("Unable to retrieve input truthEvent container " << m_truthEventKey); return StatusCode::FAILURE; } - const IParticleContainer* uniqueTruth = metMap->getUniqueSignals(truthParticleCont,MissingETBase::UsageHandler::TruthParticle); - ATH_MSG_VERBOSE("Extracted " << uniqueTruth->size() << "/" << truthParticleCont->size() + // First truth event is the hard scatter + const TruthEvent* hsevent = truthEventCont->front(); + ConstDataVector<TruthParticleContainer> truthParticleCont(SG::VIEW_ELEMENTS); + for(size_t itp=0; itp<hsevent->nTruthParticles(); ++itp) { + truthParticleCont.push_back(hsevent->truthParticle(itp)); + ATH_MSG_VERBOSE("Extracted truth particle with index " << hsevent->truthParticle(itp)->index() ); + } + + const IParticleContainer* uniqueTruth = metMap->getUniqueSignals(truthParticleCont.asDataVector(),MissingETBase::UsageHandler::TruthParticle); + ATH_MSG_VERBOSE("Extracted " << uniqueTruth->size() << "/" << truthParticleCont.size() << " unique truth particles."); for(const auto& part : *uniqueTruth) { const xAOD::TruthParticle* truth = static_cast<const xAOD::TruthParticle*>(part); @@ -279,13 +288,20 @@ namespace met { // if(truth && truth!=eltruth) truthlist.push_back(truth); // } - const TruthParticleContainer* truthParticleCont(0); - if( evtStore()->retrieve(truthParticleCont, m_truthPartKey).isFailure() ) { - ATH_MSG_WARNING("Unable to retrieve input truthParticle container " << m_truthPartKey); + const TruthEventContainer* truthEventCont(0); + if( evtStore()->retrieve(truthEventCont, m_truthEventKey).isFailure() ) { + ATH_MSG_WARNING("Unable to retrieve input truthEvent container " << m_truthEventKey); return StatusCode::FAILURE; } - for(const auto& truth : *truthParticleCont) { + // First truth event is the hard scatter + const TruthEvent* hsevent = truthEventCont->front(); + ConstDataVector<TruthParticleContainer> truthParticleCont(SG::VIEW_ELEMENTS); + for(size_t itp=0; itp<hsevent->nTruthParticles(); ++itp) { + truthParticleCont.push_back(hsevent->truthParticle(itp)); + } + + for(const auto& truth : truthParticleCont) { if(truth->pt()<1) continue; // stable if(!MC::isGenStable(truth->status(),truth->barcode())) continue; @@ -353,13 +369,20 @@ namespace met { // } // } - const TruthParticleContainer* truthParticleCont(0); - if( evtStore()->retrieve(truthParticleCont, m_truthPartKey).isFailure() ) { - ATH_MSG_WARNING("Unable to retrieve input truthParticle container " << m_truthPartKey); + const TruthEventContainer* truthEventCont(0); + if( evtStore()->retrieve(truthEventCont, m_truthEventKey).isFailure() ) { + ATH_MSG_WARNING("Unable to retrieve input truthEvent container " << m_truthEventKey); return StatusCode::FAILURE; } - for(const auto& truth : *truthParticleCont) { + // First truth event is the hard scatter + const TruthEvent* hsevent = truthEventCont->front(); + ConstDataVector<TruthParticleContainer> truthParticleCont(SG::VIEW_ELEMENTS); + for(size_t itp=0; itp<hsevent->nTruthParticles(); ++itp) { + truthParticleCont.push_back(hsevent->truthParticle(itp)); + } + + for(const auto& truth : truthParticleCont) { if(truth->pt()<1) continue; // stable if(!MC::isGenStable(truth->status(),truth->barcode())) continue; diff --git a/Reconstruction/MET/METReconstruction/Root/METTruthTool.cxx b/Reconstruction/MET/METReconstruction/Root/METTruthTool.cxx index 2f5092309d55..55bec9104f70 100644 --- a/Reconstruction/MET/METReconstruction/Root/METTruthTool.cxx +++ b/Reconstruction/MET/METReconstruction/Root/METTruthTool.cxx @@ -21,9 +21,13 @@ #include "xAODMissingET/MissingETAuxComponentMap.h" // Truth EDM +#include "xAODTruth/TruthEventContainer.h" #include "xAODTruth/TruthParticleContainer.h" #include "xAODTruth/TruthVertex.h" +// Base EDM +#include "AthContainers/ConstDataVector.h" + // Truth Utilities #include "TruthUtils/TruthParticleHelpers.h" @@ -33,6 +37,8 @@ namespace met { // using xAOD::IParticle; // + using xAOD::TruthEvent; + using xAOD::TruthEventContainer; using xAOD::TruthParticle; using xAOD::TruthParticleContainer; // @@ -199,26 +205,34 @@ namespace met { ATH_MSG_DEBUG ("In execute: " << name() << "..."); - const TruthParticleContainer* truthCont = 0; + const TruthEventContainer* truthEvents = 0; metTerm->setSource(m_truth_type); // Retrieve the truth container - if ( evtStore()->retrieve(truthCont, m_input_data_key).isFailure() ) { - ATH_MSG_WARNING("Unable to retrieve input truth particle container"); + if ( evtStore()->retrieve(truthEvents, m_input_data_key).isFailure() ) { + ATH_MSG_WARNING("Unable to retrieve input truth event container"); return StatusCode::SUCCESS; } + // First truth event is the hard scatter + const TruthEvent* hsevent = truthEvents->front(); + ConstDataVector<TruthParticleContainer> truthCont(SG::VIEW_ELEMENTS); + for(size_t itp=0; itp<hsevent->nTruthParticles(); ++itp) { + truthCont.push_back(hsevent->truthParticle(itp)); + ATH_MSG_VERBOSE("Extracted truth particle with index " << hsevent->truthParticle(itp)->index()); + } + vector<const IParticle*> signalList; - signalList.reserve(truthCont->size()); + signalList.reserve(truthCont.size()); // Loop over all truth particles - for( TruthParticleContainer::const_iterator iTruth=truthCont->begin(); iTruth!=truthCont->end(); ++iTruth ) { + for( const auto& truthp : truthCont ) { // Check if truth particles satisfies the requirements - if( this->accept(*iTruth) ) { + if( this->accept(truthp) ) { // Add the selected truth particles to the list - signalList.push_back(*iTruth); + signalList.push_back(truthp); } - } // end loop over truths + } // end loop over truth particles // Loop over the content and add to MET MissingETBase::Types::weight_t unitWeight(1.,1.,1.); diff --git a/Reconstruction/MET/METReconstruction/python/METAssocConfig.py b/Reconstruction/MET/METReconstruction/python/METAssocConfig.py index 9421a9a5082c..ac1ff5794b88 100644 --- a/Reconstruction/MET/METReconstruction/python/METAssocConfig.py +++ b/Reconstruction/MET/METReconstruction/python/METAssocConfig.py @@ -25,7 +25,7 @@ defaultInputKey = { 'ClusColl' :'CaloCalTopoClusters', 'TrkColl' :'InDetTrackParticles', 'PrimVxColl':'PrimaryVertices', - 'Truth' :'TruthParticles', + 'Truth' :'TruthEvents', 'LCOCClusColl':'LCOriginTopoClusters', 'EMOCClusColl':'EMOriginTopoClusters', } diff --git a/Reconstruction/MET/METReconstruction/python/METRecoConfig.py b/Reconstruction/MET/METReconstruction/python/METRecoConfig.py index 012734561499..ceea93c5fd54 100644 --- a/Reconstruction/MET/METReconstruction/python/METRecoConfig.py +++ b/Reconstruction/MET/METReconstruction/python/METRecoConfig.py @@ -31,7 +31,7 @@ defaultInputKey = { 'SoftClus' :'CaloCalTopoClusters', 'SoftPFlow':'JetETMissNeutralParticleFlowObjects', 'PrimaryVx':'PrimaryVertices', - 'Truth' :'TruthParticles', + 'Truth' :'TruthEvents', 'Calo' :'AllCalo', 'LCOCSoftClus':'LCOriginTopoClusters', 'EMOCSoftClus':'EMOriginTopoClusters', -- GitLab