ATLAS Offline Software
Loading...
Searching...
No Matches
MuonTPExtrapolationAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 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{
23MuonTPExtrapolationAlg::MuonTPExtrapolationAlg(const std::string& name, ISvcLocator* pSvcLocator) :
24 AthReentrantAlgorithm(name, pSvcLocator) {}
25
27 ATH_CHECK(m_extrapolator.retrieve());
28 ATH_CHECK(m_partKey.initialize());
29
30 for (const std::string& selDecor : m_trkSelDecors) {
31 m_trkSelKeys.emplace_back(m_partKey, selDecor);
32 }
33 ATH_CHECK(m_trkSelKeys.initialize());
34 ATH_CHECK(m_extEtaKey.initialize());
35 ATH_CHECK(m_extPhiKey.initialize());
36 ATH_CHECK(m_extStatKey.initialize());
37 return StatusCode::SUCCESS;
38}
39
40StatusCode MuonTPExtrapolationAlg::execute(const EventContext& ctx) const {
42 if (!muons.isValid()) {
43 ATH_MSG_FATAL("Failed to retrieve " << m_partKey.fullKey());
44 return StatusCode::FAILURE;
45 }
46
47 auto dec_Eta = makeHandle<float>(ctx, m_extEtaKey, dummy_result);
48 auto dec_Phi = makeHandle<float>(ctx, m_extPhiKey, dummy_result);
49 auto dec_Decorated = makeHandle<char>(ctx, m_extStatKey, ExtStatus::NotPresent);
50
52
53 std::vector<SelDecorator> selDecors;
55 selDecors.emplace_back(key, ctx);
56 }
57
58 for (const xAOD::IParticle* muon : *muons) {
60 const xAOD::TrackParticle* track{nullptr};
61 if (muon->type() == xAOD::Type::ObjectType::TruthParticle) {
62 ATH_MSG_FATAL("Truth is not supported");
63 return StatusCode::FAILURE;
64 } else if (muon->type() == xAOD::Type::ObjectType::TrackParticle) {
65 track = static_cast<const xAOD::TrackParticle*>(muon);
66 } else if (muon->type() == xAOD::Type::ObjectType::Muon) {
67 const xAOD::Muon* probeMuon = static_cast<const xAOD::Muon*>(muon);
68 track = probeMuon->trackParticle(xAOD::Muon::MuonSpectrometerTrackParticle);
69 if (!track) { track = probeMuon->primaryTrackParticle(); }
70 }
71 bool passSelection = muon->pt() > m_ptMin && (selDecors.empty () ||
72 std::find_if(selDecors.begin(),selDecors.end(),
73 [&muon](const SelDecorator& dec){
74 return dec(*muon);
75 }) != selDecors.end());
76 std::unique_ptr<Trk::TrackParameters> pTag = passSelection && track ? extrapolateToTriggerPivotPlane(ctx, *track) : nullptr;
77 int extr_code = ExtStatus::NotPresent;
78 float eta{dummy_result}, phi{dummy_result};
79 if (!pTag) {
80 // complain only if the particle has sufficient pt to actually make it to the MS...
81 if (passSelection && muon->pt() > min_warn_pt)
82 ATH_MSG_WARNING("Warning - Pivot plane extrapolation failed for a track particle with IP pt "
83 << muon->pt() << ", eta " << muon->eta() << ", phi " << muon->phi());
84 extr_code = ExtStatus::Failed;
85 } else {
86 eta = pTag->position().eta();
87 phi = pTag->position().phi();
88 extr_code = ExtStatus::Success;
89 }
90 dec_Eta(*muon) = eta;
91 dec_Phi(*muon) = phi;
92 dec_Decorated(*muon) = extr_code;
93 }
94 return StatusCode::SUCCESS;
95}
96
97std::unique_ptr<Trk::TrackParameters> MuonTPExtrapolationAlg::extrapolateToTriggerPivotPlane(const EventContext& ctx,
98 const xAOD::TrackParticle& track) const {
99 // BARREL
100 const Trk::Perigee& perigee = track.perigeeParameters();
101
102 // create the barrel as a cylinder surface centered at 0,0,0
103 Amg::Transform3D matrix = Amg::Transform3D(Amg::RotationMatrix3D::Identity(), Amg::Vector3D::Zero());
104
105 std::unique_ptr<Trk::CylinderSurface> cylinder =
106 std::make_unique<Trk::CylinderSurface>(matrix, m_barrelPivotPlaneRadius, m_barrelPivotPlaneHalfLength);
107
108 // and then attempt to extrapolate our track to this surface, checking for the boundaries of the barrel
109 bool boundaryCheck = true;
110
111 std::unique_ptr<Trk::TrackParameters> p{
112 m_extrapolator->extrapolate(ctx, perigee, *cylinder, Trk::alongMomentum, boundaryCheck, Trk::muon)};
113
114 // if the extrapolation worked out (so we are in the barrel) we are done and can return the
115 // track parameters at this surface.
116 if (p) return p;
117
118 // if we get here, the muon did not cross the barrel surface
119 // so we assume it is going into the endcap.
120 // ENDCAP
121
122 // After 2 years of using this code, we realised that ATLAS actually has endcaps on both sides ;-)
123 // So better make sure we place our endcap at the correct side of the detector!
124 // Hopefully no-one will ever read this comment...
125 const int SignOfEta = track.eta() > 0 ? 1. : -1.;
126 // much better!
127 matrix = Amg::Transform3D(Amg::RotationMatrix3D::Identity(), SignOfEta * m_endcapPivotPlaneZ * Amg::Vector3D::UnitZ());
128 std::unique_ptr<Trk::DiscSurface> disc = std::make_unique<Trk::DiscSurface>(matrix, m_endcapPivotPlaneMinimumRadius,
130
131 boundaryCheck = false;
132 return m_extrapolator->extrapolate(ctx, perigee, *disc, Trk::alongMomentum, boundaryCheck, Trk::muon);
133}
134
135}
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)
An algorithm that can be simultaneously executed in multiple threads.
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.
MuonTPExtrapolationAlg(const std::string &name, ISvcLocator *pSvcLocator)
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.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Class providing the definition of the 4-vector interface.
const TrackParticle * primaryTrackParticle() const
Returns a pointer (which should not usually be NULL, but might be if the muon has been stripped of in...
Definition Muon_v1.cxx:396
const TrackParticle * trackParticle(TrackParticleType type) const
Returns a pointer (which can be NULL) to the TrackParticle used in identification of this muon.
Definition Muon_v1.cxx:482
Eigen::Affine3d Transform3D
THE reconstruction tool.
SG::WriteDecorHandle< ContType, dType > makeHandle(const EventContext &ctx, const SG::WriteDecorHandleKey< ContType > &key, const dType &defValue=dType{})
@ 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: