diff --git a/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/LeptonTaggers/NonPromptLeptonVertexingAlg.h b/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/LeptonTaggers/NonPromptLeptonVertexingAlg.h index fb73ceb9fd5873977ffe519d89aefa8f6d9364ab..4a24af7be118136d03922c4def2f97d4a901f203 100644 --- a/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/LeptonTaggers/NonPromptLeptonVertexingAlg.h +++ b/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/LeptonTaggers/NonPromptLeptonVertexingAlg.h @@ -1,7 +1,7 @@ // This is -*- c++ -*- /* - Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration */ #ifndef NONPROMPTLEPTONVERTEXINGALG_H @@ -25,6 +25,7 @@ // Athena #include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/WriteDecorHandleKey.h" #include "GaudiKernel/ToolHandle.h" #include "xAODTracking/TrackParticleContainer.h" @@ -109,9 +110,6 @@ namespace Prompt Gaudi::Property<double> m_mergeMinVtxDist {this, "MergeMinVtxDist", 1.0}; Gaudi::Property<double> m_mergeChi2OverDoF {this, "MergeChi2OverDoF", 5.0}; - Gaudi::Property<std::string> m_decoratorNameSecVtxLinks {this, "SecVtxLinksName", "default"}; - Gaudi::Property<std::string> m_decoratorNameDeepMergedSecVtxLinks {this, "DeepMergedSecVtxLinksName", "default"}; - Gaudi::Property<std::string> m_decoratorNameIndexVector {this, "IndexVectorName"}; Gaudi::Property<std::string> m_linkNameRefittedPriVtxWithoutLepton {this, "NoLeptonPriVtxLinkName"}; Gaudi::Property<std::string> m_refittedVertexTypeName{ @@ -159,10 +157,15 @@ namespace Prompt // // Decorators // - std::unique_ptr<decoratorVecInt_t> m_indexVectorDec; - std::unique_ptr<decoratorVecInt_t> m_indexVectorDecDeepMerge; - std::unique_ptr<decoratorVecElemVtx_t> m_lepSVElementLinksDec; - std::unique_ptr<decoratorVecElemVtx_t> m_lepDeepMergedSVElementLinksDec; + + SG::WriteDecorHandleKey<xAOD::IParticleContainer> m_decoratorNameSecVtxLinks + { this, "SecVtxLinksName", m_leptonContainerKey, "default", }; + SG::WriteDecorHandleKey<xAOD::IParticleContainer> m_decoratorNameDeepMergedSecVtxLinks + { this, "DeepMergedSecVtxLinksName", m_leptonContainerKey, "default", }; + SG::WriteDecorHandleKey<xAOD::IParticleContainer> m_decoratorNameIndexVector + { this, "IndexVectorName", m_leptonContainerKey, "", }; + SG::WriteDecorHandleKey<xAOD::IParticleContainer> m_decoratorNameIndexVectorDeepMerge + { this, "IndexVectorNameDeepMerge", m_leptonContainerKey, "", }; }; } diff --git a/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/src/NonPromptLeptonVertexingAlg.cxx b/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/src/NonPromptLeptonVertexingAlg.cxx index a5dfee192fb59947d55011fc7908c5cffca4d65d..079cf4ffd646c0cf15ae07e50c6dc12e3547093c 100644 --- a/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/src/NonPromptLeptonVertexingAlg.cxx +++ b/PhysicsAnalysis/AnalysisCommon/LeptonTaggers/src/NonPromptLeptonVertexingAlg.cxx @@ -9,6 +9,9 @@ // Athena #include "xAODEgamma/EgammaxAODHelpers.h" #include "xAODTracking/VertexAuxContainer.h" +#include "StoreGate/WriteDecorHandle.h" +#include "StoreGate/DecorKeyHelpers.h" +#include "GaudiKernel/ThreadLocalContext.h" // C/C++ #include <cmath> @@ -54,16 +57,16 @@ StatusCode Prompt::NonPromptLeptonVertexingAlg::initialize() ATH_CHECK(m_svContainerName.initialize()); - m_indexVectorDec = std::make_unique<decoratorVecInt_t> (m_decoratorNameIndexVector); - m_indexVectorDecDeepMerge = std::make_unique<decoratorVecInt_t> (m_decoratorNameIndexVector+"DeepMerge"); - - m_lepSVElementLinksDec = std::make_unique<decoratorVecElemVtx_t>(m_decoratorNameSecVtxLinks); - m_lepDeepMergedSVElementLinksDec = std::make_unique<decoratorVecElemVtx_t>(m_decoratorNameDeepMergedSecVtxLinks); + m_decoratorNameIndexVectorDeepMerge = SG::decorKeyFromKey(m_decoratorNameIndexVector.key()) + "DeepMerge"; + ATH_CHECK(m_decoratorNameIndexVector.initialize()); + ATH_CHECK(m_decoratorNameIndexVectorDeepMerge.initialize()); + ATH_CHECK(m_decoratorNameSecVtxLinks.initialize()); + ATH_CHECK(m_decoratorNameDeepMergedSecVtxLinks.initialize()); ATH_MSG_DEBUG("LeptonContainerName = " << m_leptonContainerKey); ATH_MSG_DEBUG("ReFitPriVtxContainerName = " << m_refittedPriVtxContainerName); ATH_MSG_DEBUG("SVContainerName = " << m_svContainerName); - ATH_MSG_DEBUG("IndexVectorName = " << m_decoratorNameIndexVector); + ATH_MSG_DEBUG("IndexVectorName = " << m_decoratorNameIndexVector.key()); ATH_MSG_DEBUG("mergeMinVtxDist = " << m_mergeMinVtxDist); ATH_MSG_DEBUG("mergeChi2OverDoF = " << m_mergeChi2OverDoF); @@ -108,12 +111,14 @@ StatusCode Prompt::NonPromptLeptonVertexingAlg::execute() // TimerScopeHelper timer(m_timerExec); + const EventContext& ctx = Gaudi::Hive::currentContext(); + m_countEvents++; // // Find Inner Detector tracks save them class member variable for convenience. // - SG::ReadHandle<xAOD::TrackParticleContainer> h_inDetTracks(m_inDetTracksKey); + SG::ReadHandle<xAOD::TrackParticleContainer> h_inDetTracks(m_inDetTracksKey, ctx); if (!h_inDetTracks.isValid()){ ATH_MSG_FATAL("execute - failed to find the InDetTrackParticles"); return StatusCode::FAILURE; @@ -126,7 +131,7 @@ StatusCode Prompt::NonPromptLeptonVertexingAlg::execute() // std::set< xAOD::Vertex* > svSet; - SG::WriteHandle<xAOD::VertexContainer> h_SVContainer (m_svContainerName); + SG::WriteHandle<xAOD::VertexContainer> h_SVContainer (m_svContainerName, ctx); ATH_CHECK(h_SVContainer.record( std::make_unique< xAOD::VertexContainer>(), std::make_unique< xAOD::VertexAuxContainer>() )); @@ -135,9 +140,9 @@ StatusCode Prompt::NonPromptLeptonVertexingAlg::execute() // // Retrieve containers from evtStore // - SG::ReadHandle<xAOD::IParticleContainer> leptonContainer (m_leptonContainerKey); - SG::ReadHandle<xAOD::VertexContainer> vertices (m_primaryVertexContainerName); - SG::ReadHandle<xAOD::VertexContainer> refittedVertices(m_refittedPriVtxContainerName); + SG::ReadHandle<xAOD::IParticleContainer> leptonContainer (m_leptonContainerKey, ctx); + SG::ReadHandle<xAOD::VertexContainer> vertices (m_primaryVertexContainerName, ctx); + SG::ReadHandle<xAOD::VertexContainer> refittedVertices(m_refittedPriVtxContainerName, ctx); ATH_MSG_DEBUG ("NonPromptLeptonVertexingAlg::execute - Read " << vertices->size() << " primary vertices"); ATH_MSG_DEBUG ("NonPromptLeptonVertexingAlg::execute - Read " << refittedVertices->size() << " refitted primary vertices"); @@ -182,6 +187,16 @@ StatusCode Prompt::NonPromptLeptonVertexingAlg::execute() SG::AuxElement::ConstAccessor<ElementLink<xAOD::VertexContainer> > priVtxWithoutLepAcc(m_linkNameRefittedPriVtxWithoutLepton); + using VecElemVtx_t = std::vector<ElementLink<xAOD::VertexContainer> >; + SG::WriteDecorHandle<xAOD::IParticleContainer, std::vector<int> > + indexVectorDec (m_decoratorNameIndexVector, ctx); + SG::WriteDecorHandle<xAOD::IParticleContainer, std::vector<int> > + indexVectorDecDeepMerge (m_decoratorNameIndexVectorDeepMerge, ctx); + SG::WriteDecorHandle<xAOD::IParticleContainer, VecElemVtx_t> + lepSVElementLinksDec (m_decoratorNameSecVtxLinks, ctx); + SG::WriteDecorHandle<xAOD::IParticleContainer, VecElemVtx_t> + lepDeepMergedSVElementLinksDec (m_decoratorNameDeepMergedSecVtxLinks, ctx); + for(const xAOD::IParticle *lepton: *leptonContainer) { const xAOD::TrackParticle *tracklep = 0; const xAOD::Electron *elec = dynamic_cast<const xAOD::Electron*>(lepton); @@ -210,10 +225,10 @@ StatusCode Prompt::NonPromptLeptonVertexingAlg::execute() } if(!tracklep) { - (*m_lepSVElementLinksDec) (*lepton) = std::vector<ElementLink<xAOD::VertexContainer> >(); - (*m_lepDeepMergedSVElementLinksDec)(*lepton) = std::vector<ElementLink<xAOD::VertexContainer> >(); - (*m_indexVectorDec) (*lepton) = std::vector<int>(); - (*m_indexVectorDecDeepMerge) (*lepton) = std::vector<int>(); + lepSVElementLinksDec (*lepton).clear(); + lepDeepMergedSVElementLinksDec(*lepton).clear(); + indexVectorDec (*lepton).clear(); + indexVectorDecDeepMerge (*lepton).clear(); ATH_MSG_DEBUG("NonPromptLeptonVertexingAlg::execute - cannot find muon->inDetTrackParticleLink() nor electron->trackParticle()"); continue; @@ -290,10 +305,10 @@ StatusCode Prompt::NonPromptLeptonVertexingAlg::execute() ATH_MSG_DEBUG ("NonPromptLeptonVertexingAlg::execute -- number of two-track SV = " << twoTrkVertices.size()); ATH_MSG_DEBUG ("NonPromptLeptonVertexingAlg::execute -- number of deep merged SV = " << deep_merged_result.vtxsNewMerged.size()); - (*m_lepSVElementLinksDec) (*lepton) = svLinks; - (*m_lepDeepMergedSVElementLinksDec)(*lepton) = deepmergeSVLinks; - (*m_indexVectorDec) (*lepton) = indexVectorTwoTrk; - (*m_indexVectorDecDeepMerge) (*lepton) = indexVectorDeepMerged; + lepSVElementLinksDec (*lepton) = std::move(svLinks); + lepDeepMergedSVElementLinksDec(*lepton) = std::move(deepmergeSVLinks); + indexVectorDec (*lepton) = std::move(indexVectorTwoTrk); + indexVectorDecDeepMerge (*lepton) = std::move(indexVectorDeepMerged); ATH_MSG_DEBUG("NonPromptLeptonVertexingAlg - done with lepton pT=" << tracklep->pt() << ", " << truthAsStr(*lepton) << endl << "___________________________________________________________________________");