11#include "Acts/Utilities/VectorHelpers.hpp"
15 constexpr Acts::HashedString caloExitParKey = Acts::hashString(
"@CaloExit");
30 return StatusCode::SUCCESS;
38 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Attempt to fetch the energy loss from "
44 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Measured E-loss: "<<eLoss);
52 const Acts::BoundTrackParameters idPerigeePars = idActsTrk->createParametersAtReference();
54 eLoss = idPerigeePars.absoluteMomentum() - caloExitPars->absoluteMomentum();
57 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Track has experienced "<<eLoss<<
" [GeV] energy loss. "
58 <<(idPerigeePars.absoluteMomentum() -
61 ATH_MSG_WARNING(__func__<<
"() "<<__LINE__<<
" - ID track has negative E-loss "<<eLoss<<
" [GeV]");
66 TrackCont_t stacoTracks{};
67 StacoCont_t stacoTags{};
75 auto caloExitPars = idTag->extrapolatedParsID(caloExitParKey);
77 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Track has no calo exit pars");
80 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Calorimeter exit parameters: "<<(*caloExitPars));
88 const Acts::BoundTrackParameters msPerigeePars = msTrk->createParametersAtReference();
91 if (std::abs(Acts::VectorHelpers::eta(msPerigeePars) -
92 Acts::VectorHelpers::eta(*caloExitPars)) >
m_match_dEta ||
96 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Ms track "<<msPerigeePars<<
", rel:"<<
97 std::sqrt((*msPerigeePars.covariance())(Acts::eBoundQOverP, Acts::eBoundQOverP)) /
98 msPerigeePars.qOverP());
100 const double msQoverP = std::copysign(1./(msPerigeePars.absoluteMomentum() + eLoss), msPerigeePars.qOverP());
101 const double msCov = 1./(*msPerigeePars.covariance())(Acts::eBoundQOverP, Acts::eBoundQOverP);
102 const double idCov = 1./(*caloExitPars->covariance())(Acts::eBoundQOverP, Acts::eBoundQOverP);
103 const double combCov = msCov + idCov;
104 const double combinedQoverP = (caloExitPars->qOverP()*idCov + msQoverP * msCov) / combCov;
105 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - ID momentum: "<<caloExitPars->absoluteMomentum()
106 <<
"("<<(idCov/combCov)<<
"), MS momentum: "<< msPerigeePars.absoluteMomentum()<<
", E-loss: "<<eLoss<<
" --> "
107 <<
" MS momentum + ELoss: "<<std::abs(1./msQoverP)<<
"("<< (msCov / combCov)<<
") ---> Combined Momentum: "
108 <<std::abs(1./combinedQoverP));
109 auto combinedTrk = stacoTracks->push_back(std::make_unique<xAOD::TrackParticle>());
110 combinedTrk->setDefiningParameters(idTrk->
d0(), idTrk->
z0(), idTrk->
phi0(),
111 idTrk->
theta(), combinedQoverP / Gaudi::Units::GeV);
113 auto stacoTag = stacoTags->push_back(std::make_unique<MuonR4::MuonTag>());
114 stacoTag->setAuthor(xAOD::Muon::Author::STACO);
115 stacoTag->setIdTrack(idTrk);
116 stacoTag->setCbTrack(combinedTrk);
117 stacoTag->setMsTrack(saTag);
118 stacoTag->setSegments(msTrk->component<std::vector<const xAOD::MuonSegment*>>(
"muonSegLinks"));
125 return StatusCode::SUCCESS;
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
The CaloExtension holds the ID extrapolation states through the calorimeter and the associated CaloCl...
const ClusterVec_t & associatedClusters() const
Returns the view on the asociated clusters.
ActsTrk::ContextUtility m_ctxProvider
Context provider for geometry, magnetic field and calibration contexts.
Gaudi::Property< float > m_match_dPhi
Upper cut on the delat phi between ID and MS track.
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_msTrackKey
Input key to the reconstructed MS track particles.
SG::WriteHandleKey< MuonR4::MuonTagContainer > m_stacoKey
Write key of the created STACO tags.
Gaudi::Property< float > m_match_dEta
Upper cut on the delta eta between ID and MS track.
Gaudi::Property< bool > m_useMeasELoss
Switch toggling whether the energy loss from the associated calorimeter cluster shall be taken.
double calcELoss(const MuonR4::MuonTag &idTag) const
Calculate the energy loss that is added to the MS momentum.
virtual StatusCode initialize() override final
SG::WriteHandleKey< xAOD::TrackParticleContainer > m_cmbTrkKey
Write key of the associated combined track particle container.
SG::ReadHandleKey< MuonR4::MuonTagContainer > m_idTrkKey
Input key to the selected ID / ITk track particles.
Baseline EDM object to gather all relevant information about a reconstructed muon candidate which can...
std::optional< Acts::BoundTrackParameters > extrapolatedParsID(const Acts::HashedString &parName) const
Returns the cached extrapolated ID track parameters.
const xAOD::TrackParticle * idTrack() const
Returns the id track candidate from which the tag was built.
float z0() const
Returns the parameter.
float theta() const
Returns the parameter, which has range 0 to .
float d0() const
Returns the parameter.
float phi0() const
Returns the parameter, which has range to .
const CaloExtension * getCaloExtension(const xAOD::TrackParticle &track)
Retrieve a pointer to the CaloExtension linked with the passed TrackParticle.
std::optional< Acts::BoundTrackParameters > lastTrackParameters(const xAOD::TrackParticle &trkPart, const bool skipOutlier=true)
Returns the last MeasurementState in form of Acts::BoundTrackParameters.
std::optional< ActsTrk::TrackContainer::ConstTrackProxy > getActsTrack(const xAOD::TrackParticle &trkPart)
Return the proxy to the Acts track from which the track particle was made frome.
DataVector< MuonTag > MuonTagContainer
P4Helpers provides static helper functions for kinematic calculation on objects deriving from I4Momen...
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
CaloCluster_v1 CaloCluster
Define the latest version of the calorimeter cluster class.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
TrackParticleAuxContainer_v5 TrackParticleAuxContainer
Definition of the current TrackParticle auxiliary container.