ATLAS Offline Software
Loading...
Searching...
No Matches
AsgLeptonTrackSelectionAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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 const xAOD::Vertex *primaryVertex {nullptr};
77
78 for (const xAOD::Vertex *vertex : *vertices)
79 {
80 if (vertex->vertexType() == xAOD::VxType::PriVtx)
81 {
82 // The default "PrimaryVertex" container is ordered in
83 // sum-pt, and the tracking group recommends to pick the one
84 // with the maximum sum-pt, so this will do the right thing.
85 // If the user needs a different primary vertex, they need to
86 // provide a reordered primary vertex container and point
87 // this algorithm to it. Currently there is no central
88 // algorithm to do that, so users will have to write their
89 // own (15 Aug 18).
90 if (primaryVertex == nullptr)
91 {
92 primaryVertex = vertex;
93 break;
94 }
95 }
96 }
97
98 for (const auto& sys : m_systematicsList.systematicsVector())
99 {
100 const xAOD::IParticleContainer *particles = nullptr;
101 ANA_CHECK (m_particlesHandle.retrieve (particles, sys));
102 for (const xAOD::IParticle *particle : *particles)
103 {
104 asg::AcceptData acceptData (&m_accept);
105 float d0sig = -999;
106 float deltaZ0SinTheta = -999;
107
108 if (m_preselection.getBool (*particle, sys))
109 {
110 std::size_t cutIndex {0};
111
112 const xAOD::TrackParticle *track {nullptr};
113 if (const xAOD::Muon *muon = dynamic_cast<const xAOD::Muon *>(particle)){
114 track = muon->primaryTrackParticle();
115 } else if (const xAOD::Electron *electron = dynamic_cast<const xAOD::Electron *>(particle)){
116 track = electron->trackParticle();
117 } else {
118 ANA_MSG_ERROR ("failed to cast input to electron or muon");
119 return StatusCode::FAILURE;
120 }
121
122 acceptData.setCutResult (cutIndex ++, track != nullptr);
123
124 if (track != nullptr) {
125 try {
126 d0sig = xAOD::TrackingHelpers::d0significance(track, eventInfo->beamPosSigmaX(), eventInfo->beamPosSigmaY(), eventInfo->beamPosSigmaXY());
127 if (m_maxD0Significance > 0) acceptData.setCutResult (cutIndex ++, fabs( d0sig ) < m_maxD0Significance);
128
129 } catch (const std::runtime_error &) {
130 acceptData.setCutResult (cutIndex ++, false);
131 }
132
133 const double vertex_z = primaryVertex ? primaryVertex->z() : 0;
134 deltaZ0SinTheta = (track->z0() + track->vz() - vertex_z) * sin (particle->p4().Theta());
135 if (m_maxDeltaZ0SinTheta > 0) acceptData.setCutResult (cutIndex ++, fabs (deltaZ0SinTheta) < m_maxDeltaZ0SinTheta);
136
137 if (m_nMinPixelHits != -1 || m_nMaxPixelHits != -1) {
138 uint8_t nPixelHits;
139 track->summaryValue(nPixelHits, xAOD::numberOfPixelHits);
140 bool accept = true;
141 if(m_nMinPixelHits != -1) {
142 accept &= nPixelHits >= m_nMinPixelHits;
143 }
144 if(m_nMaxPixelHits != -1) {
145 accept &= nPixelHits <= m_nMaxPixelHits;
146 }
147 acceptData.setCutResult (cutIndex++, accept);
148 }
149 if (m_nMinSCTHits != -1 || m_nMaxSCTHits != -1) {
150 uint8_t nSCTHits;
151 track->summaryValue(nSCTHits, xAOD::numberOfSCTHits);
152 bool accept = true;
153 if(m_nMinSCTHits != -1) {
154 accept &= nSCTHits >= m_nMinSCTHits;
155 }
156 if(m_nMaxSCTHits != -1) {
157 accept &= nSCTHits <= m_nMaxSCTHits;
158 }
159 acceptData.setCutResult (cutIndex++, accept);
160 }
161 }
162 }
163
164 m_selectionHandle.setBits(*particle, selectionFromAccept (acceptData), sys);
165 }
166 }
167
168 return StatusCode::SUCCESS;
169 }
170}
#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
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition AcceptData.h:134
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.