diff --git a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleToJetAssociator.h b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleToJetAssociator.h index 6a8a908c56bfa5e55a9d55f51a741d87e694276a..e40f18f2290222afd89ab26084a284909a481c31 100644 --- a/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleToJetAssociator.h +++ b/PhysicsAnalysis/AnalysisCommon/ParticleJetTools/ParticleJetTools/ParticleToJetAssociator.h @@ -25,6 +25,7 @@ comments: A. Wildauer: 27.01.2005 rewritten into an AlgTool #include "xAODJet/Jet.h" #include "xAODJet/JetContainer.h" +#include <memory> #include <vector> #include <list> #include <string> @@ -70,12 +71,12 @@ class ParticleToJetAssociator : public asg::AsgTool { // For the new way // FF: return the vector of associations template<typename ConstituentType, typename coll> - std::vector<ConstituentType*> + std::vector< std::unique_ptr<ConstituentType> > associateParticlesToJets(jetcollection_t* theJets, const coll* particleContainer, const std::string& constituentName) const; template<typename ConstituentType, typename coll> - std::vector<ConstituentType*> + std::vector< std::unique_ptr<ConstituentType> > associateParticlesToJets(const xAOD::JetContainer* theJets, const coll* particleContainer, const std::string& constituentName) const; @@ -176,19 +177,19 @@ class ParticleToJetAssociator : public asg::AsgTool { // For the new way template<typename ConstituentType, typename coll> - inline std::vector<ConstituentType*> + inline std::vector< std::unique_ptr<ConstituentType> > ParticleToJetAssociator::associateParticlesToJets(jetcollection_t* theJets, const coll* particleContainer, const std::string& constituentName) const { - std::vector<ConstituentType*> vecTrackConst; + std::vector< std::unique_ptr<ConstituentType> > vecTrackConst; ATH_MSG_VERBOSE("Number of Jets : " << theJets->size()); if (theJets->size()<1) return vecTrackConst; ATH_MSG_VERBOSE("Number of Particles of Type " << constituentName << " : " << particleContainer->size()); for (jetcollection_t::iterator itr = theJets->begin(); itr != theJets->end(); ++itr) { // NameType name(constituentName); - vecTrackConst.push_back(new ConstituentType); + vecTrackConst.push_back( std::make_unique<ConstituentType>() ); } int index(0); @@ -275,19 +276,19 @@ template<typename ConstituentType, typename coll> } template<typename ConstituentType, typename coll> - inline std::vector<ConstituentType*> + inline std::vector< std::unique_ptr<ConstituentType> > ParticleToJetAssociator::associateParticlesToJets(const xAOD::JetContainer * theJets, const coll* particleContainer, const std::string& constituentName) const { - std::vector<ConstituentType*> vecTrackConst; + std::vector< std::unique_ptr<ConstituentType> > vecTrackConst; ATH_MSG_VERBOSE("Number of Jets : " << theJets->size()); if (theJets->size()<1) return vecTrackConst; ATH_MSG_VERBOSE("Number of Particles of Type " << constituentName << " : " << particleContainer->size()); for (xAOD::JetContainer::const_iterator itr = theJets->begin(); itr != theJets->end(); ++itr) { // NameType name(constituentName); - vecTrackConst.push_back(new ConstituentType); + vecTrackConst.push_back( std::make_unique<ConstituentType>() ); } int index(0); diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/src/BTagTrackAssociation.cxx b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/src/BTagTrackAssociation.cxx index b6c6d8a28f3d267b738b77c7b4b292be138b3223..a4fb6d184f518ebfceb08e6974c981fbf0ed6cd3 100644 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/src/BTagTrackAssociation.cxx +++ b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/src/BTagTrackAssociation.cxx @@ -156,7 +156,7 @@ namespace Analysis { ATH_MSG_VERBOSE("#BTAG# Number of TrackParticles in event: " << tpContainer->size()); // compute the associations - std::vector<std::vector<const xAOD::TrackParticle*>*> assocs = + std::vector< std::unique_ptr< std::vector<const xAOD::TrackParticle*> > > assocs = (*tAssocIter)->associateParticlesToJets<std::vector<const xAOD::TrackParticle*>, xAOD::TrackParticleContainer>( theJets, tpContainer, *tAssocNameIter ); // then store them in the BTagging objects. Note that for this to work, the ElementLink from Jet to BTagging object must exist @@ -184,10 +184,6 @@ namespace Analysis { ++i; } ATH_MSG_VERBOSE("#BTAG# stored track-to jet associations under name " << *tAssocNameIter); - //delete pointer created in associateParticlesToJets - for (i=0; i < assocs.size(); i++) { - delete assocs[i]; - } ++tNameIter; ++tAssocNameIter; } @@ -208,7 +204,7 @@ namespace Analysis { } ATH_MSG_DEBUG("#BTAG# Number of Muons in event: " << muonContainer->size()); - std::vector<std::vector<const xAOD::Muon*>*> assocs = + std::vector< std::unique_ptr< std::vector<const xAOD::Muon*> > > assocs = (*muAssocIter)->associateParticlesToJets<std::vector<const xAOD::Muon*>, xAOD::MuonContainer>( theJets, muonContainer, *muAssocNameIter ); // then store them in the BTagging objects. Note that for this to work, the ElementLink from Jet to BTagging object must exist @@ -225,10 +221,6 @@ namespace Analysis { ++i; } ATH_MSG_VERBOSE("#BTAG# stored muon-to-jet associations under name " << *muAssocNameIter); - //delete pointer created in associateParticlesToJets - for (i=0; i < assocs.size(); i++) { - delete assocs[i]; - } ++muNameIter; ++muAssocNameIter; } @@ -281,7 +273,7 @@ namespace Analysis { ATH_MSG_VERBOSE("#BTAG# Number of TrackParticles in event: " << (*h_TrackContainerName).size()); // compute the associations - std::vector<std::vector<const xAOD::TrackParticle*>*> assocs = + std::vector< std::unique_ptr< std::vector<const xAOD::TrackParticle*> > > assocs = (*tAssocIter)->associateParticlesToJets<std::vector<const xAOD::TrackParticle*>, xAOD::TrackParticleContainer>( jetContainer, &(*h_TrackContainerName), *tAssocNameIter ); // then store them in the BTagging objects. @@ -297,10 +289,6 @@ namespace Analysis { ++i; } ATH_MSG_VERBOSE("#BTAG# stored track-to jet associations under name " << *tAssocNameIter); - //delete pointer created in associateParticlesToJets - for (i=0; i < assocs.size(); i++) { - delete assocs[i]; - } ++tAssocNameIter; } @@ -329,7 +317,7 @@ namespace Analysis { } ATH_MSG_DEBUG("#BTAG# Number of Muons in event: " << (*h_MuonContainerName).size()); - std::vector<std::vector<const xAOD::Muon*>*> assocs = + std::vector< std::unique_ptr< std::vector<const xAOD::Muon*> > > assocs = (*muAssocIter)->associateParticlesToJets<std::vector<const xAOD::Muon*>, xAOD::MuonContainer>( jetContainer, &(*h_MuonContainerName), *muAssocNameIter ); // then store them in the BTagging objects. @@ -345,10 +333,6 @@ namespace Analysis { ++i; } ATH_MSG_VERBOSE("#BTAG# stored muon-to-jet associations under name " << *muAssocNameIter); - //delete pointer created in associateParticlesToJets - for (i=0; i < assocs.size(); i++) { - delete assocs[i]; - } ++muNameIter; ++muAssocNameIter; } diff --git a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/src/JetParticleAssociationAlg.cxx b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/src/JetParticleAssociationAlg.cxx index ee3dc2693d154c4a86bdf5e47f8ebcc82ce56786..f635e280222f8c617dd69e70196a38bc747cdb34 100644 --- a/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/src/JetParticleAssociationAlg.cxx +++ b/PhysicsAnalysis/JetTagging/JetTagAlgs/BTagging/src/JetParticleAssociationAlg.cxx @@ -69,7 +69,7 @@ namespace Analysis { if (m_release == "21") { // compute the associations - std::vector<std::vector<const xAOD::TrackParticle*>*> assocs = + std::vector< std::unique_ptr< std::vector<const xAOD::TrackParticle*> > > assocs = m_TrackToJetAssociator->associateParticlesToJets<std::vector<const xAOD::TrackParticle*>, xAOD::TrackParticleContainer>( h_JetCollectionName.ptr(), h_TrackParticleContainerName.ptr(), "'BTagTrackToJetAssociator ala 21" ); unsigned int i = 0;