diff --git a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCandidateTool.cxx b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCandidateTool.cxx index 986c83e0988b33ef6991878b127a1f1540e62e67..e0c68076bd26bda293c013468ea28328835d3dc7 100644 --- a/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCandidateTool.cxx +++ b/Reconstruction/MuonIdentification/MuonCombinedBaseTools/src/MuonCandidateTool.cxx @@ -173,17 +173,16 @@ namespace MuonCombined { } std::unique_ptr<MuonCandidate> muon_candidate; - + ElementLink<xAOD::TrackParticleContainer> MS_TrkLink{tracks, tLink->container_index, ctx}; if (tLink->extp_succeed) { outputTracks.push_back(std::move(tLink->track)); - ElementLink<TrackCollection> saLink(outputTracks, outputTracks.size() - 1); + ElementLink<TrackCollection> saLink(outputTracks, outputTracks.size() - 1, ctx); muon_candidate = - std::make_unique<MuonCandidate>(ElementLink<xAOD::TrackParticleContainer>(tracks, tLink->container_index), saLink); + std::make_unique<MuonCandidate>(MS_TrkLink, saLink, outputTracks.size() - 1); // remove track from set so it is not deleted } else { // in this case the extrapolation failed - muon_candidate = std::make_unique<MuonCandidate>(ElementLink<xAOD::TrackParticleContainer>(tracks, tLink->container_index), - ElementLink<TrackCollection>()); + muon_candidate = std::make_unique<MuonCandidate>(MS_TrkLink); } muon_candidate->setComissioning(m_comissioning); /// Last but not least set the segments diff --git a/Reconstruction/MuonIdentification/MuonCombinedEvent/MuonCombinedEvent/MuonCandidate.h b/Reconstruction/MuonIdentification/MuonCombinedEvent/MuonCombinedEvent/MuonCandidate.h index df0980c0ef8124a57d853dfa670c6c1ad665594f..67d73c423e54ce0ea411c29a368a53e34faee70f 100644 --- a/Reconstruction/MuonIdentification/MuonCombinedEvent/MuonCombinedEvent/MuonCandidate.h +++ b/Reconstruction/MuonIdentification/MuonCombinedEvent/MuonCombinedEvent/MuonCandidate.h @@ -21,32 +21,16 @@ namespace MuonCombined { class MuonCandidate { public: - /** constructor taking an Trk::Track reference to the spectromter track - Users should ensure that the element link is valid and the lifetime of the Track object is longer that the MuonCandidate - as it internally caches a pointer to it. - */ - MuonCandidate(const Trk::Track& msTrack); - - /** constructor taking an Trk::Track reference to the spectromter track - Users should ensure that the element link is valid and the lifetime of the Track object is longer that the MuonCandidate - as it internally caches a pointer to it. Class takes ownership of the extrapolatedTrack. - */ - MuonCandidate(const Trk::Track& msTrack, std::unique_ptr<Trk::Track> extrapolatedTrack); - + /** constructor taking an ElementLink to a xAOD::TrackParicle& Users should ensure that the element link is valid and the lifetime of the Track object is longer that the MuonCandidate as it internally caches a pointer to it. */ MuonCandidate(const ElementLink<xAOD::TrackParticleContainer>& msTrackLink); - /** constructor taking an ElementLink to a xAOD::TrackParicle& - Users should ensure that the element link is valid and the lifetime of the Track object is longer that the MuonCandidate - as it internally caches a pointer to it. Class takes ownership of the extrapolatedTrack. - */ - MuonCandidate(const ElementLink<xAOD::TrackParticleContainer>& msTrackLink, std::unique_ptr<Trk::Track> extrapolatedTrack); - - /*Constructor taking two ElementLinks, should be the new default (second may be empty)*/ - MuonCandidate(const ElementLink<xAOD::TrackParticleContainer>& msTrackLink, const ElementLink<TrackCollection>& saTrackLink); + /*Constructor taking two ElementLinks, and the index location of the extrapolated track in the container*/ + MuonCandidate(const ElementLink<xAOD::TrackParticleContainer>& msTrackLink, const ElementLink<TrackCollection>& saTrackLink, + size_t container_idx); /** destructor */ ~MuonCandidate(); @@ -57,20 +41,17 @@ namespace MuonCombined { /** access spectrometer track, always there */ const ElementLink<xAOD::TrackParticleContainer>& muonSpectrometerTrackLink() const; - /** add extrapolated track to the MuonCandidate, takes ownership of the track and delete the current one if present */ - void updateExtrapolatedTrack(std::unique_ptr<Trk::Track> extrapolatedTrack); - /** access extrapolated track, can be zero if back extrapolation failed */ const Trk::Track* extrapolatedTrack() const; - /** Returns the extrapolated track otherwise the muonSpectrometer - */ + + /** Returns the extrapolated track otherwise the muonSpectrometer */ const Trk::Track* primaryTrack() const; - /** access extrapolated track, can be zero if back extrapolation failed */ - std::unique_ptr<Trk::Track> releaseExtrapolatedTrack(); - /** access extrapolated track element link*/ const ElementLink<TrackCollection>& extrapolatedTrackLink() const; + /** returns the index of the container where the extrapolated track is located */ + size_t extrapolatedElementID() const; + /** print candidate to string */ std::string toString() const; @@ -87,22 +68,22 @@ namespace MuonCombined { private: /** element link to spectrometer track */ - const ElementLink<xAOD::TrackParticleContainer> m_muonSpectrometerTrackLink; + const ElementLink<xAOD::TrackParticleContainer> m_muonSpectrometerTrackLink{}; /** element link to extrapolated track */ - const ElementLink<TrackCollection> m_extrapolatedTrackLink; - - /** pointer to extrapolated track, may be owned */ - std::unique_ptr<Trk::Track> m_extrapolatedTrack{nullptr}; + const ElementLink<TrackCollection> m_extrapolatedTrackLink{}; /** pointer to spectrometer track, not owned */ - const Trk::Track* m_muonSpectrometerTrack; + const Trk::Track* m_muonSpectrometerTrack{nullptr}; /** flag whether the track belongs to the comissioning stream **/ bool m_isComissioning{false}; /** Segments associated with the candidate **/ std::vector<ElementLink<xAOD::MuonSegmentContainer>> m_assoc_segments; + + /// Index of the MSOE track in the output container + size_t m_extContIdx{0}; }; } // namespace MuonCombined diff --git a/Reconstruction/MuonIdentification/MuonCombinedEvent/src/MuonCandidate.cxx b/Reconstruction/MuonIdentification/MuonCombinedEvent/src/MuonCandidate.cxx index 50abb08bf2ac2c8b44b1905749282d06cedc4d5b..db1c9e8270748875756d93d313c7fe8537ef3eb1 100644 --- a/Reconstruction/MuonIdentification/MuonCombinedEvent/src/MuonCandidate.cxx +++ b/Reconstruction/MuonIdentification/MuonCombinedEvent/src/MuonCandidate.cxx @@ -9,22 +9,16 @@ namespace MuonCombined { - MuonCandidate::MuonCandidate(const Trk::Track& msTrack) : m_muonSpectrometerTrack(&msTrack) {} - - MuonCandidate::MuonCandidate(const Trk::Track& msTrack, std::unique_ptr<Trk::Track> extrapolatedTrack) : - m_extrapolatedTrack(std::move(extrapolatedTrack)), m_muonSpectrometerTrack(&msTrack) {} - - MuonCandidate::MuonCandidate(const ElementLink<xAOD::TrackParticleContainer>& trackLink, - std::unique_ptr<Trk::Track> extrapolatedTrack) : - m_muonSpectrometerTrackLink(trackLink), - m_extrapolatedTrack(std::move(extrapolatedTrack)), - m_muonSpectrometerTrack((*m_muonSpectrometerTrackLink)->track()) {} - + MuonCandidate::MuonCandidate(const ElementLink<xAOD::TrackParticleContainer>& trackLink) : + m_muonSpectrometerTrackLink(trackLink), + m_muonSpectrometerTrack((*m_muonSpectrometerTrackLink)->track()){} MuonCandidate::MuonCandidate(const ElementLink<xAOD::TrackParticleContainer>& trackLink, - const ElementLink<TrackCollection>& saTrackLink) : + const ElementLink<TrackCollection>& saTrackLink, + size_t container_idx) : m_muonSpectrometerTrackLink(trackLink), m_extrapolatedTrackLink(saTrackLink), - m_muonSpectrometerTrack((*m_muonSpectrometerTrackLink)->track()) {} + m_muonSpectrometerTrack((*m_muonSpectrometerTrackLink)->track()), + m_extContIdx(container_idx) {} MuonCandidate::~MuonCandidate() = default; @@ -36,7 +30,7 @@ namespace MuonCombined { sout << " Track has no perigee parameters!"; else sout << " pt " << perigee->momentum().perp() << " eta " << perigee->momentum().eta() << " phi " << perigee->momentum().phi(); - sout << " hasExtrapolatedTrack " << (m_extrapolatedTrack ? "yes" : "no") << std::endl; + sout << " hasExtrapolatedTrack " << (extrapolatedTrack() ? "yes" : "no") << std::endl; return sout.str(); } @@ -45,13 +39,7 @@ namespace MuonCombined { const ElementLink<xAOD::TrackParticleContainer>& MuonCandidate::muonSpectrometerTrackLink() const { return m_muonSpectrometerTrackLink; } - - void MuonCandidate::updateExtrapolatedTrack(std::unique_ptr<Trk::Track> extrapolatedTrack) { - m_extrapolatedTrack = std::move(extrapolatedTrack); - } - const Trk::Track* MuonCandidate::extrapolatedTrack() const { - if (m_extrapolatedTrack) return m_extrapolatedTrack.get(); return m_extrapolatedTrackLink.isValid() ? *m_extrapolatedTrackLink : nullptr; } const Trk::Track* MuonCandidate::primaryTrack() const { @@ -59,10 +47,8 @@ namespace MuonCombined { return ext_trk ? ext_trk : &muonSpectrometerTrack(); } - std::unique_ptr<Trk::Track> MuonCandidate::releaseExtrapolatedTrack() { return std::move(m_extrapolatedTrack); } - const ElementLink<TrackCollection>& MuonCandidate::extrapolatedTrackLink() const { return m_extrapolatedTrackLink; } - + size_t MuonCandidate::extrapolatedElementID() const {return m_extrapolatedTrackLink.isValid() ? m_extContIdx : -1;} void MuonCandidate::setComissioning(bool b) { m_isComissioning = b; } bool MuonCandidate::isComissioning() const { return m_isComissioning; } diff --git a/Trigger/TrigSteer/ViewAlgs/src/EventViewCreatorAlgorithm.cxx b/Trigger/TrigSteer/ViewAlgs/src/EventViewCreatorAlgorithm.cxx index eace07e4063db576901cb7c5dc677fbae720654b..014f6600af5aae631291f63d09b3ff432e946274 100644 --- a/Trigger/TrigSteer/ViewAlgs/src/EventViewCreatorAlgorithm.cxx +++ b/Trigger/TrigSteer/ViewAlgs/src/EventViewCreatorAlgorithm.cxx @@ -264,7 +264,7 @@ StatusCode EventViewCreatorAlgorithm::placeMuonInView( const xAOD::Muon* theObje muonCandidate->clear( SG::VIEW_ELEMENTS ); auto msLink = theObject->muonSpectrometerTrackParticleLink(); auto extTrackLink = theObject->extrapolatedMuonSpectrometerTrackParticleLink(); - if(msLink.isValid() && extTrackLink.isValid()) muonCandidate->push_back( new MuonCombined::MuonCandidate(msLink, (*extTrackLink)->trackLink()) ); + if(msLink.isValid() && extTrackLink.isValid()) muonCandidate->push_back( new MuonCombined::MuonCandidate(msLink, (*extTrackLink)->trackLink(), (*extTrackLink)->index()) ); //store both in the view auto handleMuon = SG::makeHandle( m_inViewMuons,context );