ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
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::TrackParticleType::MuonSpectrometerTrackParticle );
75
if
(!muonTrack) {
76
muonTrack = theMuon->
trackParticle
(xAOD::Muon::TrackParticleType::Primary);
77
if
(!muonTrack) {
78
muonTrack = theMuon->
trackParticle
( xAOD::Muon::TrackParticleType::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
}
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
phi
Scalar phi() const
phi method
Definition
AmgMatrixBasePlugin.h:67
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
CylinderSurface.h
DiscSurface.h
TruthParticleContainer.h
MuonExtrapolationTool.h
Phi
@ Phi
Definition
RPCdef.h:8
Eta
@ Eta
Definition
RPCdef.h:8
muonContainer
xAOD::MuonContainer * muonContainer
Definition
TrigGlobEffCorrValidation.cxx:188
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::initialize
virtual StatusCode initialize()
Definition
MuonExtrapolationTool.cxx:26
DerivationFramework::MuonExtrapolationTool::m_endcapPivotPlaneMaximumRadius
Gaudi::Property< double > m_endcapPivotPlaneMaximumRadius
Definition
MuonExtrapolationTool.h:51
DerivationFramework::MuonExtrapolationTool::m_muonContainerName
SG::ReadHandleKey< xAOD::MuonContainer > m_muonContainerName
Definition
MuonExtrapolationTool.h:44
DerivationFramework::MuonExtrapolationTool::m_barrelPivotPlaneRadius
Gaudi::Property< double > m_barrelPivotPlaneRadius
Definition
MuonExtrapolationTool.h:52
DerivationFramework::MuonExtrapolationTool::m_endcapPivotPlaneMinimumRadius
Gaudi::Property< double > m_endcapPivotPlaneMinimumRadius
Definition
MuonExtrapolationTool.h:50
DerivationFramework::MuonExtrapolationTool::addBranches
virtual StatusCode addBranches(const EventContext &ctx) const
Definition
MuonExtrapolationTool.cxx:89
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
DerivationFramework::MuonExtrapolationTool::m_endcapPivotPlaneZ
Gaudi::Property< double > m_endcapPivotPlaneZ
Definition
MuonExtrapolationTool.h:49
DerivationFramework::MuonExtrapolationTool::m_barrelPivotPlaneHalfLength
Gaudi::Property< double > m_barrelPivotPlaneHalfLength
Definition
MuonExtrapolationTool.h:53
DerivationFramework::MuonExtrapolationTool::m_extrapolator
PublicToolHandle< Trk::IExtrapolator > m_extrapolator
Definition
MuonExtrapolationTool.h:45
DerivationFramework::MuonExtrapolationTool::extrapolateAndDecorateTrackParticle
bool extrapolateAndDecorateTrackParticle(const xAOD::TrackParticle *particle, float &eta, float &phi, const EventContext &ctx) const
Definition
MuonExtrapolationTool.cxx:36
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
Trk::CylinderSurface
Class for a CylinderSurface in the ATLAS detector.
Definition
CylinderSurface.h:55
Trk::Surface
Abstract Base Class for tracking surfaces.
Definition
Surface.h:79
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition
Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAOD::Muon_v1::trackParticle
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
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition
GeoPrimitives.h:46
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition
GeoPrimitives.h:47
DerivationFramework
THE reconstruction tool.
Definition
CascadeTools.h:16
Trk::alongMomentum
@ alongMomentum
Definition
PropDirection.h:20
Trk::Perigee
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
Definition
Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:33
Trk::muon
@ muon
Definition
ParticleHypothesis.h:31
Trk::TrackParameters
ParametersBase< TrackParametersDim, Charged > TrackParameters
Definition
Tracking/TrkEvent/TrkParameters/TrkParameters/TrackParameters.h:27
xAOD::TrackParticle
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Definition
Event/xAOD/xAODTracking/xAODTracking/TrackParticle.h:13
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition
Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
xAOD::Muon
Muon_v1 Muon
Reference the current persistent version:
Definition
Event/xAOD/xAODMuon/xAODMuon/Muon.h:13
EventInfo.h
Generated on
for ATLAS Offline Software by
1.17.0