ATLAS Offline Software
Loading...
Searching...
No Matches
ZScanSeedFinder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5/*********************************************************************
6 ZScanSeedFinder.cxx - Description in header file
7*********************************************************************/
8
10
12
14#include "TrkTrack/Track.h"
16
17//Amg
19
20#include <algorithm>
21#include <cmath>
22
23namespace Trk
24{
25
26 ZScanSeedFinder::ZScanSeedFinder(const std::string& t, const std::string& n, const IInterface* p) :
27 base_class(t,n,p),
31 m_useLogPt(true),
32 m_minPt(400.),
33 m_usePt(false),
34 m_expPt(1.),
35 m_cacheWeights(true)
36 {
37 declareProperty("disableAllWeights", m_disableAllWeights);
38 declareProperty("constrainttemp", m_constrainttemp);
39 declareProperty("constraintcutoff", m_constraintcutoff);
40 declareProperty("UsePt", m_usePt);
41 declareProperty("ExpPt", m_expPt);
42 declareProperty("UseLogPt", m_useLogPt);
43 declareProperty("MinPt", m_minPt);
44 declareProperty("CacheWeights", m_cacheWeights);
45 }
46
47
49 = default;
50
51
53 {
54 ATH_CHECK( m_eventInfoKey.initialize() );
55 if ( m_mode1dfinder.retrieve().isFailure() ) {
56 ATH_MSG_FATAL("Failed to retrieve tool " << m_mode1dfinder);
57 return StatusCode::FAILURE;
58 } else if ( m_IPEstimator.retrieve().isFailure() ) {
59 ATH_MSG_FATAL("Failed to retrieve tool " << m_IPEstimator);
60 } else {
61 ATH_MSG_INFO("Retrieved tools " << m_mode1dfinder << " and " << m_IPEstimator);
62 }
63
64 if ( m_usePt && m_useLogPt )
65 {
66 ATH_MSG_FATAL("At most one of Pt and LogPt weighting may be selected");
67 return StatusCode::FAILURE;
68 }
69
70 ATH_MSG_DEBUG("Initialize successful");
71 return StatusCode::SUCCESS;
72 }
73
75 {
76 ATH_MSG_DEBUG("Finalize successful");
77 return StatusCode::SUCCESS;
78 }
79
80
81 Amg::Vector3D ZScanSeedFinder::findSeed(const std::vector<const Trk::Track*> & VectorTrk,const xAOD::Vertex * constraint) const {
82
83 //create perigees from track list
84 std::vector<const TrackParameters*> perigeeList;
85
86 std::vector<const Trk::Track*>::const_iterator begin=VectorTrk.begin();
87 std::vector<const Trk::Track*>::const_iterator end=VectorTrk.end();
88
89 for (std::vector<const Trk::Track*>::const_iterator iter=begin;
90 iter!=end;++iter)
91 {
92 if (std::isnan((*iter)->perigeeParameters()->parameters()[Trk::d0]))
93 {
94 continue;
95 }
96 perigeeList.push_back((*iter)->perigeeParameters());
97 }
98
99 //create seed from perigee list
100 return findSeed(perigeeList,constraint);
101
102 }
103
104 Amg::Vector3D ZScanSeedFinder::findSeed(const std::vector<const Trk::TrackParameters*> & perigeeList,const xAOD::Vertex * constraint) const {
105
106
107 double ZResult=0.;
108 std::vector<Trk::DoubleAndWeight> ZPositions;
109 if (m_cacheWeights) {
110 ZPositions = getPositionsCached (perigeeList, constraint);
111 }
112 else {
113 ZPositions = getPositionsUncached (perigeeList, constraint);
114 }
115
116 if ( !ZPositions.empty() )
117 {
118 ZResult=m_mode1dfinder->getMode(ZPositions);
119 ATH_MSG_DEBUG("Resulting mean Z position found: " << ZResult);
120 }
121 else
122 {
123 ATH_MSG_DEBUG("No tracks with sufficient weight; return z position = 0");
124 }
125
126 if (constraint)
127 {
128 return Amg::Vector3D(constraint->position().x(),constraint->position().y(),ZResult);
129 }
130 return Amg::Vector3D(0.,0.,ZResult);
131
132 }
133
134
135 std::vector<Trk::DoubleAndWeight>
136 ZScanSeedFinder::getPositionsUncached (const std::vector<const Trk::TrackParameters*> & perigeeList,
137 const xAOD::Vertex * constraint) const
138 {
139 std::vector<Trk::DoubleAndWeight> ZPositions;
140
141 for (const Trk::TrackParameters* i : perigeeList)
142 {
143 const Perigee* iTrk = dynamic_cast<const Trk::Perigee*>(i);
144 if (iTrk == nullptr)
145 {
146 ATH_MSG_WARNING("Neutrals not supported for seeding. Rejecting track...");
147 continue;
148 }
149
150 std::pair<double, double> z0AndWeight =
151 estimateWeight (*iTrk, constraint);
152 ATH_MSG_DEBUG("Found position z: " << z0AndWeight.first <<
153 " with weight " << z0AndWeight.second);
154
155 if (z0AndWeight.second >= 0.01)
156 {
157 ZPositions.push_back(z0AndWeight);
158 }
159 }
160
161 return ZPositions;
162 }
163
164
165 std::vector<Trk::DoubleAndWeight>
166 ZScanSeedFinder::getPositionsCached (const std::vector<const Trk::TrackParameters*> & perigeeList,
167 const xAOD::Vertex * constraint) const
168 {
169 const EventContext& ctx = Gaudi::Hive::currentContext();
170 Cache& cache = *m_cache;
171
172 Amg::Vector2D constraintkey;
173 if (constraint) {
174 constraintkey.x() = constraint->position().x();
175 constraintkey.y() = constraint->position().y();
176 }
177 else {
178 constraintkey.x() = std::numeric_limits<double>::max();
179 constraintkey.y() = std::numeric_limits<double>::min();
180 }
181
182 std::vector<Trk::DoubleAndWeight> ZPositions;
183
184 std::lock_guard<std::mutex> lock (cache.m_mutex);
185 if (ctx.evt() != cache.m_evt) {
186 cache.m_weightMap.clear();
187 }
188
189 for (const Trk::TrackParameters* i : perigeeList)
190 {
191 const Perigee* iTrk = dynamic_cast<const Trk::Perigee*>(i);
192 if (iTrk == nullptr)
193 {
194 ATH_MSG_WARNING("Neutrals not supported for seeding. Rejecting track...");
195 continue;
196 }
197
198 Cache::key_t key (*iTrk, constraintkey);
199 auto [it, flag] = cache.m_weightMap.try_emplace (key, Cache::value_t());
200 if (flag) {
201 it->second = estimateWeight (*iTrk, constraint);
202 ATH_MSG_DEBUG("Found position z: " << it->second.first <<
203 " with weight " << it->second.second);
204 }
205
206 if (it->second.second >= 0.01)
207 {
208 ZPositions.push_back (it->second);
209 }
210 }
211
212 return ZPositions;
213 }
214
215
219 std::pair<double, double>
221 const xAOD::Vertex* constraint) const
222 {
223 // protect against overflow in exponential function
224 static const double maxExpArg = log(std::numeric_limits<double>::max()/1.1);
225
226 std::unique_ptr<const Trk::ImpactParametersAndSigma> ipas;
227 if (constraint != nullptr && constraint->covariancePosition()(0,0)!=0) {
228 ipas = std::unique_ptr<const Trk::ImpactParametersAndSigma> (m_IPEstimator->estimate (&iTrk, constraint));
229 }
230
231 std::pair<double, double> z0AndWeight;
232 if (ipas != nullptr && ipas->sigmad0 > 0)
233 {
234 z0AndWeight.first = ipas->IPz0 + constraint->position().z();
235 double chi2IP = std::pow(ipas->IPd0/ipas->sigmad0, 2);
236 ATH_MSG_VERBOSE("d0 from tool: " << ipas->IPd0 << " error: " << ipas->sigmad0 << " chi2: " << chi2IP);
237 if ( !m_disableAllWeights )
238 {
239 z0AndWeight.second = 1./(1.+exp(std::min((chi2IP-m_constraintcutoff)/m_constrainttemp, maxExpArg)));
240 }
241 else
242 {
243 z0AndWeight.second = 1.;
244 }
245 }
246 else
247 {
248 if (constraint != nullptr) ATH_MSG_WARNING("Unable to compute impact parameter significance; setting IPWeight = 1");
249 z0AndWeight.first = iTrk.position()[Trk::z];
250 z0AndWeight.second = 1.;
251 }
252
253 // apply pT weighting as/if configured
255 {
256 double Pt = fabs(1./iTrk.parameters()[Trk::qOverP])*sin(iTrk.parameters()[Trk::theta]);
257 if ( m_usePt )
258 {
259 z0AndWeight.second *= std::pow(Pt, m_expPt);
260 }
261 else
262 {
263 z0AndWeight.second *= log(std::max(Pt / m_minPt, 1.001));
264 }
265 }
266
267 return z0AndWeight;
268 }
269
270
271 std::vector<Amg::Vector3D> ZScanSeedFinder::findMultiSeeds(const std::vector<const Trk::Track*>& /* vectorTrk */,const xAOD::Vertex * /* constraint */) const {
272
273 //implemented to satisfy inheritance but this algorithm only supports one seed at a time
274 ATH_MSG_WARNING("Multi-seeding requested but seed finder not able to operate in that mode, returning no seeds");
275 return std::vector<Amg::Vector3D>(0);
276
277 }
278
279
280 std::vector<Amg::Vector3D> ZScanSeedFinder::findMultiSeeds(const std::vector<const Trk::TrackParameters*>& /* perigeeList */,const xAOD::Vertex * /* constraint */) const {
281
282 //implemented to satisfy inheritance but this algorithm only supports one seed at a time
283 ATH_MSG_WARNING("Multi-seeding requested but seed finder not able to operate in that mode, returning no seeds");
284 return std::vector<Amg::Vector3D>(0);
285
286 }
287
288
289}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
const Amg::Vector3D & position() const
Access method for the position.
std::vector< Trk::DoubleAndWeight > getPositionsCached(const std::vector< const Trk::TrackParameters * > &perigeeList, const xAOD::Vertex *constraint) const
virtual StatusCode finalize() override
virtual StatusCode initialize() override
std::pair< double, double > estimateWeight(const Trk::Perigee &iTrk, const xAOD::Vertex *constraint) const
Estimate z-position and weight for one track.
std::vector< Trk::DoubleAndWeight > getPositionsUncached(const std::vector< const Trk::TrackParameters * > &perigeeList, const xAOD::Vertex *constraint) const
virtual std::vector< Amg::Vector3D > findMultiSeeds(const std::vector< const Trk::Track * > &vectorTrk, const xAOD::Vertex *constraint=0) const override final
Finds full vector of linearization points from a vector of tracks and returns it as an Amg::Vector3D ...
ToolHandle< IMode1dFinder > m_mode1dfinder
ZScanSeedFinder(const std::string &t, const std::string &n, const IInterface *p)
ToolHandle< ITrackToVertexIPEstimator > m_IPEstimator
virtual Amg::Vector3D findSeed(const std::vector< const Trk::Track * > &vectorTrk, const xAOD::Vertex *constraint=0) const override final
Finds a linearization point out of a vector of tracks and returns it as an Amg::Vector3D object.
virtual ~ZScanSeedFinder()
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
const Amg::Vector3D & position() const
Returns the 3-pos.
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ z
global position (cartesian)
Definition ParamDefs.h:57
@ theta
Definition ParamDefs.h:66
@ qOverP
perigee
Definition ParamDefs.h:67
@ d0
Definition ParamDefs.h:63
ParametersBase< TrackParametersDim, Charged > TrackParameters
Vertex_v1 Vertex
Define the latest version of the vertex class.
std::pair< double, double > value_t
EventContext::ContextEvt_t m_evt
std::pair< Trk::Perigee, Amg::Vector2D > key_t