ATLAS Offline Software
Loading...
Searching...
No Matches
MuonTPExtrapolationAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
11namespace {
12 constexpr float min_warn_pt = 3500;
13 constexpr float dummy_result = 5.;
14
15 enum ExtStatus {
16 Success = 1,
17 Failed = 2,
18 NotPresent = 0,
19 };
20} // namespace
21
22namespace DerivationFramework{
23
25 ATH_CHECK(m_extrapolator.retrieve());
26 ATH_CHECK(m_partKey.initialize());
27
28 for (const std::string& selDecor : m_trkSelDecors) {
29 m_trkSelKeys.emplace_back(m_partKey, selDecor);
30 }
31 ATH_CHECK(m_trkSelKeys.initialize());
32 ATH_CHECK(m_extEtaKey.initialize());
33 ATH_CHECK(m_extPhiKey.initialize());
34 ATH_CHECK(m_extStatKey.initialize());
35 return StatusCode::SUCCESS;
36}
37
38StatusCode MuonTPExtrapolationAlg::execute(const EventContext& ctx) const {
39 const xAOD::IParticleContainer* muons{nullptr};
40 ATH_CHECK(SG::get(muons, m_partKey, ctx));
41
42
45 xAOD::ContainerDecorator<xAOD::IParticleContainer, char> dec_Decorated{m_extStatKey, ctx, ExtStatus::NotPresent};
46
48
49 std::vector<SelDecorator> selDecors;
51 selDecors.emplace_back(key, ctx);
52 }
53
54 for (const xAOD::IParticle* muon : *muons) {
56 const xAOD::TrackParticle* track{nullptr};
57 if (muon->type() == xAOD::Type::ObjectType::TruthParticle) {
58 ATH_MSG_FATAL("Truth is not supported");
59 return StatusCode::FAILURE;
60 } else if (muon->type() == xAOD::Type::ObjectType::TrackParticle) {
61 track = static_cast<const xAOD::TrackParticle*>(muon);
62 } else if (muon->type() == xAOD::Type::ObjectType::Muon) {
63 const xAOD::Muon* probeMuon = static_cast<const xAOD::Muon*>(muon);
64 track = probeMuon->trackParticle(xAOD::Muon::TrackParticleType::MuonSpectrometerTrackParticle);
65 if (!track) { track = probeMuon->trackParticle(xAOD::Muon::TrackParticleType::Primary); }
66 }
67 bool passSelection = muon->pt() > m_ptMin && (selDecors.empty () ||
68 std::find_if(selDecors.begin(),selDecors.end(),
69 [&muon](const SelDecorator& dec){
70 return dec(*muon);
71 }) != selDecors.end());
72 std::unique_ptr<Trk::TrackParameters> pTag = passSelection && track ? extrapolateToTriggerPivotPlane(ctx, *track) : nullptr;
73 int extr_code = ExtStatus::NotPresent;
74 float eta{dummy_result}, phi{dummy_result};
75 if (!pTag) {
76 // complain only if the particle has sufficient pt to actually make it to the MS...
77 if (passSelection && muon->pt() > min_warn_pt)
78 ATH_MSG_WARNING("Warning - Pivot plane extrapolation failed for a track particle with IP pt "
79 << muon->pt() << ", eta " << muon->eta() << ", phi " << muon->phi());
80 extr_code = ExtStatus::Failed;
81 } else {
82 eta = pTag->position().eta();
83 phi = pTag->position().phi();
84 extr_code = ExtStatus::Success;
85 }
86 dec_Eta(*muon) = eta;
87 dec_Phi(*muon) = phi;
88 dec_Decorated(*muon) = extr_code;
89 }
90 return StatusCode::SUCCESS;
91}
92
93std::unique_ptr<Trk::TrackParameters> MuonTPExtrapolationAlg::extrapolateToTriggerPivotPlane(const EventContext& ctx,
94 const xAOD::TrackParticle& track) const {
95 // BARREL
96 const Trk::Perigee& perigee = track.perigeeParameters();
97
98 // create the barrel as a cylinder surface centered at 0,0,0
99 Amg::Transform3D matrix = Amg::Transform3D(Amg::RotationMatrix3D::Identity(), Amg::Vector3D::Zero());
100
101 std::unique_ptr<Trk::CylinderSurface> cylinder =
102 std::make_unique<Trk::CylinderSurface>(matrix, m_barrelPivotPlaneRadius, m_barrelPivotPlaneHalfLength);
103
104 // and then attempt to extrapolate our track to this surface, checking for the boundaries of the barrel
105 bool boundaryCheck = true;
106
107 std::unique_ptr<Trk::TrackParameters> p{
108 m_extrapolator->extrapolate(ctx, perigee, *cylinder, Trk::alongMomentum, boundaryCheck, Trk::muon)};
109
110 // if the extrapolation worked out (so we are in the barrel) we are done and can return the
111 // track parameters at this surface.
112 if (p) return p;
113
114 // if we get here, the muon did not cross the barrel surface
115 // so we assume it is going into the endcap.
116 // ENDCAP
117
118 // After 2 years of using this code, we realised that ATLAS actually has endcaps on both sides ;-)
119 // So better make sure we place our endcap at the correct side of the detector!
120 // Hopefully no-one will ever read this comment...
121 const int SignOfEta = track.eta() > 0 ? 1. : -1.;
122 // much better!
123 matrix = Amg::Transform3D(Amg::RotationMatrix3D::Identity(), SignOfEta * m_endcapPivotPlaneZ * Amg::Vector3D::UnitZ());
124 std::unique_ptr<Trk::DiscSurface> disc = std::make_unique<Trk::DiscSurface>(matrix, m_endcapPivotPlaneMinimumRadius,
126
127 boundaryCheck = false;
128 return m_extrapolator->extrapolate(ctx, perigee, *disc, Trk::alongMomentum, boundaryCheck, Trk::muon);
129}
130
131}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
virtual StatusCode execute(const EventContext &ctx) const override
ToolHandle< Trk::IExtrapolator > m_extrapolator
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_extPhiKey
Gaudi::Property< std::vector< std::string > > m_trkSelDecors
Gaudi::Property< float > m_ptMin
Optional list of decorators to select only the good tracks for the isolation decoration.
SG::ReadHandleKey< xAOD::IParticleContainer > m_partKey
Particle container to decorate the Pivot plane coordinates to.
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_extEtaKey
SG::ReadDecorHandleKeyArray< xAOD::IParticleContainer > m_trkSelKeys
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_extStatKey
std::unique_ptr< Trk::TrackParameters > extrapolateToTriggerPivotPlane(const EventContext &ctx, const xAOD::TrackParticle &track) const
run the extrapolation - only available in full athena
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Handle class for reading a decoration on an object.
Auxiliary class to instantiate WriteDecorHandles.The handles can be created in an empty state.
Class providing the definition of the 4-vector interface.
const TrackParticle * trackParticle(TrackParticleType type) const
Returns a pointer (which can be a nullptr) to the TrackParticle used in identification of this muon.
Definition Muon_v1.cxx:422
Eigen::Affine3d Transform3D
THE reconstruction tool.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
@ alongMomentum
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ TrackParticle
The object is a charged track particle.
Definition ObjectType.h:43
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ TruthParticle
The object is a truth particle.
Definition ObjectType.h:67
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Muon_v1 Muon
Reference the current persistent version:
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.