ATLAS Offline Software
PhysicsAnalysis
DerivationFramework
DerivationFrameworkBPhys
src
MuonExtrapolationTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
// MuonExtrapolationTool.cxx
5
#include "
MuonExtrapolationTool.h
"
6
#include "
xAODTruth/TruthParticleContainer.h
"
7
#include "
xAODEventInfo/EventInfo.h
"
8
#include "
TrkSurfaces/DiscSurface.h
"
9
#include "
TrkSurfaces/CylinderSurface.h
"
10
#include "TVector2.h"
11
#include <memory>
12
13
//**********************************************************************
14
15
namespace
DerivationFramework
{
16
17
MuonExtrapolationTool::MuonExtrapolationTool
(
const
std::string &
t
,
const
std::string&
n
,
const
IInterface*
p
)
18
:
19
base_class(
t
,
n
,
p
)
20
{
21
}
22
23
//**********************************************************************
24
25
26
StatusCode
MuonExtrapolationTool::initialize
()
27
{
28
ATH_CHECK
(
m_muonContainerName
.
initialize
());
29
ATH_CHECK
(
m_extrapolator
.retrieve());
30
return
StatusCode::SUCCESS;
31
}
32
33
34
//**********************************************************************
35
36
bool
MuonExtrapolationTool::extrapolateAndDecorateTrackParticle
(
const
xAOD::TrackParticle
*
particle
,
float
&
eta
,
float
&
phi
,
const
EventContext& ctx)
const
37
{
38
39
// decorators used to access or store the information
40
static
const
SG::AuxElement::Decorator< char >
Decorated (
"DecoratedPivotEtaPhi"
);
41
static
const
SG::AuxElement::Decorator< float >
Eta
(
"EtaTriggerPivot"
);
42
static
const
SG::AuxElement::Decorator< float >
Phi
(
"PhiTriggerPivot"
);
43
44
if
(! Decorated.
isAvailable
(*
particle
) || !Decorated(*
particle
)){
45
// in the athena release, we can run the extrapolation if needed
46
const
Trk::TrackParameters
*
pTag
=
extrapolateToTriggerPivotPlane
(*
particle
, ctx);
47
if
(!
pTag
) {
48
Decorated(*
particle
) =
false
;
49
return
false
;
50
}
51
Eta
(*
particle
) =
pTag
->position().eta();
52
Phi
(*
particle
) =
pTag
->position().phi();
53
Decorated(*
particle
) =
true
;
54
delete
pTag
;
55
}
56
// if we get here, the decoration was either already present or just added by us
57
// so we can finally read the values
58
eta
=
Eta
(*
particle
);
59
phi
=
Phi
(*
particle
);
60
return
true
;
61
}
62
63
//**********************************************************************
64
65
const
xAOD::TrackParticle
*
MuonExtrapolationTool::getPreferredTrackParticle
(
const
xAOD::IParticle
*
muon
)
const
66
{
67
if
(
dynamic_cast<
const
xAOD::TruthParticle
*
>
(
muon
)){
68
ATH_MSG_WARNING
(
"Pivot plane extrapolation not supported for Truth muons!"
);
69
return
0;
70
}
71
const
xAOD::TrackParticle
* muonTrack =
dynamic_cast<
const
xAOD::TrackParticle
*
>
(
muon
);
72
if
(!muonTrack &&
dynamic_cast<
const
xAOD::Muon
*
>
(
muon
)) {
73
const
xAOD::Muon
* theMuon =
dynamic_cast<
const
xAOD::Muon
*
>
(
muon
);
74
muonTrack = theMuon->
trackParticle
( xAOD::Muon::MuonSpectrometerTrackParticle );
75
if
(!muonTrack) {
76
muonTrack = theMuon->
primaryTrackParticle
();
77
if
(!muonTrack) {
78
muonTrack = theMuon->
trackParticle
( xAOD::Muon::InnerDetectorTrackParticle );
79
}
80
}
81
}
82
if
(!muonTrack){
83
ATH_MSG_WARNING
(
"no valid track found for extrapolating the muon to the pivot plane!"
);
84
}
85
return
muonTrack;
86
87
}
88
89
StatusCode
MuonExtrapolationTool::addBranches
(
const
EventContext& ctx)
const
90
{
91
SG::ReadHandle<xAOD::MuonContainer>
muonContainer
{
m_muonContainerName
, ctx};
92
if
(!
muonContainer
.isValid()) {
93
ATH_MSG_ERROR
(
"Failed to retrieve MuonContainer with name: "
<<
m_muonContainerName
.
key
());
94
return
StatusCode::FAILURE;
95
}
96
for
(
auto
muon
: *
muonContainer
) {
97
const
xAOD::TrackParticle
*
track
=
getPreferredTrackParticle
(
muon
);
98
float
eta
,
phi
= 0;
99
if
( !
extrapolateAndDecorateTrackParticle
(
track
,
eta
,
phi
, ctx )){
100
if
(
muon
->pt() > 3500.){
101
//only complain if the muon has sufficient pT to actually reach the pivot plane
102
//extrapolation will often fail for muons with pT < 3500 MeV
103
ATH_MSG_WARNING
(
"Failed to extrapolate+decorate muon with pivot plane coords - Muon params: pt "
<<
muon
->pt()<<
", eta "
<<
muon
->eta()<<
", phi "
<<
muon
->phi());
104
}
105
}
106
}
107
return
StatusCode::SUCCESS;
108
}
109
110
const
Trk::TrackParameters
*
MuonExtrapolationTool::extrapolateToTriggerPivotPlane
(
const
xAOD::TrackParticle
&
track
,
const
EventContext& ctx)
const
111
{
112
// BARREL
113
const
Trk::Perigee
& perigee =
track
.perigeeParameters();
114
115
// create the barrel as a cylinder surface centered at 0,0,0
116
Amg::Vector3D
barrelCentre(0., 0., 0.);
117
Amg::Transform3D
matrix
=
Amg::Transform3D
(Amg::RotationMatrix3D::Identity(), barrelCentre);
118
119
Trk::CylinderSurface
* cylinder =
120
new
Trk::CylinderSurface
(
matrix
,
121
m_barrelPivotPlaneRadius
,
122
m_barrelPivotPlaneHalfLength
);
123
if
(!cylinder) {
124
ATH_MSG_WARNING
(
"extrapolateToTriggerPivotPlane :: new Trk::CylinderSurface failed."
);
125
return
nullptr
;
126
}
127
// and then attempt to extrapolate our track to this surface, checking for the boundaries of the barrel
128
bool
boundaryCheck =
true
;
129
const
Trk::Surface
* surface = cylinder;
130
const
Trk::TrackParameters
*
p
=
m_extrapolator
->extrapolate(
131
ctx, perigee, *surface,
Trk::alongMomentum
, boundaryCheck,
Trk::muon
).release();
132
delete
cylinder;
133
// if the extrapolation worked out (so we are in the barrel) we are done and can return the
134
// track parameters at this surface.
135
if
(
p
)
return
p
;
136
137
// if we get here, the muon did not cross the barrel surface
138
// so we assume it is going into the endcap.
139
// ENDCAP
140
141
// After 2 years of using this code, we realised that ATLAS actually has endcaps on both sides ;-)
142
// So better make sure we place our endcap at the correct side of the detector!
143
// Hopefully no-one will ever read this comment...
144
float
SignOfEta =
track
.eta() > 0 ? 1. : -1.;
145
146
Amg::Vector3D
endcapCentre(0., 0.,
m_endcapPivotPlaneZ
);
147
// much better!
148
matrix
=
Amg::Transform3D
(Amg::RotationMatrix3D::Identity(), SignOfEta * endcapCentre);
149
150
std::unique_ptr<Trk::DiscSurface> disc =
151
std::make_unique<Trk::DiscSurface>(
matrix
,
152
m_endcapPivotPlaneMinimumRadius
,
153
m_endcapPivotPlaneMaximumRadius
);
154
if
(!disc) {
155
ATH_MSG_WARNING
(
"extrapolateToTriggerPivotPlane :: new Trk::DiscSurface failed."
);
156
return
nullptr
;
157
}
158
159
// for the endcap, we turn off the boundary check, extending the EC infinitely to catch stuff heading for the transition region
160
boundaryCheck =
false
;
161
surface = disc.get();
162
p
=
m_extrapolator
->extrapolate(
163
ctx, perigee, *surface,
Trk::alongMomentum
, boundaryCheck,
Trk::muon
).release();
164
return
p
;
165
}
166
}
muonContainer
xAOD::MuonContainer * muonContainer
Definition:
TrigGlobEffCorrValidation.cxx:188
xAOD::muon
@ muon
Definition:
TrackingPrimitives.h:196
DerivationFramework::MuonExtrapolationTool::m_extrapolator
PublicToolHandle< Trk::IExtrapolator > m_extrapolator
Definition:
MuonExtrapolationTool.h:45
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition:
ParticleHypothesis.h:79
phi
Scalar phi() const
phi method
Definition:
AmgMatrixBasePlugin.h:67
xAOD::Muon_v1::trackParticle
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:487
eta
Scalar eta() const
pseudorapidity method
Definition:
AmgMatrixBasePlugin.h:83
SG::ReadHandle
Definition:
StoreGate/StoreGate/ReadHandle.h:67
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition:
EMErrorDetail.h:25
DerivationFramework::MuonExtrapolationTool::extrapolateToTriggerPivotPlane
const Trk::TrackParameters * extrapolateToTriggerPivotPlane(const xAOD::TrackParticle &track, const EventContext &ctx) const
run the extrapolation - only available in full athena
Definition:
MuonExtrapolationTool.cxx:110
TruthParticleContainer.h
Trk::alongMomentum
@ alongMomentum
Definition:
PropDirection.h:20
Phi
@ Phi
Definition:
RPCdef.h:8
read_hist_ntuple.t
t
Definition:
read_hist_ntuple.py:5
DerivationFramework::MuonExtrapolationTool::m_endcapPivotPlaneMinimumRadius
Gaudi::Property< double > m_endcapPivotPlaneMinimumRadius
Definition:
MuonExtrapolationTool.h:50
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition:
AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition:
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
DerivationFramework::MuonExtrapolationTool::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const
Definition:
MuonExtrapolationTool.cxx:89
xAOD::Muon_v1
Class describing a Muon.
Definition:
Muon_v1.h:38
DerivationFramework::MuonExtrapolationTool::initialize
virtual StatusCode initialize()
Definition:
MuonExtrapolationTool.cxx:26
DerivationFramework::MuonExtrapolationTool::m_barrelPivotPlaneRadius
Gaudi::Property< double > m_barrelPivotPlaneRadius
Definition:
MuonExtrapolationTool.h:52
python.utils.AtlRunQueryDQUtils.p
p
Definition:
AtlRunQueryDQUtils.py:209
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition:
AthMsgStreamMacros.h:33
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition:
Decorator.h:59
DerivationFramework::MuonExtrapolationTool::m_barrelPivotPlaneHalfLength
Gaudi::Property< double > m_barrelPivotPlaneHalfLength
Definition:
MuonExtrapolationTool.h:53
beamspotman.n
n
Definition:
beamspotman.py:727
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition:
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::CylinderSurface
Definition:
CylinderSurface.h:55
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition:
TruthParticle_v1.h:37
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition:
GeoPrimitives.h:46
CylinderSurface.h
ATH_CHECK
#define ATH_CHECK
Definition:
AthCheckMacros.h:40
Trk::ParametersBase
Definition:
ParametersBase.h:55
DerivationFramework
THE reconstruction tool.
Definition:
ParticleSortingAlg.h:24
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition:
AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
jobOptions.pTag
string pTag
Definition:
jobOptions.py:28
Trk::muon
@ muon
Definition:
ParticleHypothesis.h:31
MuonExtrapolationTool.h
DerivationFramework::MuonExtrapolationTool::MuonExtrapolationTool
MuonExtrapolationTool(const std::string &t, const std::string &n, const IInterface *p)
Definition:
MuonExtrapolationTool.cxx:17
DerivationFramework::MuonExtrapolationTool::getPreferredTrackParticle
const xAOD::TrackParticle * getPreferredTrackParticle(const xAOD::IParticle *probe) const
Definition:
MuonExtrapolationTool.cxx:65
DerivationFramework::MuonExtrapolationTool::m_endcapPivotPlaneMaximumRadius
Gaudi::Property< double > m_endcapPivotPlaneMaximumRadius
Definition:
MuonExtrapolationTool.h:51
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition:
GeoPrimitives.h:47
EventInfo.h
DerivationFramework::MuonExtrapolationTool::m_muonContainerName
SG::ReadHandleKey< xAOD::MuonContainer > m_muonContainerName
Definition:
MuonExtrapolationTool.h:44
python.testIfMatch.matrix
matrix
Definition:
testIfMatch.py:63
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition:
AthMsgStreamMacros.h:32
SG::Decorator::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
DiscSurface.h
xAOD::Muon_v1::primaryTrackParticle
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:401
xAOD::track
@ track
Definition:
TrackingPrimitives.h:513
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition:
TrackParticle_v1.h:44
Trk::Surface
Definition:
Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:79
Eta
@ Eta
Definition:
RPCdef.h:8
DerivationFramework::MuonExtrapolationTool::m_endcapPivotPlaneZ
Gaudi::Property< double > m_endcapPivotPlaneZ
Definition:
MuonExtrapolationTool.h:49
DerivationFramework::MuonExtrapolationTool::extrapolateAndDecorateTrackParticle
bool extrapolateAndDecorateTrackParticle(const xAOD::TrackParticle *particle, float &eta, float &phi, const EventContext &ctx) const
Definition:
MuonExtrapolationTool.cxx:36
Generated on Fri Oct 31 2025 21:15:18 for ATLAS Offline Software by
1.8.18