11#include "Acts/Utilities/VectorHelpers.hpp"
16 constexpr Acts::HashedString caloExitParKey = Acts::hashString(
"@CaloExit");
32 return StatusCode::SUCCESS;
40 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Attempt to fetch the energy loss from "
46 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Measured E-loss: "<<eLoss);
54 const Acts::BoundTrackParameters idPerigeePars = idActsTrk->createParametersAtReference();
56 eLoss = idPerigeePars.absoluteMomentum() - caloExitPars->absoluteMomentum();
59 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Track has experienced "<<eLoss<<
" [GeV] energy loss. "
60 <<(idPerigeePars.absoluteMomentum() -
63 ATH_MSG_WARNING(__func__<<
"() "<<__LINE__<<
" - ID track has negative E-loss "<<eLoss<<
" [GeV]");
68 TrackCont_t stacoTracks{};
69 StacoCont_t stacoTags{};
76 const Acts::GeometryContext tgContext =
m_ctxProvider.getGeometryContext(ctx);
79 auto caloExitPars = idTag->extrapolatedParsID(caloExitParKey);
81 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
" - Track has no calo exit pars");
84 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Calorimeter exit parameters: "<<(*caloExitPars));
92 const Acts::BoundTrackParameters msPerigeePars = msTrk->createParametersAtReference();
93 const std::optional<Acts::BoundTrackParameters> matchPars =
makeDiffParameters(tgContext,
94 *caloExitPars, msPerigeePars,
logger(),
99 std::abs(matchPars->get<Acts::eBoundPhi>()) >
m_match_dPhi) {
102 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - Ms track "<<msPerigeePars<<
", rel:"<<
103 std::sqrt((*msPerigeePars.covariance())(Acts::eBoundQOverP, Acts::eBoundQOverP)) /
104 msPerigeePars.qOverP());
106 const double msQoverP = std::copysign(1./(msPerigeePars.absoluteMomentum() + eLoss), msPerigeePars.qOverP());
107 const double msCov = 1./(*msPerigeePars.covariance())(Acts::eBoundQOverP, Acts::eBoundQOverP);
108 const double idCov = 1./(*caloExitPars->covariance())(Acts::eBoundQOverP, Acts::eBoundQOverP);
109 const double combCov = msCov + idCov;
110 const double combinedQoverP = (caloExitPars->qOverP()*idCov + msQoverP * msCov) / combCov;
111 ATH_MSG_DEBUG(__func__<<
"() "<<__LINE__<<
" - ID momentum: "<<caloExitPars->absoluteMomentum()
112 <<
"("<<(idCov/combCov)<<
"), MS momentum: "<< msPerigeePars.absoluteMomentum()<<
", E-loss: "<<eLoss<<
" --> "
113 <<
" MS momentum + ELoss: "<<std::abs(1./msQoverP)<<
"("<< (msCov / combCov)<<
") ---> Combined Momentum: "
114 <<std::abs(1./combinedQoverP));
115 auto combinedTrk = stacoTracks->push_back(std::make_unique<xAOD::TrackParticle>());
116 combinedTrk->setDefiningParameters(idTrk->
d0(), idTrk->
z0(), idTrk->
phi0(),
117 idTrk->
theta(), combinedQoverP / Gaudi::Units::GeV);
119 Acts::BoundMatrix matchCov{Acts::BoundMatrix::Zero()};
120 if (matchPars->covariance()) {
121 matchCov = (*matchPars->covariance()).inverse();
123 const float matchQuality = matchPars->parameters().dot(matchCov * matchPars->parameters());
125 combinedTrk->setFitQuality(idTrk->
chiSquared() + saTag->chiSquared() + matchQuality,
126 idTrk->
numberDoF() + saTag->numberDoF());
127 auto stacoTag = stacoTags->push_back(std::make_unique<MuonR4::MuonTag>());
128 stacoTag->setParameter(MuonR4::MuonTag::ParamDef::msInnerMatchChi2, matchQuality);
129 stacoTag->setAuthor(xAOD::Muon::Author::STACO);
130 stacoTag->setIdTrack(idTrk);
131 stacoTag->setCbTrack(combinedTrk);
132 stacoTag->setMsTrack(saTag);
133 stacoTag->setSegments(msTrk->component<std::vector<const xAOD::MuonSegment*>>(
"muonSegLinks"));
140 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
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.
const Acts::Logger & logger() const
Return the reference to the Acts logger.
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
Gaudi::Property< float > m_match_dTheta
Upper cut on the delta eta between ID and MS track.
std::unique_ptr< const Acts::Logger > m_logger
Instance to the Acts logger.
SG::ReadHandleKey< xAOD::TrackParticleContainer > m_msTrackKey
Input key to the reconstructed MS track particles.
Gaudi::Property< float > m_match_boundTol
Upper cut on the boundary tolerance.
SG::WriteHandleKey< MuonR4::MuonTagContainer > m_stacoKey
Write key of the created STACO tags.
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 numberDoF() const
Returns the number of degrees of freedom of the overall track or vertex fit as float.
float d0() const
Returns the parameter.
float chiSquared() const
Returns the of the overall track fit.
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.
std::optional< Acts::BoundTrackParameters > makeDiffParameters(const Acts::GeometryContext &tgContext, const Acts::BoundTrackParameters &idParameters, const Acts::BoundTrackParameters &msParameters, const Acts::Logger &logger, const double boundTolerance=Acts::UnitConstants::km)
Calculates the difference parameters between the ID and the MS If the parameters are expressed on dif...
DataVector< MuonTag > MuonTagContainer
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.