ATLAS Offline Software
Loading...
Searching...
No Matches
AsgLeptonTrackDecorationAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
8
10#include <xAODMuon/Muon.h>
12
13
14namespace CP
15{
16
17 StatusCode AsgLeptonTrackDecorationAlg ::
18 initialize ()
19 {
20 if (!m_biasingTool.empty())
21 ANA_CHECK (m_biasingTool.retrieve());
22 if (!m_smearingTool.empty())
23 ANA_CHECK (m_smearingTool.retrieve());
24
26
29
33
34 if (!m_biasingTool.empty())
35 ANA_CHECK (m_systematicsList.addSystematics (*m_biasingTool));
36 if (!m_smearingTool.empty())
37 ANA_CHECK (m_systematicsList.addSystematics (*m_smearingTool));
38 ANA_CHECK (m_systematicsList.initialize());
39
40 ANA_CHECK (m_eventInfoKey.initialize());
41 ANA_CHECK (m_primaryVerticesKey.initialize());
42 ANA_CHECK (m_outOfValidity.initialize());
43
44 return StatusCode::SUCCESS;
45 }
46
47 StatusCode AsgLeptonTrackDecorationAlg ::
48 execute ()
49 {
52 const xAOD::Vertex *primaryVertex {nullptr};
53
54 for (const xAOD::Vertex *vertex : *vertices)
55 {
56 if (vertex->vertexType() == xAOD::VxType::PriVtx)
57 {
58 if (primaryVertex == nullptr)
59 {
60 primaryVertex = vertex;
61 break;
62 }
63 }
64 }
65
66 for (const auto& sys : m_systematicsList.systematicsVector())
67 {
68 if (!m_biasingTool.empty())
69 ANA_CHECK (m_biasingTool->applySystematicVariation (sys));
70 if (!m_smearingTool.empty())
71 ANA_CHECK (m_smearingTool->applySystematicVariation (sys));
72 const xAOD::IParticleContainer *particles = nullptr;
73 ANA_CHECK (m_particlesHandle.retrieve (particles, sys));
74 for (const xAOD::IParticle *particle : *particles)
75 {
76 float d0sig = -999;
77 float d0 = -999;
78 float z0 = -999;
79 float deltaZ0SinTheta = -999;
80 float deltaZ0SinThetasig = -999;
81
82 const xAOD::TrackParticle *track {nullptr};
83 if (const xAOD::Muon *muon = dynamic_cast<const xAOD::Muon *>(particle)){
84 track = muon->primaryTrackParticle();
85 } else if (const xAOD::Electron *electron = dynamic_cast<const xAOD::Electron *>(particle)){
86 track = electron->trackParticle();
87 } else {
88 ANA_MSG_ERROR ("failed to cast input to electron or muon");
89 return StatusCode::FAILURE;
90 }
91
92 if (track != nullptr) {
93 // This deep-copy is not optimal and it would be more efficient to work with shallow-copies of the track container(s)
94 xAOD::TrackParticle copyTrack {*track};
95 if (!m_biasingTool.empty())
96 ANA_CHECK_CORRECTION (m_outOfValidity, copyTrack, m_biasingTool->applyCorrection (copyTrack));
97 if (!m_smearingTool.empty())
98 ANA_CHECK_CORRECTION (m_outOfValidity, copyTrack, m_smearingTool->applyCorrection (copyTrack));
99 d0 = copyTrack.d0();
100 d0sig = xAOD::TrackingHelpers::d0significance(&copyTrack,
101 eventInfo->beamPosSigmaX(),
102 eventInfo->beamPosSigmaY(),
103 eventInfo->beamPosSigmaXY());
104
105 z0 = copyTrack.z0();
106 const double vertex_z = primaryVertex ? primaryVertex->z() : 0;
107 deltaZ0SinTheta = (z0 + copyTrack.vz() - vertex_z) * sin (particle->p4().Theta());
108 deltaZ0SinThetasig = xAOD::TrackingHelpers::z0sinthetasignificance(&copyTrack,primaryVertex);
109 }
110
111 m_d0Handle.set(*particle,d0,sys);
112 m_d0sigHandle.set(*particle, d0sig, sys);
113 m_z0Handle.set(*particle,z0,sys);
114 m_z0sinthetaHandle.set(*particle, deltaZ0SinTheta, sys);
115 m_z0sinthetasigHandle.set(*particle,deltaZ0SinThetasig,sys);
116 }
117 }
118
119 return StatusCode::SUCCESS;
120 }
121
122} // 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
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.