ATLAS Offline Software
Loading...
Searching...
No Matches
AsgLeptonTrackSelectionAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9//
10// includes
11//
12
14
15#include <xAODEgamma/Electron.h>
16#include <xAODMuon/Muon.h>
18
19//
20// method implementations
21//
22
23namespace CP
24{
25
26 StatusCode AsgLeptonTrackSelectionAlg ::
27 initialize ()
28 {
29
30 if (m_maxD0Significance < 0 || !std::isfinite (m_maxD0Significance))
31 {
32 ATH_MSG_ERROR ("invalid value of maxD0Significance: " << m_maxD0Significance);
33 return StatusCode::FAILURE;
34 }
35 if (m_maxDeltaZ0SinTheta < 0 || !std::isfinite (m_maxDeltaZ0SinTheta))
36 {
37 ATH_MSG_ERROR ("invalid value of maxDeltaZ0SinTheta: " << m_maxDeltaZ0SinTheta);
38 return StatusCode::FAILURE;
39 }
40
41 m_accept.addCut ("trackRetrieval", "whether the track retrieval failed");
42 if (m_maxD0Significance > 0)
43 m_accept.addCut ("maxD0Significance", "maximum D0 significance cut");
45 m_accept.addCut ("maxDeltaZ0SinTheta", "maximum Delta z0 sin theta cut");
46 if (m_nMinPixelHits != -1 || m_nMaxPixelHits != -1)
47 m_accept.addCut ("numPixelHits", "Minimum and/or maxiumum Pixel hits");
48 if (m_nMinSCTHits != -1 || m_nMaxSCTHits != -1)
49 m_accept.addCut ("numSCTHits", "Minimum and/or maxiumum SCT hits");
50
54 ANA_CHECK (m_systematicsList.initialize());
55
56 ANA_CHECK (m_eventInfoKey.initialize());
57 ANA_CHECK (m_primaryVerticesKey.initialize());
58
59 if (!m_nameSvc.empty())
60 {
61 ANA_CHECK (m_nameSvc.retrieve());
62 ANA_CHECK (m_nameSvc->addAcceptInfo (m_particlesHandle.getNamePattern(), m_selectionHandle.getLabel(),
63 m_accept));
64 }
65
66 return StatusCode::SUCCESS;
67 }
68
69
70
71 StatusCode AsgLeptonTrackSelectionAlg ::
72 execute (const EventContext &ctx) const
73 {
76 if (!vertices.isValid())
77 {
78 ANA_MSG_ERROR ("Cannot retrieve primary vertex container " << m_primaryVerticesKey.key());
79 return StatusCode::FAILURE;
80 }
81 const xAOD::Vertex *primaryVertex {nullptr};
82
83 for (const xAOD::Vertex *vertex : *vertices)
84 {
85 if (vertex->vertexType() == xAOD::VxType::PriVtx)
86 {
87 // The default "PrimaryVertex" container is ordered in
88 // sum-pt, and the tracking group recommends to pick the one
89 // with the maximum sum-pt, so this will do the right thing.
90 // If the user needs a different primary vertex, they need to
91 // provide a reordered primary vertex container and point
92 // this algorithm to it. Currently there is no central
93 // algorithm to do that, so users will have to write their
94 // own (15 Aug 18).
95 primaryVertex = vertex;
96 break;
97 }
98 }
99
100 for (const auto& sys : m_systematicsList.systematicsVector())
101 {
102 const xAOD::IParticleContainer *particles = nullptr;
103 ANA_CHECK (m_particlesHandle.retrieve (particles, sys, ctx));
104 for (const xAOD::IParticle *particle : *particles)
105 {
106 asg::AcceptData acceptData (&m_accept);
107 float d0sig = -999;
108 float deltaZ0SinTheta = -999;
109
110 if (m_preselection.getBool (*particle, sys))
111 {
112 std::size_t cutIndex {0};
113
114 const xAOD::TrackParticle *track {nullptr};
115 if (const xAOD::Muon *muon = dynamic_cast<const xAOD::Muon *>(particle)){
116 track = muon->trackParticle(xAOD::Muon::TrackParticleType::Primary);
117 } else if (const xAOD::Electron *electron = dynamic_cast<const xAOD::Electron *>(particle)){
118 track = electron->trackParticle();
119 } else {
120 ANA_MSG_ERROR ("failed to cast input to electron or muon");
121 return StatusCode::FAILURE;
122 }
123
124 acceptData.setCutResult (cutIndex ++, track != nullptr);
125
126 if (track != nullptr) {
127 if (m_maxD0Significance > 0) {
128 try {
129 d0sig = xAOD::TrackingHelpers::d0significance(track, eventInfo->beamPosSigmaX(), eventInfo->beamPosSigmaY(), eventInfo->beamPosSigmaXY());
130 acceptData.setCutResult (cutIndex ++, fabs( d0sig ) < m_maxD0Significance);
131 } catch (const std::runtime_error &) {
132 acceptData.setCutResult (cutIndex ++, false);
133 }
134 }
135
136 const double vertex_z = primaryVertex ? primaryVertex->z() : 0;
137 deltaZ0SinTheta = (track->z0() + track->vz() - vertex_z) * sin (particle->p4().Theta());
138 if (m_maxDeltaZ0SinTheta > 0) acceptData.setCutResult (cutIndex ++, fabs (deltaZ0SinTheta) < m_maxDeltaZ0SinTheta);
139
140 if (m_nMinPixelHits != -1 || m_nMaxPixelHits != -1) {
141 uint8_t nPixelHits = 0;
142 bool accept = track->summaryValue(nPixelHits, xAOD::numberOfPixelHits);
143 if(accept && m_nMinPixelHits != -1) {
144 accept = nPixelHits >= m_nMinPixelHits;
145 }
146 if(accept && m_nMaxPixelHits != -1) {
147 accept = nPixelHits <= m_nMaxPixelHits;
148 }
149 acceptData.setCutResult (cutIndex++, accept);
150 }
151 if (m_nMinSCTHits != -1 || m_nMaxSCTHits != -1) {
152 uint8_t nSCTHits = 0;
153 bool accept = track->summaryValue(nSCTHits, xAOD::numberOfSCTHits);
154 if(accept && m_nMinSCTHits != -1) {
155 accept = nSCTHits >= m_nMinSCTHits;
156 }
157 if(accept && m_nMaxSCTHits != -1) {
158 accept = nSCTHits <= m_nMaxSCTHits;
159 }
160 acceptData.setCutResult (cutIndex++, accept);
161 }
162 }
163 }
164
165 m_selectionHandle.setBits(*particle, selectionFromAccept (acceptData), sys);
166 }
167 }
168
169 return StatusCode::SUCCESS;
170 }
171}
#define ATH_MSG_ERROR(x,...)
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
SysListHandle m_systematicsList
the systematics list we run
ServiceHandle< ISelectionNameSvc > m_nameSvc
the ISelectionNameSvc
Gaudi::Property< float > m_maxDeltaZ0SinTheta
SysWriteSelectionHandle m_selectionHandle
the accessor for m_selectionDecoration
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
the EventInfo key
SG::ReadHandleKey< xAOD::VertexContainer > m_primaryVerticesKey
the PrimaryVertex key
SysReadHandle< xAOD::IParticleContainer > m_particlesHandle
the particle container we run on
Gaudi::Property< float > m_maxD0Significance
algorithm properties
SysReadSelectionHandle m_preselection
the preselection we apply to our input
asg::AcceptInfo m_accept
the asg::AcceptInfo we are using
virtual bool isValid() override final
Can the handle be successfully dereferenced?
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer).
Definition AcceptData.h:135
Class providing the definition of the 4-vector interface.
float z() const
Returns the z position.
Select isolated Photons, Electrons and Muons.
SelectionType selectionFromAccept(const asg::AcceptData &accept)
the selection decoration made from the given AcceptData object
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:
@ numberOfSCTHits
number of hits in SCT [unit8_t].
@ numberOfPixelHits
these are the pixel hits, including the b-layer [unit8_t].
Electron_v1 Electron
Definition of the current "egamma version".
DataVector< IParticle > IParticleContainer
Simple convenience declaration of IParticleContainer.