ATLAS Offline Software
MuonExtrapolationTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 // MuonExtrapolationTool.cxx
10 #include "TVector2.h"
11 #include "xAODMuon/MuonContainer.h"
12 //**********************************************************************
13 
14 namespace DerivationFramework {
15 
16 MuonExtrapolationTool::MuonExtrapolationTool(const std::string &t, const std::string& n, const IInterface* p)
17  :
18  base_class(t, n, p),
19  m_extrapolator("Trk::Extrapolator/AtlasExtrapolator")
20 {
21  declareProperty("EndcapPivotPlaneZ", m_endcapPivotPlaneZ = 15525.);// z position of pivot plane in endcap region
22  declareProperty("EndcapPivotPlaneMinimumRadius", m_endcapPivotPlaneMinimumRadius = 0.);// minimum radius of pivot plane in endcap region
23  declareProperty("EndcapPivotPlaneMaximumRadius", m_endcapPivotPlaneMaximumRadius = 11977.); // maximum radius of pivot plane in endcap region
24  declareProperty("BarrelPivotPlaneRadius", m_barrelPivotPlaneRadius = 8000.);// radius of pivot plane in barrel region
25  declareProperty("BarrelPivotPlaneHalfLength", m_barrelPivotPlaneHalfLength = 9700.);// half length of pivot plane in barrel region
26  declareProperty("Extrapolator", m_extrapolator);
27  declareProperty("MuonCollection", m_muonContainerName = "Muons");
28 }
29 
30 //**********************************************************************
31 
32 
34 {
35  ATH_CHECK(m_extrapolator.retrieve());
36  return StatusCode::SUCCESS;
37 }
38 
39 
40 //**********************************************************************
41 
43 {
44 
45  // decorators used to access or store the information
46  static const SG::AuxElement::Decorator< char > Decorated ("DecoratedPivotEtaPhi");
47  static const SG::AuxElement::Decorator< float > Eta ("EtaTriggerPivot");
48  static const SG::AuxElement::Decorator< float > Phi ("PhiTriggerPivot");
49 
50  if (! Decorated.isAvailable(*particle) || !Decorated(*particle)){
51  // in the athena release, we can run the extrapolation if needed
53  if(!pTag) {
54  Decorated(*particle) = false;
55  return false;
56  }
57  Eta(*particle) = pTag->position().eta();
58  Phi(*particle) = pTag->position().phi();
59  Decorated(*particle) = true;
60  delete pTag;
61  }
62  // if we get here, the decoration was either already present or just added by us
63  // so we can finally read the values
64  eta = Eta(*particle);
65  phi = Phi(*particle);
66  return true;
67 }
68 
69 //**********************************************************************
70 
72 {
73  if (dynamic_cast<const xAOD::TruthParticle*>(muon)){
74  ATH_MSG_WARNING("Pivot plane extrapolation not supported for Truth muons!");
75  return 0;
76  }
77  const xAOD::TrackParticle* muonTrack = dynamic_cast<const xAOD::TrackParticle*>(muon);
78  if(!muonTrack && dynamic_cast<const xAOD::Muon*>(muon)) {
79  const xAOD::Muon* theMuon = dynamic_cast<const xAOD::Muon*>(muon);
80  muonTrack = theMuon->trackParticle( xAOD::Muon::MuonSpectrometerTrackParticle );
81  if(!muonTrack) {
82  muonTrack = theMuon->primaryTrackParticle();
83  if(!muonTrack) {
84  muonTrack = theMuon->trackParticle( xAOD::Muon::InnerDetectorTrackParticle );
85  }
86  }
87  }
88  if(!muonTrack){
89  ATH_MSG_WARNING("no valid track found for extrapolating the muon to the pivot plane!");
90  }
91  return muonTrack;
92 
93 }
94 
96 {
97  const xAOD::MuonContainer* muons = NULL;
98  CHECK(evtStore()->retrieve(muons, m_muonContainerName));
99  for(auto muon : *muons){
101  float eta, phi = 0;
103  if( muon->pt() > 3500.){
104  //only complain if the muon has sufficient pT to actually reach the pivot plane
105  //extrapolation will often fail for muons with pT < 3500 MeV
106  ATH_MSG_WARNING("Failed to extrapolate+decorate muon with pivot plane coords - Muon params: pt "<<muon->pt()<<", eta "<< muon->eta()<<", phi "<< muon->phi());
107  }
108  }
109  }
110  return StatusCode::SUCCESS;
111 }
112 
114 {
115  // BARREL
116  const EventContext& ctx = Gaudi::Hive::currentContext();
117  const Trk::Perigee& perigee = track.perigeeParameters();
118 
119  // create the barrel as a cylinder surface centered at 0,0,0
120  Amg::Vector3D barrelCentre(0., 0., 0.);
121  Amg::Transform3D matrix = Amg::Transform3D(Amg::RotationMatrix3D::Identity(), barrelCentre);
122 
123  Trk::CylinderSurface* cylinder =
127  if (!cylinder) {
128  ATH_MSG_WARNING("extrapolateToTriggerPivotPlane :: new Trk::CylinderSurface failed.");
129  return 0;
130  }
131  // and then attempt to extrapolate our track to this surface, checking for the boundaries of the barrel
132  bool boundaryCheck = true;
133  const Trk::Surface* surface = cylinder;
134  const Trk::TrackParameters* p = m_extrapolator->extrapolate(
135  ctx, perigee, *surface, Trk::alongMomentum, boundaryCheck, Trk::muon).release();
136  delete cylinder;
137  // if the extrapolation worked out (so we are in the barrel) we are done and can return the
138  // track parameters at this surface.
139  if (p) return p;
140 
141  // if we get here, the muon did not cross the barrel surface
142  // so we assume it is going into the endcap.
143  // ENDCAP
144 
145  // After 2 years of using this code, we realised that ATLAS actually has endcaps on both sides ;-)
146  // So better make sure we place our endcap at the correct side of the detector!
147  // Hopefully no-one will ever read this comment...
148  float SignOfEta = track.eta() > 0 ? 1. : -1.;
149 
150  Amg::Vector3D endcapCentre(0., 0., m_endcapPivotPlaneZ);
151  // much better!
152  matrix = Amg::Transform3D(Amg::RotationMatrix3D::Identity(), SignOfEta * endcapCentre);
153 
154  Trk::DiscSurface* disc =
158  if (!disc) {
159  ATH_MSG_WARNING("extrapolateToTriggerPivotPlane :: new Trk::DiscSurface failed.");
160  return 0;
161  }
162 
163  // for the endcap, we turn off the boundary check, extending the EC infinitely to catch stuff heading for the transition region
164  boundaryCheck = false;
165  surface = disc;
166  p = m_extrapolator->extrapolate(
167  ctx, perigee, *surface, Trk::alongMomentum, boundaryCheck, Trk::muon).release();
168  delete disc;
169  return p;
170 }
171 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:196
DerivationFramework::MuonExtrapolationTool::m_barrelPivotPlaneRadius
double m_barrelPivotPlaneRadius
Definition: MuonExtrapolationTool.h:52
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
DerivationFramework::MuonExtrapolationTool::m_endcapPivotPlaneMinimumRadius
double m_endcapPivotPlaneMinimumRadius
Definition: MuonExtrapolationTool.h:50
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
DerivationFramework::MuonExtrapolationTool::extrapolateAndDecorateTrackParticle
bool extrapolateAndDecorateTrackParticle(const xAOD::TrackParticle *particle, float &eta, float &phi) const
Definition: MuonExtrapolationTool.cxx:42
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
DerivationFramework::MuonExtrapolationTool::m_barrelPivotPlaneHalfLength
double m_barrelPivotPlaneHalfLength
Definition: MuonExtrapolationTool.h:53
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
TruthParticleContainer.h
DerivationFramework::MuonExtrapolationTool::m_endcapPivotPlaneZ
double m_endcapPivotPlaneZ
Definition: MuonExtrapolationTool.h:49
Trk::alongMomentum
@ alongMomentum
Definition: PropDirection.h:20
Phi
@ Phi
Definition: RPCdef.h:8
Trk::DiscSurface
Definition: DiscSurface.h:54
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
DerivationFramework::MuonExtrapolationTool::initialize
virtual StatusCode initialize()
Definition: MuonExtrapolationTool.cxx:33
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
DerivationFramework::MuonExtrapolationTool::m_endcapPivotPlaneMaximumRadius
double m_endcapPivotPlaneMaximumRadius
Definition: MuonExtrapolationTool.h:51
DerivationFramework::MuonExtrapolationTool::addBranches
virtual StatusCode addBranches() const
Definition: MuonExtrapolationTool.cxx:95
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
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
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
Trk::ParametersBase
Definition: ParametersBase.h:55
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
jobOptions.pTag
string pTag
Definition: jobOptions.py:28
Trk::muon
@ muon
Definition: ParticleHypothesis.h:31
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
MuonExtrapolationTool.h
DerivationFramework::MuonExtrapolationTool::extrapolateToTriggerPivotPlane
const Trk::TrackParameters * extrapolateToTriggerPivotPlane(const xAOD::TrackParticle &track) const
run the extrapolation - only available in full athena
Definition: MuonExtrapolationTool.cxx:113
DerivationFramework::MuonExtrapolationTool::MuonExtrapolationTool
MuonExtrapolationTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: MuonExtrapolationTool.cxx:16
DerivationFramework::MuonExtrapolationTool::getPreferredTrackParticle
const xAOD::TrackParticle * getPreferredTrackParticle(const xAOD::IParticle *probe) const
Definition: MuonExtrapolationTool.cxx:71
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
EventInfo.h
MuonContainer.h
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
DerivationFramework::MuonExtrapolationTool::m_muonContainerName
std::string m_muonContainerName
Definition: MuonExtrapolationTool.h:54
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:43
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:79
DerivationFramework::MuonExtrapolationTool::m_extrapolator
ToolHandle< Trk::IExtrapolator > m_extrapolator
Definition: MuonExtrapolationTool.h:28
Eta
@ Eta
Definition: RPCdef.h:8