place all tracks in the origTrack vector and initially all in the seedTrack vector
122 {
125 theVertexContainer->setStore(theVertexAuxContainer);
126
128 static const xAOD::Vertex::Decorator<Trk::MvfFitInfo*> MvfFitInfo("MvfFitInfo");
129 static const xAOD::Vertex::Decorator<bool> isInitialized("isInitialized");
130 static const xAOD::Vertex::Decorator<std::vector<Trk::VxTrackAtVertex*>> VTAV("VTAV");
131
132 const EventContext& ctx = Gaudi::Hive::currentContext();
133
134 std::vector<xAODVertex_pair> myxAODVertices;
135
136 std::vector<Trk::TrackToVtxLink*> myTrackToVtxLinks;
137
139 std::vector<Trk::ITrackLink*> origTracks = trackVector;
140 std::vector<Trk::ITrackLink*> seedTracks = trackVector;
141
142
143 std::map<Trk::ITrackLink*, Trk::TrackToVtxLink*> TrackLinkOf;
144
145
146
147
148 for (Trk::ITrackLink* trkIter : origTracks) {
149 Trk::TrackToVtxLink* newTrkToVtxLink(new Trk::TrackToVtxLink(new std::vector<xAOD::Vertex*>));
150
151 TrackLinkOf[trkIter] = newTrkToVtxLink;
152 myTrackToVtxLinks.push_back(newTrkToVtxLink);
153 }
154
155 int iteration = 0;
156 unsigned int seedtracknumber = seedTracks.size();
157
158 do {
159 if (seedtracknumber == 0) {
ATH_MSG_DEBUG(
"New iteration. No tracks available after track selection for seeding."); }
160
161 iteration += 1;
162 ATH_MSG_DEBUG(
"Iteration number " << iteration <<
" and tracks left for seeding " << seedtracknumber);
163
164 std::vector<const Trk::TrackParameters*> perigeeList;
165
166 perigeeList.reserve(seedTracks.size());
167for (
const Trk::ITrackLink* seedtrkAtVtxIter : seedTracks) { perigeeList.push_back((seedtrkAtVtxIter)->
parameters()); }
168
170
171 std::unique_ptr<Trk::IMode3dInfo>
info;
174
175 ATH_MSG_DEBUG(
"Found seed at x: " << seedVertex.x() <<
" at y: " << seedVertex.y() <<
" at z: " << seedVertex.z());
176
178 theVertexContainer->
push_back(seededxAODVertex);
181 looseConstraintCovariance.setIdentity();
182 looseConstraintCovariance = looseConstraintCovariance * 1
e+8;
184 seededxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
186
187 if (seedVertex.z() == 0) {
188 ATH_MSG_DEBUG(
"No good seed found: no further vertices in event");
189 ATH_MSG_DEBUG(
"Number of input tracks: " << perigeeList.size() <<
", but no good seed returned");
190 break;
191 }
192
194 looseConstraintCovariance.setIdentity();
195 looseConstraintCovariance = looseConstraintCovariance * 1
e+8;
197 constraintVertex->makePrivateStore();
202
204 actualCandidate->makePrivateStore();
206
207 MvfFitInfo(*actualCandidate) =
209 isInitialized(*actualCandidate) = false;
210 std::vector<Trk::VxTrackAtVertex*> vectorOfTracks(0);
211 VTAV(*actualCandidate) = vectorOfTracks;
212
213 for (Trk::ITrackLink* trkIter : origTracks) {
214
217 Trk::TrackToVtxLink* actualLink = TrackLinkOf[trkIter];
218 std::vector<xAOD::Vertex*>* actualvtxlink = actualLink->
vertices();
219
220 actualvtxlink->push_back(actualCandidate);
221 VTAV(*actualCandidate).push_back(new Trk::MVFVxTrackAtVertex((trkIter)->clone(), actualLink));
222 }
223 }
224
225 ATH_MSG_DEBUG(
" Considering n. " << VTAV(*actualCandidate).size() <<
" tracks for the fit. ");
226
227 if (VTAV(*actualCandidate).size() < 2) {
228 ATH_MSG_DEBUG(
"No tracks found near seed, while at least two tracks were expected.");
229
230 if (VTAV.isAvailable(*actualCandidate)) {
231 for (auto *tav : VTAV(*actualCandidate)) {
232 if (tav == nullptr) continue;
233
234 (static_cast<Trk::MVFVxTrackAtVertex*>(tav))->setLinkToVertices(nullptr);
235 delete tav;
236 tav = nullptr;
237 }
238 VTAV(*actualCandidate).clear();
239 }
240 if (MvfFitInfo.isAvailable(*actualCandidate) && MvfFitInfo(*actualCandidate) != nullptr) {
241 delete MvfFitInfo(*actualCandidate);
242 MvfFitInfo(*actualCandidate) = nullptr;
243 }
244 delete actualCandidate;
245 actualCandidate = nullptr;
246
247 break;
248 }
249
251
253
254 ATH_MSG_DEBUG(
"Deleting tracks with really good fit to vertex from seeding tracks.");
256
257 ATH_MSG_DEBUG(
"Found and deleted " << nFound <<
" tracks from seeding tracks.");
258 if (nFound == 0) {
259 ATH_MSG_DEBUG(
"All tracks used for fitting came from fiting tracks, removing closest from seeding.");
260
261
262
264 }
265
266 if (nFound == 0) {
267 ATH_MSG_DEBUG(
"You still have not removed any tracks from seeds! Aborting.");
268 break;
269 }
270
272 bool goodVertex =
checkFit(actualCandidate);
273
274 if (!goodVertex) {
275 ATH_MSG_DEBUG(
"Bad vertex, deleting the vertex and clearing all pointers");
276
278
279 if (actualCandidate) {
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.