diff --git a/Core/include/Acts/Vertexing/AMVFInfo.hpp b/Core/include/Acts/Vertexing/AMVFInfo.hpp index 534c72cdbab..2a18882e49a 100644 --- a/Core/include/Acts/Vertexing/AMVFInfo.hpp +++ b/Core/include/Acts/Vertexing/AMVFInfo.hpp @@ -21,15 +21,15 @@ template struct VertexInfo { VertexInfo() = default; - VertexInfo(const Acts::Vertex& constr, - const Acts::Vector4& pos) - : constraint(constr), - linPoint(pos), - oldPosition(pos), - seedPosition(pos) {} + VertexInfo(const Acts::Vertex& vtxSeed) + : seed(vtxSeed), + linPoint(vtxSeed.fullPosition()), + oldPosition(vtxSeed.fullPosition()) {} - // Vertex constraint - Acts::Vertex constraint; + // The seed position (i.e., the first estimate for the vertex position as + // obtained by the vertex seed finder). Its covariance matrix comes either + // from the vertex seeding or from a user-provided constraint. + Acts::Vertex seed; // Point where all associated tracks are linearized Acts::Vector4 linPoint{Acts::Vector4::Zero()}; @@ -37,10 +37,6 @@ struct VertexInfo { // Vertex position from the last iteration of the fit Acts::Vector4 oldPosition{Acts::Vector4::Zero()}; - // The seed position (i.e., the first estimate for the vertex position as - // obtained by the vertex seed finder) - Acts::Vector4 seedPosition{Acts::Vector4::Zero()}; - // If set to true, the associated tracks need to be relinearized at a more // recent vertex position bool relinearize = true; diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp index bb48156a703..1b62c4bf82c 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.hpp @@ -228,7 +228,6 @@ class AdaptiveMultiVertexFinder { /// vertex if desired /// /// @param trackVector All tracks to be used for seeding - /// @param currentConstraint Vertex constraint /// @param vertexingOptions Vertexing options /// @param seedFinderState The seed finder state /// @param removedSeedTracks Seed track that have been removed @@ -237,19 +236,17 @@ class AdaptiveMultiVertexFinder { /// @return The seed vertex Result> doSeeding( const std::vector& trackVector, - Vertex& currentConstraint, const VertexingOptions& vertexingOptions, SeedFinderState_t& seedFinderState, const std::vector& removedSeedTracks) const; - /// @brief Sets constraint vertex after seeding + /// @brief Sets the covariance matrix of the vertex seed /// - /// @param currentConstraint Vertex constraint - /// @param useVertexConstraintInFit Indicates whether constraint is used during vertex fit - /// @param seedVertex Seed vertex - void setConstraintAfterSeeding(Vertex& currentConstraint, - bool useVertexConstraintInFit, - Vertex& seedVertex) const; + /// @param seedVertex Seed vertex whose covariance matrix we set + /// @param vertexingOptions Vertexing options + void setSeedCovariance( + Vertex& seedVertex, + const VertexingOptions& vertexingOptions) const; /// @brief Calculates the IP significance of a track to a given vertex /// @@ -280,7 +277,6 @@ class AdaptiveMultiVertexFinder { /// seedTracks) /// @param seedTracks The seed tracks /// @param[out] vtx The vertex candidate - /// @param currentConstraint Vertex constraint /// @param[out] fitterState The vertex fitter state /// @param vertexingOptions Vertexing options /// @@ -288,8 +284,7 @@ class AdaptiveMultiVertexFinder { Result canRecoverFromNoCompatibleTracks( const std::vector& allTracks, const std::vector& seedTracks, - Vertex& vtx, const Vertex& currentConstraint, - FitterState_t& fitterState, + Vertex& vtx, FitterState_t& fitterState, const VertexingOptions& vertexingOptions) const; /// @brief Method that tries to prepare the vertex for the fit @@ -298,7 +293,6 @@ class AdaptiveMultiVertexFinder { /// seedTracks) /// @param seedTracks The seed tracks /// @param[out] vtx The vertex candidate - /// @param currentConstraint Vertex constraint /// @param[out] fitterState The vertex fitter state /// @param vertexingOptions Vertexing options /// @@ -306,8 +300,7 @@ class AdaptiveMultiVertexFinder { Result canPrepareVertexForFit( const std::vector& allTracks, const std::vector& seedTracks, - Vertex& vtx, const Vertex& currentConstraint, - FitterState_t& fitterState, + Vertex& vtx, FitterState_t& fitterState, const VertexingOptions& vertexingOptions) const; /// @brief Method that checks if vertex is a good vertex and if diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp index b506afd55d7..5fb478532f3 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFinder.ipp @@ -44,10 +44,9 @@ auto Acts::AdaptiveMultiVertexFinder::find( } else { searchTracks = seedTracks; } - Vertex currentConstraint = vertexingOptions.constraint; // Retrieve seed vertex from all remaining seedTracks - auto seedResult = doSeeding(seedTracks, currentConstraint, vertexingOptions, - seedFinderState, removedSeedTracks); + auto seedResult = doSeeding(seedTracks, vertexingOptions, seedFinderState, + removedSeedTracks); if (!seedResult.ok()) { return seedResult.error(); } @@ -71,9 +70,8 @@ auto Acts::AdaptiveMultiVertexFinder::find( // now after seed finding is done removedSeedTracks.clear(); - auto prepResult = canPrepareVertexForFit(searchTracks, seedTracks, - vtxCandidate, currentConstraint, - fitterState, vertexingOptions); + auto prepResult = canPrepareVertexForFit( + searchTracks, seedTracks, vtxCandidate, fitterState, vertexingOptions); if (!prepResult.ok()) { return prepResult.error(); @@ -141,53 +139,48 @@ auto Acts::AdaptiveMultiVertexFinder::find( template auto Acts::AdaptiveMultiVertexFinder::doSeeding( const std::vector& trackVector, - Vertex& currentConstraint, const VertexingOptions& vertexingOptions, SeedFinderState_t& seedFinderState, const std::vector& removedSeedTracks) const -> Result> { - VertexingOptions seedOptions = vertexingOptions; - seedOptions.constraint = currentConstraint; - if constexpr (NeedsRemovedTracks::value) { seedFinderState.tracksToRemove = removedSeedTracks; } // Run seed finder auto seedResult = - m_cfg.seedFinder.find(trackVector, seedOptions, seedFinderState); + m_cfg.seedFinder.find(trackVector, vertexingOptions, seedFinderState); if (!seedResult.ok()) { return seedResult.error(); } Vertex seedVertex = (*seedResult).back(); - // Update constraints according to seed vertex - setConstraintAfterSeeding(currentConstraint, seedOptions.useConstraintInFit, - seedVertex); + // Update covariance matrix of the vertex seed + setSeedCovariance(seedVertex, vertexingOptions); return seedVertex; } template -auto Acts::AdaptiveMultiVertexFinder:: - setConstraintAfterSeeding(Vertex& currentConstraint, - bool useVertexConstraintInFit, - Vertex& seedVertex) const -> void { - if (useVertexConstraintInFit) { +auto Acts::AdaptiveMultiVertexFinder::setSeedCovariance( + Vertex& seedVertex, + const VertexingOptions& vertexingOptions) const -> void { + // if useConstraintInFit == true, we either use + // -) the covariance matrix from the vertex seeding or + // -) the covariance matrix of the user-provided constraint + // for the vertex seed. + if (vertexingOptions.useConstraintInFit) { if (!m_cfg.useSeedConstraint) { - // Set seed vertex constraint to old constraint before seeding - seedVertex.setFullCovariance(currentConstraint.fullCovariance()); - } else { - // Use the constraint provided by the seed finder - currentConstraint.setFullPosition(seedVertex.fullPosition()); - currentConstraint.setFullCovariance(seedVertex.fullCovariance()); + // Use covariance from user-provided constraint + seedVertex.setFullCovariance( + vertexingOptions.constraint.fullCovariance()); } } else { - currentConstraint.setFullPosition(seedVertex.fullPosition()); - currentConstraint.setFullCovariance(SquareMatrix4::Identity() * - m_cfg.looseConstrValue); - currentConstraint.setFitQuality(m_cfg.defaultConstrFitQuality); + // Otherwise, we set the covariance to a diagonal matrix with large entries + seedVertex.setFullCovariance(SquareMatrix4::Identity() * + m_cfg.looseConstrValue); + seedVertex.setFitQuality(m_cfg.defaultConstrFitQuality); } } @@ -261,9 +254,7 @@ auto Acts::AdaptiveMultiVertexFinder:: canRecoverFromNoCompatibleTracks( const std::vector& allTracks, const std::vector& seedTracks, - Vertex& vtx, - const Vertex& currentConstraint, - FitterState_t& fitterState, + Vertex& vtx, FitterState_t& fitterState, const VertexingOptions& vertexingOptions) const -> Result { // Recover from cases where no compatible tracks to vertex @@ -289,8 +280,7 @@ auto Acts::AdaptiveMultiVertexFinder:: vtx.setFullPosition(Vector4(0., 0., newZ, 0.)); // Update vertex info for current vertex - fitterState.vtxInfoMap[&vtx] = - VertexInfo(currentConstraint, vtx.fullPosition()); + fitterState.vtxInfoMap[&vtx] = VertexInfo(vtx); // Try to add compatible track with adapted vertex position auto res = addCompatibleTracksToVertex(allTracks, vtx, fitterState, @@ -320,14 +310,11 @@ auto Acts::AdaptiveMultiVertexFinder:: canPrepareVertexForFit( const std::vector& allTracks, const std::vector& seedTracks, - Vertex& vtx, - const Vertex& currentConstraint, - FitterState_t& fitterState, + Vertex& vtx, FitterState_t& fitterState, const VertexingOptions& vertexingOptions) const -> Result { // Add vertex info to fitter state - fitterState.vtxInfoMap[&vtx] = - VertexInfo(currentConstraint, vtx.fullPosition()); + fitterState.vtxInfoMap[&vtx] = VertexInfo(vtx); // Add all compatible tracks to vertex auto resComp = addCompatibleTracksToVertex(allTracks, vtx, fitterState, @@ -338,8 +325,7 @@ auto Acts::AdaptiveMultiVertexFinder:: // Try to recover from cases where adding compatible track was not possible auto resRec = canRecoverFromNoCompatibleTracks(allTracks, seedTracks, vtx, - currentConstraint, fitterState, - vertexingOptions); + fitterState, vertexingOptions); if (!resRec.ok()) { return Result::failure(resRec.error()); } diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.hpp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.hpp index 09a203e0b1c..4c70bb0b413 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.hpp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.hpp @@ -151,6 +151,11 @@ class AdaptiveMultiVertexFitter { // Do smoothing after multivertex fit bool doSmoothing{false}; + // If set to true, the vertices are set back to their seed positions before + // each fit iteration. This is how it's done in athena; not sure why we + // would do this. + bool startFitFromSeed{true}; + // Use time information when calculating the vertex compatibility bool useTime{false}; }; diff --git a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.ipp b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.ipp index 89bb09ba2a2..d25c3de2f42 100644 --- a/Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.ipp +++ b/Core/include/Acts/Vertexing/AdaptiveMultiVertexFitter.ipp @@ -63,13 +63,11 @@ Acts::AdaptiveMultiVertexFitter::fit( } // Check if we use the constraint during the vertex fit - if (state.vtxInfoMap[vtx].constraint.fullCovariance() != - SquareMatrix4::Zero()) { - const Acts::Vertex& constraint = - state.vtxInfoMap[vtx].constraint; - vtx->setFullPosition(constraint.fullPosition()); - vtx->setFitQuality(constraint.fitQuality()); - vtx->setFullCovariance(constraint.fullCovariance()); + if (m_cfg.startFitFromSeed) { + const Acts::Vertex& seed = state.vtxInfoMap[vtx].seed; + vtx->setFullPosition(seed.fullPosition()); + vtx->setFitQuality(seed.fitQuality()); + vtx->setFullCovariance(seed.fullCovariance()); } else if (vtx->fullCovariance() == SquareMatrix4::Zero()) { return VertexingError::NoCovariance; } @@ -208,7 +206,7 @@ Acts::Result Acts:: // Vertex info object auto& vtxInfo = state.vtxInfoMap[vtx]; // Vertex seed position - const Vector3& seedPos = vtxInfo.seedPosition.template head<3>(); + const Vector3& seedPos = vtxInfo.seed.position(); // Loop over all tracks at the vertex for (const auto& trk : vtxInfo.trackLinks) { @@ -399,7 +397,7 @@ void Acts::AdaptiveMultiVertexFitter::logDebugData( ++vtxInd) { auto vtx = state.vertexCollection[vtxInd]; ACTS_DEBUG("Position of " << vtxInd << ". vertex seed:\n" - << state.vtxInfoMap.at(vtx).seedPosition); + << state.vtxInfoMap.at(vtx).seed.fullPosition()); ACTS_DEBUG("Position of said vertex after the last fitting step:\n" << state.vtxInfoMap.at(vtx).oldPosition); ACTS_DEBUG("Associated tracks:"); diff --git a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp index d25316218aa..3a82aaf147c 100644 --- a/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp +++ b/Core/include/Acts/Vertexing/TrackDensityVertexFinder.ipp @@ -29,8 +29,8 @@ auto Acts::TrackDensityVertexFinder::find( SquareMatrix4 seedCov = vertexingOptions.constraint.fullCovariance(); - // Check if a constraint is provided and set the new z position constraint - if (seedCov != SquareMatrix4::Zero() && std::isnormal(zAndWidth.second)) { + // Set the new z position constraint if desired + if (vertexingOptions.useConstraintInFit && std::isnormal(zAndWidth.second)) { seedCov(eZ, eZ) = zAndWidth.second * zAndWidth.second; } diff --git a/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFitterTests.cpp b/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFitterTests.cpp index 7b23de2f213..a2ad99735a6 100644 --- a/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFitterTests.cpp +++ b/Tests/UnitTests/Core/Vertexing/AdaptiveMultiVertexFitterTests.cpp @@ -129,6 +129,7 @@ BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_fitter_test) { // Test smoothing fitterCfg.doSmoothing = true; + fitterCfg.startFitFromSeed = false; AdaptiveMultiVertexFitter fitter( std::move(fitterCfg)); @@ -603,17 +604,16 @@ BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_fitter_test_athena) { state.vertexCollection.push_back(&vtx1); // The constraint vtx for vtx1 - Vertex vtx1Constr(vtxPos1); - vtx1Constr.setFullCovariance(covConstr); - vtx1Constr.setFitQuality(0, -3); + Vertex vtx1Seed(vtxPos1); + vtx1Seed.setFullCovariance(covConstr); + vtx1Seed.setFitQuality(0, -3); // Prepare vtx info for fitter VertexInfo vtxInfo1; vtxInfo1.linPoint.setZero(); vtxInfo1.linPoint.head<3>() = vtxPos1; - vtxInfo1.constraint = vtx1Constr; + vtxInfo1.seed = vtx1Seed; vtxInfo1.oldPosition = vtxInfo1.linPoint; - vtxInfo1.seedPosition = vtxInfo1.linPoint; for (const auto& trk : params1) { vtxInfo1.trackLinks.push_back(&trk); @@ -630,17 +630,16 @@ BOOST_AUTO_TEST_CASE(adaptive_multi_vertex_fitter_test_athena) { state.vertexCollection.push_back(&vtx2); // The constraint vtx for vtx2 - Vertex vtx2Constr(vtxPos2); - vtx2Constr.setFullCovariance(covConstr); - vtx2Constr.setFitQuality(0, -3); + Vertex vtx2Seed(vtxPos2); + vtx2Seed.setFullCovariance(covConstr); + vtx2Seed.setFitQuality(0, -3); // Prepare vtx info for fitter VertexInfo vtxInfo2; vtxInfo2.linPoint.setZero(); vtxInfo2.linPoint.head<3>() = vtxPos2; - vtxInfo2.constraint = vtx2Constr; + vtxInfo2.seed = vtx2Seed; vtxInfo2.oldPosition = vtxInfo2.linPoint; - vtxInfo2.seedPosition = vtxInfo2.linPoint; for (const auto& trk : params2) { vtxInfo2.trackLinks.push_back(&trk);