30 , m_maxDistToLinPoint(0.5)
31 , m_initialError(0.0001)
32 , m_doSmoothing(false)
34 , m_maxRelativeShift(0.01)
42 declareInterface<AdaptiveMultiVertexFitter>(
this);
59 return StatusCode::SUCCESS;
66 return StatusCode::SUCCESS;
81 std::map<xAOD::Vertex*, Amg::Vector3D> oldpositions;
82 std::map<xAOD::Vertex*, bool> relinearizations;
89 bool shiftIsSmall(
true);
92 for (
auto* pThisVertex : allVertices) {
97 ATH_MSG_DEBUG(
"Now considering candidate with ptr " << pThisVertex);
98 relinearizations[pThisVertex] =
false;
99 if (isInitialized(*pThisVertex)) {
100 ATH_MSG_DEBUG(
"vertex position z: " << (*pThisVertex).position()[2]);
101 oldpositions[pThisVertex] = pThisVertex->position();
103 isInitialized(*pThisVertex) =
true;
104 ATH_MSG_DEBUG(
"Candidate has no position so far: using as old position "
111 oldpositions[pThisVertex] = *(MvfFitInfo(*pThisVertex)->seedVertex());
113 if (MvfFitInfo(*pThisVertex)->linearizationVertex() ==
117 " Candidate has no linearization point...CRASHING now!!! ");
119 if ((oldpositions[pThisVertex] -
120 *MvfFitInfo(*pThisVertex)->linearizationVertex())
123 relinearizations[pThisVertex] =
true;
126 ATH_MSG_DEBUG(
"Setting the Vertex to the initial constraint");
128 pThisVertex->setPosition(
129 MvfFitInfo(*pThisVertex)->constraintVertex()->position());
130 pThisVertex->setCovariancePosition(
131 MvfFitInfo(*pThisVertex)->constraintVertex()->covariancePosition());
132 pThisVertex->setFitQuality(
133 MvfFitInfo(*pThisVertex)->constraintVertex()->chiSquared(),
134 MvfFitInfo(*pThisVertex)->constraintVertex()->numberDoF());
135 pThisVertex->setCovariancePosition(
136 pThisVertex->covariancePosition() * 1. /
138 ATH_MSG_DEBUG(
"Running TrackCompatibilityEstimator on each track");
140 const auto& theseTrackPointersAtVtx = VTAV(*pThisVertex);
142 for (
const auto& pThisTrack : theseTrackPointersAtVtx) {
144 << theseTrackPointersAtVtx.size());
147 if (not pThisTrack->ImpactPoint3dAtaPlane()) {
149 *pThisTrack, *MvfFitInfo(*pThisVertex)->linearizationVertex());
152 "Adding compatibility to vertex information failed. Newton "
153 "distance finder didn't converge...");
158 oldpositions[pThisVertex]);
165 for (
auto* pThisVertex : allVertices) {
173 std::vector<Trk::VxTrackAtVertex>* tracksOfVertex =
174 &(pThisVertex->vxTrackAtVertex());
175 tracksOfVertex->clear();
177 const auto& theseTrackPointersAtVtx = VTAV(*pThisVertex);
179 "Beginning lin&update of vertex with pointer: " << pThisVertex);
180 for (
const auto& pThisTrack : theseTrackPointersAtVtx) {
182 ATH_MSG_DEBUG(
"Calling collect weight for track " << pThisTrack);
183 const std::vector<double>& allweights(
185 ->linkToVertices()));
187 << pThisTrack->vtxCompatibility());
189 astate, pThisTrack->vtxCompatibility(), allweights));
192 astate, pThisTrack->vtxCompatibility(), allweights));
196 if (not pThisTrack->linState()) {
200 oldpositions[pThisVertex]);
201 }
else if (relinearizations[pThisVertex]) {
204 oldpositions[pThisVertex]);
205 MvfFitInfo(*pThisVertex)
206 ->setLinearizationVertex(
211 << pThisTrack <<
" to the vertex " << pThisVertex);
213 tracksOfVertex->push_back(*pThisTrack);
221 ATH_MSG_DEBUG(
"Vertex pointer " << pThisVertex <<
" New position x: "
222 << pThisVertex->position().x()
223 <<
" y: " << pThisVertex->position().y()
224 <<
" z: " << pThisVertex->position().z());
235 for (
const auto& pThisVertex : allVertices) {
236 vrtpos[0] = oldpositions[pThisVertex][0] - pThisVertex->position()[0];
237 vrtpos[1] = oldpositions[pThisVertex][1] - pThisVertex->position()[1];
238 vrtpos[2] = oldpositions[pThisVertex][2] - pThisVertex->position()[2];
240 weightMatrixVertex = pThisVertex->covariancePosition().
inverse();
241 double relativeShift = vrtpos.
dot(weightMatrixVertex * vrtpos);
243 shiftIsSmall =
false;
255 "In principle the big multivertex fit step is finished now...");
261 return pV->vxTrackAtVertexAvailable() and
262 not(pV->vxTrackAtVertex()).empty();
264 for (
const auto& pThisVertex : allVertices) {
265 if (trackAvailable(pThisVertex)) {
270 for (
auto* pThisVertex : allVertices) {
271 const auto& theseTrackPointersAtVtx = VTAV(*pThisVertex);
272 for (
const auto& pTrack : theseTrackPointersAtVtx) {
273 if (pTrack->initialPerigee())
274 pTrack->setPerigeeAtVertex((pTrack->initialPerigee())->clone());
284 ATH_MSG_DEBUG(
"Collecting weights for tracklink " << &tracklink);
290 const auto& theseVertices = *(tracklink.
vertices());
291 std::vector<double> myvector;
292 myvector.reserve(theseVertices.size());
293 for (
const auto& pThisVertex : theseVertices) {
297 const auto& trackPointersForThisVertex = VTAV(*pThisVertex);
298 for (
const auto& pThisTrack : trackPointersForThisVertex) {
300 ->linkToVertices() == &tracklink) {
302 << pThisTrack->vtxCompatibility() <<
" for track "
304 myvector.push_back(pThisTrack->vtxCompatibility());
323 if (VTAV(*newvertex).empty()) {
325 "The candidate you're adding has no tracks: please fix the problem");
327 std::vector<xAOD::Vertex*>
329 allVerticesToFit.reserve(10);
333 std::vector<xAOD::Vertex*> addedVerticesLastIteration;
334 std::vector<xAOD::Vertex*> addedVerticesNewIteration;
335 addedVerticesLastIteration.push_back(newvertex);
337 for (
const auto& vertexIterator : addedVerticesLastIteration) {
340 const auto& vertexTracksAtVertex = VTAV(*vertexIterator);
341 for (
const auto& thisTrack : vertexTracksAtVertex) {
342 const auto& pTheseVertices =
346 for (
const auto& thisVertex : *pTheseVertices) {
349 allVerticesToFit.push_back(thisVertex);
350 if (thisVertex != vertexIterator) {
351 addedVerticesNewIteration.push_back(thisVertex);
358 addedVerticesLastIteration = addedVerticesNewIteration;
359 addedVerticesNewIteration.clear();
360 }
while (not addedVerticesLastIteration.empty());
363 fit(allVerticesToFit);
379 auto addImpactPoint = [
this, seedPoint](
const auto& thisVxTrack) {
383 const auto& vertexTracksAtVertex = VTAV(*newvertex);
385 const bool success = std::all_of(
386 vertexTracksAtVertex.begin(), vertexTracksAtVertex.end(), addImpactPoint);
388 ATH_MSG_DEBUG(
"Adding compatibility to vertex information failed. Newton "
389 "distance finder didn't converge...");
396 const std::vector<xAOD::Vertex*>& previousVertices)
398 return (
std::find(previousVertices.begin(), previousVertices.end(),
vertex) !=
399 previousVertices.end());