125 theVertexContainer->setStore(theVertexAuxContainer);
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");
132 const EventContext& ctx = Gaudi::Hive::currentContext();
134 std::vector<xAODVertex_pair> myxAODVertices;
136 std::vector<Trk::TrackToVtxLink*> myTrackToVtxLinks;
139 std::vector<Trk::ITrackLink*> origTracks = trackVector;
140 std::vector<Trk::ITrackLink*> seedTracks = trackVector;
143 std::map<Trk::ITrackLink*, Trk::TrackToVtxLink*> TrackLinkOf;
151 TrackLinkOf[trkIter] = newTrkToVtxLink;
152 myTrackToVtxLinks.push_back(newTrkToVtxLink);
156 unsigned int seedtracknumber = seedTracks.size();
159 if (seedtracknumber == 0) {
ATH_MSG_DEBUG(
"New iteration. No tracks available after track selection for seeding."); }
162 ATH_MSG_DEBUG(
"Iteration number " << iteration <<
" and tracks left for seeding " << seedtracknumber);
164 std::vector<const Trk::TrackParameters*> perigeeList;
166 perigeeList.reserve(seedTracks.size());
167for (
const Trk::ITrackLink* seedtrkAtVtxIter : seedTracks) { perigeeList.push_back((seedtrkAtVtxIter)->parameters()); }
171 std::unique_ptr<Trk::IMode3dInfo> info;
175 ATH_MSG_DEBUG(
"Found seed at x: " << seedVertex.x() <<
" at y: " << seedVertex.y() <<
" at z: " << seedVertex.z());
178 theVertexContainer->
push_back(seededxAODVertex);
181 looseConstraintCovariance.setIdentity();
182 looseConstraintCovariance = looseConstraintCovariance * 1e+8;
184 seededxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
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");
194 looseConstraintCovariance.setIdentity();
195 looseConstraintCovariance = looseConstraintCovariance * 1e+8;
197 constraintVertex->makePrivateStore();
204 actualCandidate->makePrivateStore();
207 MvfFitInfo(*actualCandidate) =
209 isInitialized(*actualCandidate) =
false;
210 std::vector<Trk::VxTrackAtVertex*> vectorOfTracks(0);
211 VTAV(*actualCandidate) = vectorOfTracks;
218 std::vector<xAOD::Vertex*>* actualvtxlink = actualLink->
vertices();
220 actualvtxlink->push_back(actualCandidate);
225 ATH_MSG_DEBUG(
" Considering n. " << VTAV(*actualCandidate).size() <<
" tracks for the fit. ");
227 if (VTAV(*actualCandidate).size() < 2) {
228 ATH_MSG_DEBUG(
"No tracks found near seed, while at least two tracks were expected.");
230 if (VTAV.isAvailable(*actualCandidate)) {
231 for (
auto *tav : VTAV(*actualCandidate)) {
232 if (tav ==
nullptr)
continue;
238 VTAV(*actualCandidate).clear();
240 if (MvfFitInfo.isAvailable(*actualCandidate) && MvfFitInfo(*actualCandidate) !=
nullptr) {
241 delete MvfFitInfo(*actualCandidate);
242 MvfFitInfo(*actualCandidate) =
nullptr;
244 delete actualCandidate;
245 actualCandidate =
nullptr;
254 ATH_MSG_DEBUG(
"Deleting tracks with really good fit to vertex from seeding tracks.");
257 ATH_MSG_DEBUG(
"Found and deleted " << nFound <<
" tracks from seeding tracks.");
259 ATH_MSG_DEBUG(
"All tracks used for fitting came from fiting tracks, removing closest from seeding.");
267 ATH_MSG_DEBUG(
"You still have not removed any tracks from seeds! Aborting.");
272 bool goodVertex =
checkFit(actualCandidate);
275 ATH_MSG_DEBUG(
"Bad vertex, deleting the vertex and clearing all pointers");
279 if (actualCandidate) {
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);