ATLAS Offline Software
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 
11 namespace {
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 
22 namespace DerivationFramework{
23 MuonTPExtrapolationAlg::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 
40 StatusCode 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};
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 
97 std::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 }
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
DerivationFramework::MuonTPExtrapolationAlg::extrapolateToTriggerPivotPlane
std::unique_ptr< Trk::TrackParameters > extrapolateToTriggerPivotPlane(const EventContext &ctx, const xAOD::TrackParticle &track) const
run the extrapolation - only available in full athena
Definition: MuonTPExtrapolationAlg.cxx:97
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:504
Utils.h
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
xAODP4Helpers.h
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
DerivationFramework::MuonTPExtrapolationAlg::m_barrelPivotPlaneHalfLength
Gaudi::Property< float > m_barrelPivotPlaneHalfLength
Definition: MuonTPExtrapolationAlg.h:38
DerivationFramework::MuonTPExtrapolationAlg::m_extrapolator
ToolHandle< Trk::IExtrapolator > m_extrapolator
Definition: MuonTPExtrapolationAlg.h:30
Trk::alongMomentum
@ alongMomentum
Definition: PropDirection.h:20
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
MuonTPExtrapolationAlg.h
DerivationFramework::MuonTPExtrapolationAlg::m_endcapPivotPlaneMaximumRadius
Gaudi::Property< float > m_endcapPivotPlaneMaximumRadius
Definition: MuonTPExtrapolationAlg.h:35
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
xAOD::TrackParticle
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Definition: Event/xAOD/xAODTracking/xAODTracking/TrackParticle.h:13
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
DerivationFramework::MuonTPExtrapolationAlg::m_barrelPivotPlaneRadius
Gaudi::Property< float > m_barrelPivotPlaneRadius
Definition: MuonTPExtrapolationAlg.h:37
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
DerivationFramework::MuonTPExtrapolationAlg::m_partKey
SG::ReadHandleKey< xAOD::IParticleContainer > m_partKey
Particle container to decorate the Pivot plane coordinates to.
Definition: MuonTPExtrapolationAlg.h:42
CylinderSurface.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
jobOptions.pTag
string pTag
Definition: jobOptions.py:28
Trk::muon
@ muon
Definition: ParticleHypothesis.h:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
EventInfo.h
Muon
struct TBPatternUnitContext Muon
DerivationFramework::MuonTPExtrapolationAlg::m_extStatKey
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_extStatKey
Definition: MuonTPExtrapolationAlg.h:46
DerivationFramework::MuonTPExtrapolationAlg::m_extEtaKey
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_extEtaKey
Definition: MuonTPExtrapolationAlg.h:44
DerivationFramework::MuonTPExtrapolationAlg::MuonTPExtrapolationAlg
MuonTPExtrapolationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MuonTPExtrapolationAlg.cxx:23
python.testIfMatch.matrix
matrix
Definition: testIfMatch.py:66
DerivationFramework::MuonTPExtrapolationAlg::m_trkSelDecors
Gaudi::Property< std::vector< std::string > > m_trkSelDecors
Definition: MuonTPExtrapolationAlg.h:52
DerivationFramework::MuonTPExtrapolationAlg::m_trkSelKeys
SG::ReadDecorHandleKeyArray< xAOD::IParticleContainer > m_trkSelKeys
Definition: MuonTPExtrapolationAlg.h:55
DerivationFramework::MuonTPExtrapolationAlg::m_extPhiKey
SG::WriteDecorHandleKey< xAOD::IParticleContainer > m_extPhiKey
Definition: MuonTPExtrapolationAlg.h:45
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DerivationFramework::MuonTPExtrapolationAlg::m_endcapPivotPlaneZ
Gaudi::Property< float > m_endcapPivotPlaneZ
Definition: MuonTPExtrapolationAlg.h:32
DiscSurface.h
DerivationFramework::MuonTPExtrapolationAlg::m_endcapPivotPlaneMinimumRadius
Gaudi::Property< float > m_endcapPivotPlaneMinimumRadius
Definition: MuonTPExtrapolationAlg.h:33
DerivationFramework::MuonTPExtrapolationAlg::initialize
virtual StatusCode initialize() override
Definition: MuonTPExtrapolationAlg.cxx:26
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:418
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
xAOD::TrackParticle_v1
Class describing a TrackParticle.
Definition: TrackParticle_v1.h:43
SG::ReadDecorHandleKey
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Definition: StoreGate/StoreGate/ReadDecorHandleKey.h:85
DerivationFramework::MuonTPExtrapolationAlg::m_ptMin
Gaudi::Property< float > m_ptMin
Optional list of decorators to select only the good tracks for the isolation decoration.
Definition: MuonTPExtrapolationAlg.h:50
DerivationFramework::MuonTPExtrapolationAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: MuonTPExtrapolationAlg.cxx:40
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37