diff --git a/MuonSpectrometer/MuonTruthAlgs/MuonTruthAlgs/MuonTrackTruthTool.h b/MuonSpectrometer/MuonTruthAlgs/MuonTruthAlgs/MuonTrackTruthTool.h index d755688f54de5668a14487f48a4b2c8f27dfb5a6..d919b8381b1cc45a8e57d17b510176576fabed2e 100644 --- a/MuonSpectrometer/MuonTruthAlgs/MuonTruthAlgs/MuonTrackTruthTool.h +++ b/MuonSpectrometer/MuonTruthAlgs/MuonTruthAlgs/MuonTrackTruthTool.h @@ -147,7 +147,7 @@ namespace Muon { ToolHandle<Trk::ITruthTrajectoryBuilder> m_truthTrajectoryBuilder{this,"TruthTrajectoryBuilder","Muon::MuonDecayTruthTrajectoryBuilder/MuonDecayTruthTrajectoryBuilder"}; mutable TruthTree m_truthTree; - mutable std::vector<TruthTrajectory*> m_truthTrajectoriesToBeDeleted; + mutable std::vector<std::unique_ptr<TruthTrajectory> > m_truthTrajectoriesToBeDeleted; mutable std::map<int,int> m_barcodeMap; // map used to link barcode of TrackRecord particles/hits to 'final' state barcode Gaudi::Property<bool> m_manipulateBarCode{this,"ManipulateBarCode",false}; diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonTrackTruthTool.cxx b/MuonSpectrometer/MuonTruthAlgs/src/MuonTrackTruthTool.cxx index c343b108ef4b51159869e2aea340876b05d83bca..e5e4cf377e319a9d5db1b722d4341f59368ef625 100644 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonTrackTruthTool.cxx +++ b/MuonSpectrometer/MuonTruthAlgs/src/MuonTrackTruthTool.cxx @@ -156,13 +156,13 @@ namespace Muon { } ATH_MSG_VERBOSE(" found new particle with pdgid " << PDGCode << " in truth record, barcode " << barcode); - TruthTrajectory* truthTrajectory = 0; + std::unique_ptr<TruthTrajectory> truthTrajectory; // associate the muon truth with the gen event info if( genEvent ){ HepMC::GenParticle* genParticle = genEvent->barcode_to_particle( (*tr_it).GetBarCode() ); if( genParticle ){ - truthTrajectory = new TruthTrajectory(); - m_truthTrajectoryBuilder->buildTruthTrajectory(truthTrajectory,genParticle); + truthTrajectory = std::make_unique<TruthTrajectory>(); + m_truthTrajectoryBuilder->buildTruthTrajectory(truthTrajectory.get(),genParticle); if( !truthTrajectory->empty() ){ // always use barcode of the 'final' particle in chain in map @@ -212,8 +212,8 @@ namespace Muon { TruthTreeEntry& entry = m_truthTree[barcode]; entry.truthTrack = &(*tr_it); - entry.truthTrajectory = truthTrajectory; - m_truthTrajectoriesToBeDeleted.push_back(truthTrajectory); + entry.truthTrajectory = truthTrajectory.get(); + m_truthTrajectoriesToBeDeleted.push_back(std::move(truthTrajectory)); } // add sim data collections @@ -698,9 +698,6 @@ namespace Muon { void MuonTrackTruthTool::clear() const { m_truthTree.clear(); m_barcodeMap.clear(); - std::vector<TruthTrajectory*>::iterator dit = m_truthTrajectoriesToBeDeleted.begin(); - std::vector<TruthTrajectory*>::iterator dit_end = m_truthTrajectoriesToBeDeleted.end(); - for( ;dit!=dit_end;++dit ) delete *dit; m_truthTrajectoriesToBeDeleted.clear(); } diff --git a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthDecorationAlg.cxx b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthDecorationAlg.cxx index 1199406c5469d84c760a14048be2323c8a9b8e34..e531dc87f97a318010afcc347ecae3885dba3767 100644 --- a/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthDecorationAlg.cxx +++ b/MuonSpectrometer/MuonTruthAlgs/src/MuonTruthDecorationAlg.cxx @@ -163,8 +163,10 @@ namespace Muon { // loop over chamber layers for( const auto& lay : ids ){ // skip empty layers - Amg::Vector3D* firstPos = 0; - Amg::Vector3D* secondPos = 0; + Amg::Vector3D firstPos = Amg::Vector3D::Zero(); + Amg::Vector3D secondPos = Amg::Vector3D::Zero(); + bool firstPosSet = false; + bool secondPosSet = false; Identifier chId; int index = -1; uint8_t nprecLayers = 0; @@ -218,14 +220,18 @@ namespace Muon { if( isEndcap ) return fabs(p1.z()) < fabs(p2.z()); else return p1.perp() < p2.perp(); }; - if( !firstPos ) firstPos = new Amg::Vector3D(gpos); - else if( !secondPos ){ - secondPos = new Amg::Vector3D(gpos); - if( isSmaller(*secondPos,*firstPos) ) std::swap(firstPos,secondPos); + if( !firstPosSet ) { + firstPos = gpos; + firstPosSet = true; + } + else if( !secondPosSet ){ + secondPos = gpos; + secondPosSet = true; + if( isSmaller(secondPos,firstPos) ) std::swap(firstPos,secondPos); }else{ // update position if we can increase the distance between the two positions - if( isSmaller(gpos,*firstPos) ) *firstPos = gpos; - else if( isSmaller(*secondPos,gpos) ) *secondPos = gpos; + if( isSmaller(gpos,firstPos) ) firstPos = gpos; + else if( isSmaller(secondPos,gpos) ) secondPos = gpos; } } } @@ -238,14 +244,18 @@ namespace Muon { Amg::Vector3D locpos(0,pos->second.getdeposits()[0].second.ypos(),pos->second.getdeposits()[0].second.zpos()); gpos=descriptor->localToGlobalCoords(locpos,m_idHelperSvc->cscIdHelper().elementID(id)); ATH_MSG_DEBUG("got CSC global position "<<gpos); - if( !firstPos ) firstPos = new Amg::Vector3D(gpos); - else if( !secondPos ){ - secondPos = new Amg::Vector3D(gpos); - if(secondPos->perp()<firstPos->perp()) std::swap(firstPos,secondPos); + if( !firstPosSet ) { + firstPos = gpos; + firstPosSet = true; + } + else if( !secondPosSet ){ + secondPos = gpos; + secondPosSet = true; + if(secondPos.perp() < firstPos.perp()) std::swap(firstPos,secondPos); } else{ - if( gpos.perp()<firstPos->perp() ) *firstPos = gpos; - else if( secondPos->perp()<gpos.perp() ) *secondPos = gpos; + if( gpos.perp() < firstPos.perp() ) firstPos = gpos; + else if( secondPos.perp() < gpos.perp() ) secondPos = gpos; } } } @@ -272,16 +282,14 @@ namespace Muon { MuonStationIndex::ChIndex chIndex = m_idHelperSvc->chamberIndex(chId); segment->setIdentifier(sector,chIndex,eta,technology); } - if( firstPos && secondPos ){ - Amg::Vector3D gpos = (*firstPos+*secondPos)/2.; - Amg::Vector3D gdir = (*firstPos-*secondPos).unit(); + if( firstPosSet && secondPosSet ){ + Amg::Vector3D gpos = (firstPos+secondPos)/2.; + Amg::Vector3D gdir = (firstPos-secondPos).unit(); ATH_MSG_DEBUG(" got position : r " << gpos.perp() << " z " << gpos.z() << " and direction: theta " << gdir.theta() << " phi " << gdir.phi() ); segment->setPosition(gpos.x(),gpos.y(),gpos.z()); segment->setDirection(gdir.x(),gdir.y(),gdir.z()); } - delete firstPos; - delete secondPos; } } }