place all tracks in the origTrack vector and initially all in the seedTrack vector
124 {
127 theVertexContainer->setStore(theVertexAuxContainer);
128
130 static const xAOD::Vertex::Decorator<Trk::MvfFitInfo*> MvfFitInfo("MvfFitInfo");
131 static const xAOD::Vertex::Decorator<bool> isInitialized("isInitialized");
132 static const xAOD::Vertex::Decorator<std::vector<Trk::VxTrackAtVertex*>> VTAV("VTAV");
133
134 const EventContext& ctx = Gaudi::Hive::currentContext();
135
136 std::vector<xAODVertex_pair> myxAODVertices;
137
138 std::vector<Trk::TrackToVtxLink*> myTrackToVtxLinks;
139
141 std::vector<Trk::ITrackLink*> origTracks = trackVector;
142 std::vector<Trk::ITrackLink*> seedTracks = trackVector;
143
144
145 std::map<Trk::ITrackLink*, Trk::TrackToVtxLink*> TrackLinkOf;
146
147
148
149
150 for (Trk::ITrackLink* trkIter : origTracks) {
151 Trk::TrackToVtxLink* newTrkToVtxLink(new Trk::TrackToVtxLink(new std::vector<xAOD::Vertex*>));
152
153 TrackLinkOf[trkIter] = newTrkToVtxLink;
154 myTrackToVtxLinks.push_back(newTrkToVtxLink);
155 }
156
157 int iteration = 0;
158 unsigned int seedtracknumber = seedTracks.size();
159
160 do {
161 if (seedtracknumber == 0) {
ATH_MSG_DEBUG(
"New iteration. No tracks available after track selection for seeding."); }
162
163 iteration += 1;
164 ATH_MSG_DEBUG(
"Iteration number " << iteration <<
" and tracks left for seeding " << seedtracknumber);
165
166 std::vector<const Trk::TrackParameters*> perigeeList;
167
168 perigeeList.reserve(seedTracks.size());
169for (
const Trk::ITrackLink* seedtrkAtVtxIter : seedTracks) { perigeeList.push_back((seedtrkAtVtxIter)->
parameters()); }
170
172
173 std::unique_ptr<Trk::IMode3dInfo>
info;
176
177 ATH_MSG_DEBUG(
"Found seed at x: " << seedVertex.x() <<
" at y: " << seedVertex.y() <<
" at z: " << seedVertex.z());
178
180 theVertexContainer->
push_back(seededxAODVertex);
183 looseConstraintCovariance.setIdentity();
184 looseConstraintCovariance = looseConstraintCovariance * 1
e+8;
186 seededxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
188
189 if (seedVertex.z() == 0) {
190 ATH_MSG_DEBUG(
"No good seed found: no further vertices in event");
191 ATH_MSG_DEBUG(
"Number of input tracks: " << perigeeList.size() <<
", but no good seed returned");
192 break;
193 }
194
196 looseConstraintCovariance.setIdentity();
197 looseConstraintCovariance = looseConstraintCovariance * 1
e+8;
199 constraintVertex->makePrivateStore();
204
206 actualCandidate->makePrivateStore();
208
209 MvfFitInfo(*actualCandidate) =
211 isInitialized(*actualCandidate) = false;
212 std::vector<Trk::VxTrackAtVertex*> vectorOfTracks(0);
213 VTAV(*actualCandidate) = std::move(vectorOfTracks);
214
215 for (Trk::ITrackLink* trkIter : origTracks) {
216
219 Trk::TrackToVtxLink* actualLink = TrackLinkOf[trkIter];
220 std::vector<xAOD::Vertex*>* actualvtxlink = actualLink->
vertices();
221
222 actualvtxlink->push_back(actualCandidate);
223 VTAV(*actualCandidate).push_back(new Trk::MVFVxTrackAtVertex((trkIter)->clone(), actualLink));
224 }
225 }
226
227 ATH_MSG_DEBUG(
" Considering n. " << VTAV(*actualCandidate).size() <<
" tracks for the fit. ");
228
229 if (VTAV(*actualCandidate).size() < 2) {
230 ATH_MSG_DEBUG(
"No tracks found near seed, while at least two tracks were expected.");
231
232 if (VTAV.isAvailable(*actualCandidate)) {
233 for (auto *tav : VTAV(*actualCandidate)) {
234 if (tav == nullptr) continue;
235
236 (static_cast<Trk::MVFVxTrackAtVertex*>(tav))->setLinkToVertices(nullptr);
237 delete tav;
238 tav = nullptr;
239 }
240 VTAV(*actualCandidate).clear();
241 }
242 if (MvfFitInfo.isAvailable(*actualCandidate) && MvfFitInfo(*actualCandidate) != nullptr) {
243 delete MvfFitInfo(*actualCandidate);
244 MvfFitInfo(*actualCandidate) = nullptr;
245 }
246 delete actualCandidate;
247 actualCandidate = nullptr;
248
249 break;
250 }
251
253
255
256 ATH_MSG_DEBUG(
"Deleting tracks with really good fit to vertex from seeding tracks.");
258
259 ATH_MSG_DEBUG(
"Found and deleted " << nFound <<
" tracks from seeding tracks.");
260 if (nFound == 0) {
261 ATH_MSG_DEBUG(
"All tracks used for fitting came from fiting tracks, removing closest from seeding.");
262
263
264
266 }
267
268 if (nFound == 0) {
269 ATH_MSG_DEBUG(
"You still have not removed any tracks from seeds! Aborting.");
270 break;
271 }
272
274 bool goodVertex =
checkFit(actualCandidate);
275
276 if (!goodVertex) {
277 ATH_MSG_DEBUG(
"Bad vertex, deleting the vertex and clearing all pointers");
279
280 if (VTAV.isAvailable(*actualCandidate)) {
281 for (auto *tav : VTAV(*actualCandidate)) {
282 if (tav == nullptr) continue;
283
284 (static_cast<Trk::MVFVxTrackAtVertex*>(tav))->setLinkToVertices(nullptr);
285 delete tav;
286 tav = nullptr;
287 }
288 VTAV(*actualCandidate).clear();
289 }
290 if (MvfFitInfo.isAvailable(*actualCandidate) && MvfFitInfo(*actualCandidate) != nullptr) {
291 delete MvfFitInfo(*actualCandidate);
292 MvfFitInfo(*actualCandidate) = nullptr;
293 }
294
295 delete actualCandidate;
296 actualCandidate = nullptr;
297
298
299 } else {
301
304 myxAODVertices.emplace_back(0, actualCandidate);
305 }
306 seedtracknumber = seedTracks.size();
308
311 <<
m_maxIterations <<
") reached; to reconstruct more vertices, set maxIterations to a higher value.");
312 }
313
314 ATH_MSG_DEBUG(
"Secondary vertex finding complete with " << iteration <<
" iterations and " << myxAODVertices.size()
315 << " vertices found.");
316
317 for (const xAODVertex_pair& vtxIter : myxAODVertices) {
319
326
327 std::vector<Trk::VxTrackAtVertex>* tracksOfVertex = &(cand->
vxTrackAtVertex());
328 tracksOfVertex->clear();
329
330 for (Trk::VxTrackAtVertex* MVFtrkIter : VTAV(*fittedVert)) {
331 if ((*MVFtrkIter).initialPerigee()) { (*MVFtrkIter).setPerigeeAtVertex(((*MVFtrkIter).initialPerigee())->clone()); }
332 tracksOfVertex->push_back(*MVFtrkIter);
333 }
334 }
335
336 for (const xAODVertex_pair& vtxIter : myxAODVertices) {
338
339 for (Trk::VxTrackAtVertex* MVFtrkIter : VTAV(*cand)) {
340 (static_cast<Trk::MVFVxTrackAtVertex*>(MVFtrkIter))->setLinkToVertices(nullptr);
341 delete MVFtrkIter;
342 MVFtrkIter = nullptr;
343 }
344
345 delete MvfFitInfo(*cand);
346 }
347
349
351 std::vector<Trk::VxTrackAtVertex>* myVxTracksAtVtx = &((vxIter)->vxTrackAtVertex());
352 if (!myVxTracksAtVtx) continue;
353
354 for (Trk::VxTrackAtVertex& tracksIter : *myVxTracksAtVtx) {
355 Trk::LinkToXAODTrackParticle* linkToXAODTP = nullptr;
356 Trk::ITrackLink* tmpLink = (tracksIter).trackOrParticleLink();
358 linkToXAODTP = static_cast<Trk::LinkToXAODTrackParticle*>(tmpLink);
359 }
360
361 if (linkToXAODTP) { (vxIter)->addTrackAtVertex(*linkToXAODTP, (tracksIter).
weight()); }
362 }
363
364 int ntrk = myVxTracksAtVtx->size();
365 if (ntrk == 2) {
367
369 if (isV0) {
372 }
373 }
374 }
375
376
377 for (Trk::TrackToVtxLink* iterator : myTrackToVtxLinks) {
delete iterator; }
378
379 if (!theVertexContainer->empty()) {
384 theVertexContainer->push_back(dummyxAODVertex);
387 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
389 } else {
391 }
392 }
393
394 else if (theVertexContainer->empty()) {
396 theVertexContainer->push_back(dummyxAODVertex);
399 looseConstraintCovariance.setIdentity();
400 looseConstraintCovariance = looseConstraintCovariance * 1
e+8;
402 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
404 }
405
406 int noVtx = 0;
407 int kinkVtx = 0;
408 int notSpec = 0;
409 int secVtx = 0;
410 int V0vtx = 0;
411 for (
unsigned int i = 0;
i < theVertexContainer->size();
i++) {
414 switch (vtxType) {
421 }
422
424 << (*theVertexContainer)[i]->
position().
y() <<
" z= " << (*theVertexContainer)[i]->
position().
z()
425 <<
" ntracks= " << (*theVertexContainer)[i]->vxTrackAtVertex().
size() <<
" chi2= "
426 << (*theVertexContainer)[i]->
chiSquared() <<
" #dof = " << (*theVertexContainer)[i]->numberDoF());
427 }
428
429 ATH_MSG_DEBUG(
"Done finding " << theVertexContainer->size() <<
" vertices and cleaning the container.");
430 ATH_MSG_DEBUG(
"Seeds good/bad/all : " << noVtx <<
"/" << kinkVtx <<
"/" << notSpec);
431 ATH_MSG_DEBUG(
"'Good' secondaries : " << secVtx <<
" and V0: " << V0vtx);
432
433 return std::make_pair(theVertexContainer, theVertexAuxContainer);
434 }
size_t size() const
Number of registered mappings.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
virtual ITrackLinkType type() const =0
return the type
const std::vector< xAOD::Vertex * > * vertices(void) const
Const access to the vertex list.
void setCovariancePosition(const AmgSymMatrix(3)&covariancePosition)
Sets the vertex covariance matrix.
void setVertexType(VxType::VertexType vType)
Set the type of the vertex.
void setPosition(const Amg::Vector3D &position)
Sets the 3-position.
float chiSquared() const
Returns the of the vertex fit as float.
std::vector< Trk::VxTrackAtVertex > & vxTrackAtVertex()
Non-const access to the VxTrackAtVertex vector.
void setFitQuality(float chiSquared, float numberDoF)
Set the 'Fit Quality' information.
const Amg::Vector3D & position() const
Returns the 3-pos.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 3, 1 > Vector3D
float chiSquared(const U &p)
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.
@ V0Vtx
Vertex from V0 decay.
@ NotSpecified
Default value, no explicit type set.
@ SecVtx
Secondary vertex.
@ NoVtx
Dummy vertex. TrackParticle was not used in vertex fit.
VertexAuxContainer_v1 VertexAuxContainer
Definition of the current jet auxiliary container.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.