ATLAS Offline Software
Loading...
Searching...
No Matches
CombinedStacoAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#include "CombinedStacoAlg.h"
5
8
11#include "Acts/Utilities/VectorHelpers.hpp"
13
14namespace {
15 constexpr Acts::HashedString caloExitParKey = Acts::hashString("@CaloExit");
16
18
21}
22
23namespace MuonCombinedR4 {
25 ATH_CHECK(m_msTrackKey.initialize());
26 ATH_CHECK(m_idTrkKey.initialize());
27 ATH_CHECK(m_stacoKey.initialize());
28 ATH_CHECK(m_cmbTrkKey.initialize());
29 ATH_CHECK(m_ctxProvider.initialize());
30 return StatusCode::SUCCESS;
31 }
32
33 double CombinedStacoAlg::calcELoss(const MuonR4::MuonTag& idTag) const {
34 const xAOD::TrackParticle* idTrk = idTag.idTrack();
36 double eLoss{0.};
37 if (m_useMeasELoss && caloExt) {
38 ATH_MSG_VERBOSE(__func__<<"() "<<__LINE__<<" - Attempt to fetch the energy loss from "
39 <<caloExt->associatedClusters().size()<<" associated clusters. ");
40 for (const xAOD::CaloCluster* clust : caloExt->associatedClusters()) {
41 eLoss += clust->e();
42 }
43 if (!caloExt->associatedClusters().empty()) {
44 ATH_MSG_DEBUG(__func__<<"() "<<__LINE__<<" - Measured E-loss: "<<eLoss);
45 return eLoss;
46 }
47 }
48
49 auto idActsTrk = ActsTrk::getActsTrack(*idTrk);
50 auto caloExitPars = idTag.extrapolatedParsID(caloExitParKey);
51
52 const Acts::BoundTrackParameters idPerigeePars = idActsTrk->createParametersAtReference();
54 eLoss = idPerigeePars.absoluteMomentum() - caloExitPars->absoluteMomentum();
55
56
57 ATH_MSG_VERBOSE(__func__<<"() "<<__LINE__<<" - Track has experienced "<<eLoss<<" [GeV] energy loss. "
58 <<(idPerigeePars.absoluteMomentum() -
59 ActsTrk::lastTrackParameters(*idTrk)->absoluteMomentum())<<" [GeV] were lost in the calorimeter");
60 if(eLoss< 0) {
61 ATH_MSG_WARNING(__func__<<"() "<<__LINE__<<" - ID track has negative E-loss "<<eLoss<<" [GeV]");
62 }
63 return eLoss;
64 }
65 StatusCode CombinedStacoAlg::execute(const EventContext& ctx) const {
66 TrackCont_t stacoTracks{};
67 StacoCont_t stacoTags{};
68
69 const MuonR4::MuonTagContainer* idTracks{nullptr};
70 const xAOD::TrackParticleContainer *msTracks{nullptr};
71 ATH_CHECK(SG::get(idTracks, m_idTrkKey, ctx));
72 ATH_CHECK(SG::get(msTracks, m_msTrackKey, ctx));
73
74 for (const MuonR4::MuonTag* idTag : *idTracks) {
75 auto caloExitPars = idTag->extrapolatedParsID(caloExitParKey);
76 if (!caloExitPars) {
77 ATH_MSG_VERBOSE(__func__<<"() "<<__LINE__<<" - Track has no calo exit pars");
78 continue;
79 }
80 ATH_MSG_DEBUG(__func__<<"() "<<__LINE__<<" - Calorimeter exit parameters: "<<(*caloExitPars));
81 const double eLoss = calcELoss(*idTag);
82
83 const xAOD::TrackParticle* idTrk = idTag->idTrack();
84
86 for (const xAOD::TrackParticle* saTag : *msTracks) {
87 const auto msTrk = ActsTrk::getActsTrack(*saTag);
88 const Acts::BoundTrackParameters msPerigeePars = msTrk->createParametersAtReference();
90 using namespace P4Helpers;
91 if (std::abs(Acts::VectorHelpers::eta(msPerigeePars) -
92 Acts::VectorHelpers::eta(*caloExitPars)) > m_match_dEta ||
93 std::abs(deltaPhi(msPerigeePars.phi(), caloExitPars->phi())) > m_match_dPhi) {
94 continue;
95 }
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);
112
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"));
119 }
120 }
121
122 ATH_CHECK(stacoTags.record(m_stacoKey, ctx));
123 ATH_CHECK(stacoTracks.record(m_cmbTrkKey, ctx));
124
125 return StatusCode::SUCCESS;
126 }
127}
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)
#define ATH_MSG_DEBUG(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...
Definition MuonTag.h:25
std::optional< Acts::BoundTrackParameters > extrapolatedParsID(const Acts::HashedString &parName) const
Returns the cached extrapolated ID track parameters.
Definition MuonTag.cxx:76
const xAOD::TrackParticle * idTrack() const
Returns the id track candidate from which the tag was built.
Definition MuonTag.cxx:17
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.
Definition Decoration.cxx:9
DataVector< MuonTag > MuonTagContainer
Definition MuonTag.h:125
P4Helpers provides static helper functions for kinematic calculation on objects deriving from I4Momen...
Definition P4Helpers.h:32
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.