ATLAS Offline Software
Loading...
Searching...
No Matches
AsgLeptonTrackDecorationAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
8
10#include <xAODMuon/Muon.h>
12
13#include <optional>
14
15
16namespace CP
17{
18
19 StatusCode AsgLeptonTrackDecorationAlg ::
20 initialize ()
21 {
22 if (!m_biasingTool.empty())
23 ANA_CHECK (m_biasingTool.retrieve());
24 if (!m_smearingTool.empty())
25 ANA_CHECK (m_smearingTool.retrieve());
26
28
31
35
36 if (!m_biasingTool.empty())
37 ANA_CHECK (m_systematicsList.addSystematics (*m_biasingTool));
38 if (!m_smearingTool.empty())
39 ANA_CHECK (m_systematicsList.addSystematics (*m_smearingTool));
40 ANA_CHECK (m_systematicsList.initialize());
41
42 ANA_CHECK (m_eventInfoKey.initialize());
43 ANA_CHECK (m_primaryVerticesKey.initialize());
44 ANA_CHECK (m_outOfValidity.initialize());
45
46 return StatusCode::SUCCESS;
47 }
48
49 StatusCode AsgLeptonTrackDecorationAlg ::
50 execute (const EventContext& ctx)
51 {
54 if (!vertices.isValid())
55 {
56 ANA_MSG_ERROR ("Cannot retrieve primary vertex container " << m_primaryVerticesKey.key());
57 return StatusCode::FAILURE;
58 }
59 const xAOD::Vertex *primaryVertex {nullptr};
60
61 for (const xAOD::Vertex *vertex : *vertices)
62 {
63 if (vertex->vertexType() == xAOD::VxType::PriVtx)
64 {
65 primaryVertex = vertex;
66 break;
67 }
68 }
69
70 for (const auto& sys : m_systematicsList.systematicsVector())
71 {
72 if (!m_biasingTool.empty())
73 ANA_CHECK (m_biasingTool->applySystematicVariation (sys));
74 if (!m_smearingTool.empty())
75 ANA_CHECK (m_smearingTool->applySystematicVariation (sys));
76 const xAOD::IParticleContainer *particles = nullptr;
77 ANA_CHECK (m_particlesHandle.retrieve (particles, sys, ctx));
78 for (const xAOD::IParticle *particle : *particles)
79 {
80 float d0sig = -999;
81 float d0 = -999;
82 float z0 = -999;
83 float deltaZ0SinTheta = -999;
84 float deltaZ0SinThetasig = -999;
85
86 const xAOD::TrackParticle *track {nullptr};
87 if (const xAOD::Muon *muon = dynamic_cast<const xAOD::Muon *>(particle)){
88 track = muon->trackParticle(xAOD::Muon::TrackParticleType::Primary);
89 } else if (const xAOD::Electron *electron = dynamic_cast<const xAOD::Electron *>(particle)){
90 track = electron->trackParticle();
91 } else {
92 ANA_MSG_ERROR ("failed to cast input to electron or muon");
93 return StatusCode::FAILURE;
94 }
95
96 // This deep-copy is not optimal and it would be more efficient to work with shallow-copies of the track container(s)
97 std::optional<xAOD::TrackParticle> correctedTrack;
98 if (!m_biasingTool.empty() || !m_smearingTool.empty())
99 correctedTrack.emplace (*track);
100 if (!m_biasingTool.empty())
101 ANA_CHECK_CORRECTION (m_outOfValidity, *correctedTrack, m_biasingTool->applyCorrection (*correctedTrack));
102 if (!m_smearingTool.empty())
103 ANA_CHECK_CORRECTION (m_outOfValidity, *correctedTrack, m_smearingTool->applyCorrection (*correctedTrack));
104 const xAOD::TrackParticle &copyTrack = correctedTrack ? *correctedTrack : *track;
105 d0 = copyTrack.d0();
106 try {
107 d0sig = xAOD::TrackingHelpers::d0significance(&copyTrack,
108 eventInfo->beamPosSigmaX(),
109 eventInfo->beamPosSigmaY(),
110 eventInfo->beamPosSigmaXY());
111 } catch (const std::runtime_error &) {
112 d0sig = -999;
113 }
114 z0 = copyTrack.z0();
115 const double vertex_z = primaryVertex ? primaryVertex->z() : 0;
116 deltaZ0SinTheta = (z0 + copyTrack.vz() - vertex_z) * sin (particle->p4().Theta());
117 try {
118 deltaZ0SinThetasig = xAOD::TrackingHelpers::z0sinthetasignificance(&copyTrack,primaryVertex);
119 } catch (const std::runtime_error &) {
120 deltaZ0SinThetasig = -999;
121 }
122
123 m_d0Handle.set(*particle,d0,sys);
124 m_d0sigHandle.set(*particle, d0sig, sys);
125 m_z0Handle.set(*particle,z0,sys);
126 m_z0sinthetaHandle.set(*particle, deltaZ0SinTheta, sys);
127 m_z0sinthetasigHandle.set(*particle,deltaZ0SinThetasig,sys);
128 }
129 }
130
131 return StatusCode::SUCCESS;
132 }
133
134} // namespace
Handle class for reading from StoreGate.
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
#define ANA_CHECK_CORRECTION(helper, object, expr)
a helper check macro to work with OutOfValidityHelper
ToolHandle< InDet::IInDetTrackSmearingTool > m_smearingTool
the smearing tool
SysWriteDecorHandle< float > m_d0sigHandle
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
the EventInfo key
SysReadHandle< xAOD::IParticleContainer > m_particlesHandle
the particle container we run on
SysWriteDecorHandle< float > m_z0Handle
SysWriteDecorHandle< float > m_d0Handle
ToolHandle< InDet::IInDetTrackBiasingTool > m_biasingTool
the biasing tool
SysWriteDecorHandle< float > m_z0sinthetasigHandle
SysWriteDecorHandle< float > m_z0sinthetaHandle
SysListHandle m_systematicsList
the systematics list we run
OutOfValidityHelper m_outOfValidity
the helper for OutOfValidity results
SG::ReadHandleKey< xAOD::VertexContainer > m_primaryVerticesKey
the PrimaryVertex key
virtual bool isValid() override final
Can the handle be successfully dereferenced?
Class providing the definition of the 4-vector interface.
float z0() const
Returns the parameter.
float vz() const
The z origin for the parameters.
float d0() const
Returns the parameter.
float z() const
Returns the z position.
Select isolated Photons, Electrons and Muons.
double z0sinthetasignificance(const xAOD::TrackParticle *tp, const xAOD::Vertex *vx=NULL)
Get the impact parameter significance of a track particle in the z direction, including the sin(theta...
double d0significance(const xAOD::TrackParticle *tp, double d0_uncert_beam_spot_2)
@ PriVtx
Primary vertex.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
Vertex_v1 Vertex
Define the latest version of the vertex class.
Muon_v1 Muon
Reference the current persistent version:
Electron_v1 Electron
Definition of the current "egamma version".
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.