127 theVertexContainer->setStore(theVertexAuxContainer);
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");
134 const EventContext& ctx = Gaudi::Hive::currentContext();
136 std::vector<xAODVertex_pair> myxAODVertices;
138 std::vector<Trk::TrackToVtxLink*> myTrackToVtxLinks;
141 std::vector<Trk::ITrackLink*> origTracks = trackVector;
142 std::vector<Trk::ITrackLink*> seedTracks = trackVector;
145 std::map<Trk::ITrackLink*, Trk::TrackToVtxLink*> TrackLinkOf;
153 TrackLinkOf[trkIter] = newTrkToVtxLink;
154 myTrackToVtxLinks.push_back(newTrkToVtxLink);
158 unsigned int seedtracknumber = seedTracks.size();
161 if (seedtracknumber == 0) {
ATH_MSG_DEBUG(
"New iteration. No tracks available after track selection for seeding."); }
164 ATH_MSG_DEBUG(
"Iteration number " << iteration <<
" and tracks left for seeding " << seedtracknumber);
166 std::vector<const Trk::TrackParameters*> perigeeList;
168 perigeeList.reserve(seedTracks.size());
169for (
const Trk::ITrackLink* seedtrkAtVtxIter : seedTracks) { perigeeList.push_back((seedtrkAtVtxIter)->parameters()); }
173 std::unique_ptr<Trk::IMode3dInfo> info;
177 ATH_MSG_DEBUG(
"Found seed at x: " << seedVertex.x() <<
" at y: " << seedVertex.y() <<
" at z: " << seedVertex.z());
180 theVertexContainer->
push_back(seededxAODVertex);
183 looseConstraintCovariance.setIdentity();
184 looseConstraintCovariance = looseConstraintCovariance * 1e+8;
186 seededxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
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");
196 looseConstraintCovariance.setIdentity();
197 looseConstraintCovariance = looseConstraintCovariance * 1e+8;
199 constraintVertex->makePrivateStore();
206 actualCandidate->makePrivateStore();
209 MvfFitInfo(*actualCandidate) =
211 isInitialized(*actualCandidate) =
false;
212 std::vector<Trk::VxTrackAtVertex*> vectorOfTracks(0);
213 VTAV(*actualCandidate) = std::move(vectorOfTracks);
220 std::vector<xAOD::Vertex*>* actualvtxlink = actualLink->
vertices();
222 actualvtxlink->push_back(actualCandidate);
227 ATH_MSG_DEBUG(
" Considering n. " << VTAV(*actualCandidate).size() <<
" tracks for the fit. ");
229 if (VTAV(*actualCandidate).size() < 2) {
230 ATH_MSG_DEBUG(
"No tracks found near seed, while at least two tracks were expected.");
232 if (VTAV.isAvailable(*actualCandidate)) {
233 for (
auto *tav : VTAV(*actualCandidate)) {
234 if (tav ==
nullptr)
continue;
240 VTAV(*actualCandidate).clear();
242 if (MvfFitInfo.isAvailable(*actualCandidate) && MvfFitInfo(*actualCandidate) !=
nullptr) {
243 delete MvfFitInfo(*actualCandidate);
244 MvfFitInfo(*actualCandidate) =
nullptr;
246 delete actualCandidate;
247 actualCandidate =
nullptr;
256 ATH_MSG_DEBUG(
"Deleting tracks with really good fit to vertex from seeding tracks.");
259 ATH_MSG_DEBUG(
"Found and deleted " << nFound <<
" tracks from seeding tracks.");
261 ATH_MSG_DEBUG(
"All tracks used for fitting came from fiting tracks, removing closest from seeding.");
269 ATH_MSG_DEBUG(
"You still have not removed any tracks from seeds! Aborting.");
274 bool goodVertex =
checkFit(actualCandidate);
277 ATH_MSG_DEBUG(
"Bad vertex, deleting the vertex and clearing all pointers");
280 if (VTAV.isAvailable(*actualCandidate)) {
281 for (
auto *tav : VTAV(*actualCandidate)) {
282 if (tav ==
nullptr)
continue;
288 VTAV(*actualCandidate).clear();
290 if (MvfFitInfo.isAvailable(*actualCandidate) && MvfFitInfo(*actualCandidate) !=
nullptr) {
291 delete MvfFitInfo(*actualCandidate);
292 MvfFitInfo(*actualCandidate) =
nullptr;
295 delete actualCandidate;
296 actualCandidate =
nullptr;
304 myxAODVertices.emplace_back(0, actualCandidate);
306 seedtracknumber = seedTracks.size();
311 <<
m_maxIterations <<
") reached; to reconstruct more vertices, set maxIterations to a higher value.");
314 ATH_MSG_DEBUG(
"Secondary vertex finding complete with " << iteration <<
" iterations and " << myxAODVertices.size()
315 <<
" vertices found.");
317 for (
const xAODVertex_pair& vtxIter : myxAODVertices) {
327 std::vector<Trk::VxTrackAtVertex>* tracksOfVertex = &(cand->
vxTrackAtVertex());
328 tracksOfVertex->clear();
331 if ((*MVFtrkIter).initialPerigee()) { (*MVFtrkIter).setPerigeeAtVertex(((*MVFtrkIter).initialPerigee())->clone()); }
332 tracksOfVertex->push_back(*MVFtrkIter);
336 for (
const xAODVertex_pair& vtxIter : myxAODVertices) {
342 MVFtrkIter =
nullptr;
345 delete MvfFitInfo(*cand);
351 std::vector<Trk::VxTrackAtVertex>* myVxTracksAtVtx = &((vxIter)->vxTrackAtVertex());
352 if (!myVxTracksAtVtx)
continue;
361 if (linkToXAODTP) { (vxIter)->addTrackAtVertex(*linkToXAODTP, (tracksIter).weight()); }
364 int ntrk = myVxTracksAtVtx->size();
379 if (!theVertexContainer->
empty()) {
384 theVertexContainer->
push_back(dummyxAODVertex);
387 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
394 else if (theVertexContainer->
empty()) {
396 theVertexContainer->
push_back(dummyxAODVertex);
399 looseConstraintCovariance.setIdentity();
400 looseConstraintCovariance = looseConstraintCovariance * 1e+8;
402 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
411 for (
unsigned int i = 0; i < theVertexContainer->
size(); i++) {
423 ATH_MSG_DEBUG(
" Vtx: " << i <<
" x= " << (*theVertexContainer)[i]->position().
x() <<
" y= "
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());
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);
433 return std::make_pair(theVertexContainer, theVertexAuxContainer);