From 12de1e21285d2f243ee5fedad013708d4512139c Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Thu, 7 Dec 2023 00:16:25 +0100 Subject: [PATCH] refactor: Factorize GX2F delta param calculation (#2774) This allows compiling the fairly expensive `colPivHouseholderQr` expression to be compiled in a separate translation unit. --- .../TrackFitting/GlobalChiSquareFitter.hpp | 20 ++++------- Core/src/TrackFitting/CMakeLists.txt | 1 + .../TrackFitting/GlobalChiSquareFitter.cpp | 34 +++++++++++++++++++ 3 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 Core/src/TrackFitting/GlobalChiSquareFitter.cpp diff --git a/Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp b/Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp index 6bb62a1d9b4..539c2a87266 100644 --- a/Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp +++ b/Core/include/Acts/TrackFitting/GlobalChiSquareFitter.hpp @@ -287,6 +287,9 @@ void collector(typename traj_t::TrackStateProxy& trackStateProxy, } } +BoundVector calculateDeltaParams(bool zeroField, const BoundMatrix& aMatrix, + const BoundVector& bVector); + /// Global Chi Square fitter (GX2F) implementation. /// /// @tparam propagator_t Type of the propagation class @@ -718,20 +721,8 @@ class Gx2Fitter { } // calculate delta params [a] * delta = b - deltaParams = BoundVector::Zero(); - if (gx2fOptions.zeroField) { - constexpr std::size_t reducedMatrixSize = 4; - deltaParams.topLeftCorner() = - aMatrix.topLeftCorner() - .colPivHouseholderQr() - .solve(bVector.topLeftCorner()); - } else { - constexpr std::size_t reducedMatrixSize = 5; - deltaParams.topLeftCorner() = - aMatrix.topLeftCorner() - .colPivHouseholderQr() - .solve(bVector.topLeftCorner()); - } + deltaParams = + calculateDeltaParams(gx2fOptions.zeroField, aMatrix, bVector); ACTS_VERBOSE("aMatrix:\n" << aMatrix << "\n" @@ -822,5 +813,6 @@ class Gx2Fitter { return track; } }; + } // namespace Experimental } // namespace Acts diff --git a/Core/src/TrackFitting/CMakeLists.txt b/Core/src/TrackFitting/CMakeLists.txt index 05eccd967ad..c370dc9aa01 100644 --- a/Core/src/TrackFitting/CMakeLists.txt +++ b/Core/src/TrackFitting/CMakeLists.txt @@ -9,4 +9,5 @@ target_sources( GsfUtils.cpp BetheHeitlerApprox.cpp GsfMixtureReduction.cpp + GlobalChiSquareFitter.cpp ) diff --git a/Core/src/TrackFitting/GlobalChiSquareFitter.cpp b/Core/src/TrackFitting/GlobalChiSquareFitter.cpp new file mode 100644 index 00000000000..c74319982ec --- /dev/null +++ b/Core/src/TrackFitting/GlobalChiSquareFitter.cpp @@ -0,0 +1,34 @@ +// This file is part of the Acts project. +// +// Copyright (C) 2023 CERN for the benefit of the Acts project +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "Acts/TrackFitting/GlobalChiSquareFitter.hpp" + +#include "Acts/Definitions/TrackParametrization.hpp" + +namespace Acts::Experimental { + +BoundVector calculateDeltaParams(bool zeroField, const BoundMatrix& aMatrix, + const BoundVector& bVector) { + BoundVector deltaParams = BoundVector::Zero(); + if (zeroField) { + constexpr std::size_t reducedMatrixSize = 4; + deltaParams.topLeftCorner() = + aMatrix.topLeftCorner() + .colPivHouseholderQr() + .solve(bVector.topLeftCorner()); + } else { + constexpr std::size_t reducedMatrixSize = 5; + deltaParams.topLeftCorner() = + aMatrix.topLeftCorner() + .colPivHouseholderQr() + .solve(bVector.topLeftCorner()); + } + + return deltaParams; +} +} // namespace Acts::Experimental