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  AthAlgTool(t, n, p),
19  m_extrapolator("Trk::Extrapolator/AtlasExtrapolator")
20 {
21  declareInterface<DerivationFramework::IAugmentationTool>(this);
22  declareProperty("EndcapPivotPlaneZ", m_endcapPivotPlaneZ = 15525.);// z position of pivot plane in endcap region
23  declareProperty("EndcapPivotPlaneMinimumRadius", m_endcapPivotPlaneMinimumRadius = 0.);// minimum radius of pivot plane in endcap region
24  declareProperty("EndcapPivotPlaneMaximumRadius", m_endcapPivotPlaneMaximumRadius = 11977.); // maximum radius of pivot plane in endcap region
25  declareProperty("BarrelPivotPlaneRadius", m_barrelPivotPlaneRadius = 8000.);// radius of pivot plane in barrel region
26  declareProperty("BarrelPivotPlaneHalfLength", m_barrelPivotPlaneHalfLength = 9700.);// half length of pivot plane in barrel region
27  declareProperty("Extrapolator", m_extrapolator);
28  declareProperty("MuonCollection", m_muonContainerName = "Muons");
29 }
30 
31 //**********************************************************************
32 
33 
35 {
36  ATH_CHECK(m_extrapolator.retrieve());
37  return StatusCode::SUCCESS;
38 }
39 
40 
41 //**********************************************************************
42 
44 {
45 
46  // decorators used to access or store the information
47  static const SG::AuxElement::Decorator< char > Decorated ("DecoratedPivotEtaPhi");
48  static const SG::AuxElement::Decorator< float > Eta ("EtaTriggerPivot");
49  static const SG::AuxElement::Decorator< float > Phi ("PhiTriggerPivot");
50 
51  if (! Decorated.isAvailable(*particle) || !Decorated(*particle)){
52  // in the athena release, we can run the extrapolation if needed
54  if(!pTag) {
55  Decorated(*particle) = false;
56  return false;
57  }
58  Eta(*particle) = pTag->position().eta();
59  Phi(*particle) = pTag->position().phi();
60  Decorated(*particle) = true;
61  delete pTag;
62  }
63  // if we get here, the decoration was either already present or just added by us
64  // so we can finally read the values
65  eta = Eta(*particle);
66  phi = Phi(*particle);
67  return true;
68 }
69 
70 //**********************************************************************
71 
73 {
74  if (dynamic_cast<const xAOD::TruthParticle*>(muon)){
75  ATH_MSG_WARNING("Pivot plane extrapolation not supported for Truth muons!");
76  return 0;
77  }
78  const xAOD::TrackParticle* muonTrack = dynamic_cast<const xAOD::TrackParticle*>(muon);
79  if(!muonTrack && dynamic_cast<const xAOD::Muon*>(muon)) {
80  const xAOD::Muon* theMuon = dynamic_cast<const xAOD::Muon*>(muon);
81  muonTrack = theMuon->trackParticle( xAOD::Muon::MuonSpectrometerTrackParticle );
82  if(!muonTrack) {
83  muonTrack = theMuon->primaryTrackParticle();
84  if(!muonTrack) {
85  muonTrack = theMuon->trackParticle( xAOD::Muon::InnerDetectorTrackParticle );
86  }
87  }
88  }
89  if(!muonTrack){
90  ATH_MSG_WARNING("no valid track found for extrapolating the muon to the pivot plane!");
91  }
92  return muonTrack;
93 
94 }
95 
97 {
98  const xAOD::MuonContainer* muons = NULL;
100  for(auto muon : *muons){
102  float eta, phi = 0;
103  if( !extrapolateAndDecorateTrackParticle( track, eta, phi )){
104  if( muon->pt() > 3500.){
105  //only complain if the muon has sufficient pT to actually reach the pivot plane
106  //extrapolation will often fail for muons with pT < 3500 MeV
107  ATH_MSG_WARNING("Failed to extrapolate+decorate muon with pivot plane coords - Muon params: pt "<<muon->pt()<<", eta "<< muon->eta()<<", phi "<< muon->phi());
108  }
109  }
110  }
111  return StatusCode::SUCCESS;
112 }
113 
115 {
116  // BARREL
117  const EventContext& ctx = Gaudi::Hive::currentContext();
118  const Trk::Perigee& perigee = track.perigeeParameters();
119 
120  // create the barrel as a cylinder surface centered at 0,0,0
121  Amg::Vector3D barrelCentre(0., 0., 0.);
122  Amg::Transform3D matrix = Amg::Transform3D(Amg::RotationMatrix3D::Identity(), barrelCentre);
123 
124  Trk::CylinderSurface* cylinder =
128  if (!cylinder) {
129  ATH_MSG_WARNING("extrapolateToTriggerPivotPlane :: new Trk::CylinderSurface failed.");
130  return 0;
131  }
132  // and then attempt to extrapolate our track to this surface, checking for the boundaries of the barrel
133  bool boundaryCheck = true;
134  const Trk::Surface* surface = cylinder;
135  const Trk::TrackParameters* p = m_extrapolator->extrapolate(
136  ctx, perigee, *surface, Trk::alongMomentum, boundaryCheck, Trk::muon).release();
137  delete cylinder;
138  // if the extrapolation worked out (so we are in the barrel) we are done and can return the
139  // track parameters at this surface.
140  if (p) return p;
141 
142  // if we get here, the muon did not cross the barrel surface
143  // so we assume it is going into the endcap.
144  // ENDCAP
145 
146  // After 2 years of using this code, we realised that ATLAS actually has endcaps on both sides ;-)
147  // So better make sure we place our endcap at the correct side of the detector!
148  // Hopefully no-one will ever read this comment...
149  float SignOfEta = track.eta() > 0 ? 1. : -1.;
150 
151  Amg::Vector3D endcapCentre(0., 0., m_endcapPivotPlaneZ);
152  // much better!
153  matrix = Amg::Transform3D(Amg::RotationMatrix3D::Identity(), SignOfEta * endcapCentre);
154 
155  Trk::DiscSurface* disc =
159  if (!disc) {
160  ATH_MSG_WARNING("extrapolateToTriggerPivotPlane :: new Trk::DiscSurface failed.");
161  return 0;
162  }
163 
164  // for the endcap, we turn off the boundary check, extending the EC infinitely to catch stuff heading for the transition region
165  boundaryCheck = false;
166  surface = disc;
167  p = m_extrapolator->extrapolate(
168  ctx, perigee, *surface, Trk::alongMomentum, boundaryCheck, Trk::muon).release();
169  delete disc;
170  return p;
171 }
172 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
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:76
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:486
DerivationFramework::MuonExtrapolationTool::extrapolateAndDecorateTrackParticle
bool extrapolateAndDecorateTrackParticle(const xAOD::TrackParticle *particle, float &eta, float &phi) const
Definition: MuonExtrapolationTool.cxx:43
DerivationFramework::MuonExtrapolationTool::m_barrelPivotPlaneHalfLength
double m_barrelPivotPlaneHalfLength
Definition: MuonExtrapolationTool.h:53
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
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:34
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
DerivationFramework::MuonExtrapolationTool::m_endcapPivotPlaneMaximumRadius
double m_endcapPivotPlaneMaximumRadius
Definition: MuonExtrapolationTool.h:51
DerivationFramework::MuonExtrapolationTool::addBranches
virtual StatusCode addBranches() const
Pass the thinning service
Definition: MuonExtrapolationTool.cxx:96
SG::Decorator
Helper class to provide type-safe access to aux data.
Definition: Decorator.h:59
beamspotman.n
n
Definition: beamspotman.py:731
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:28
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
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:114
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:72
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
EventInfo.h
MuonContainer.h
python.testIfMatch.matrix
matrix
Definition: testIfMatch.py:66
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:400
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
AthAlgTool
Definition: AthAlgTool.h:26
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
DerivationFramework::MuonExtrapolationTool::m_extrapolator
ToolHandle< Trk::IExtrapolator > m_extrapolator
Definition: MuonExtrapolationTool.h:28
Eta
@ Eta
Definition: RPCdef.h:8