Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-29 07:34:34

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/EventData/detail/TestSourceLink.hpp"
0012 #include "Acts/Geometry/CuboidVolumeBuilder.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "ActsAlignment/Kernel/Alignment.hpp"
0015 #include "ActsTests/CommonHelpers/AlignmentHelpers.hpp"
0016 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0017 
0018 #include <string>
0019 
0020 using namespace Acts;
0021 using namespace ActsTests;
0022 using namespace ActsTests::AlignmentUtils;
0023 using namespace Acts::detail::Test;
0024 using namespace Acts::UnitConstants;
0025 ///
0026 /// @brief Unit test for KF-based alignment algorithm
0027 ///
0028 BOOST_AUTO_TEST_CASE(ZeroFieldKalmanAlignment) {
0029   aliTestUtils utils;
0030   // Build detector
0031   TelescopeDetector detector(utils.geoCtx);
0032   const auto geometry = detector();
0033 
0034   // reconstruction propagator and fitter
0035   auto kfLogger = getDefaultLogger("KalmanFilter", Logging::INFO);
0036   const auto kfZeroPropagator =
0037       makeConstantFieldPropagator(geometry, 0_T, std::move(kfLogger));
0038   auto kfZero = KalmanFitterType(kfZeroPropagator);
0039 
0040   // alignment
0041   auto alignLogger = getDefaultLogger("Alignment", Logging::INFO);
0042   const auto alignZero =
0043       ActsAlignment::Alignment(std::move(kfZero), std::move(alignLogger));
0044 
0045   // Create 10 trajectories
0046   const auto& trajectories = createTrajectories(geometry, 10, utils);
0047 
0048   // Construct the KalmanFitter options
0049 
0050   auto extensions = getExtensions(utils);
0051   TestSourceLink::SurfaceAccessor surfaceAccessor{*geometry};
0052   extensions.surfaceAccessor
0053       .connect<&TestSourceLink::SurfaceAccessor::operator()>(&surfaceAccessor);
0054   KalmanFitterOptions kfOptions(
0055       utils.geoCtx, utils.magCtx, utils.calCtx, extensions,
0056       PropagatorPlainOptions(utils.geoCtx, utils.magCtx));
0057 
0058   // Construct a non-updating alignment updater
0059   ActsAlignment::AlignedTransformUpdater voidAlignUpdater =
0060       [](SurfacePlacementBase* /*element*/, const GeometryContext& /*gctx*/,
0061          const Transform3& /*transform*/) { return true; };
0062 
0063   // Construct the alignment options
0064   ActsAlignment::AlignmentOptions<KalmanFitterOptions<VectorMultiTrajectory>>
0065       alignOptions(kfOptions, voidAlignUpdater);
0066   alignOptions.maxIterations = 1;
0067 
0068   // Set the surfaces to be aligned (fix the layer 8)
0069   unsigned int iSurface = 0;
0070   std::unordered_map<const Surface*, std::size_t> idxedAlignSurfaces;
0071   // Loop over the detector elements
0072   for (auto& det : detector.detectorStore) {
0073     const auto& surface = det->surface();
0074     if (surface.geometryId().layer() != 8) {
0075       alignOptions.alignedDetElements.push_back(det.get());
0076       idxedAlignSurfaces.emplace(&surface, iSurface);
0077       iSurface++;
0078     }
0079   }
0080 
0081   // Test the method to evaluate alignment state for a single track
0082   const auto& inputTraj = trajectories.front();
0083   kfOptions.referenceSurface = &(*inputTraj.startParameters).referenceSurface();
0084 
0085   auto evaluateRes = alignZero.evaluateTrackAlignmentState(
0086       kfOptions.geoContext, inputTraj.sourceLinks, *inputTraj.startParameters,
0087       kfOptions, idxedAlignSurfaces, ActsAlignment::AlignmentMask::All);
0088   BOOST_CHECK(evaluateRes.ok());
0089 
0090   const auto& alignState = evaluateRes.value();
0091   CHECK_CLOSE_ABS(alignState.chi2 / alignState.alignmentDof, 0.5, 1);
0092 
0093   // Check the dimensions
0094   BOOST_CHECK_EQUAL(alignState.measurementDim, 12);
0095   BOOST_CHECK_EQUAL(alignState.trackParametersDim, 36);
0096   // Check the alignment dof
0097   BOOST_CHECK_EQUAL(alignState.alignmentDof, 30);
0098   BOOST_CHECK_EQUAL(alignState.alignedSurfaces.size(), 5);
0099   // Check the measurements covariance
0100   BOOST_CHECK_EQUAL(alignState.measurementCovariance.rows(), 12);
0101   const SquareMatrix2 measCov =
0102       alignState.measurementCovariance.block<2, 2>(2, 2);
0103   SquareMatrix2 cov2D;
0104   cov2D << 30_um * 30_um, 0, 0, 50_um * 50_um;
0105   CHECK_CLOSE_ABS(measCov, cov2D, 1e-10);
0106   // Check the track parameters covariance matrix. Its rows/columns scales
0107   // with the number of measurement states
0108   BOOST_CHECK_EQUAL(alignState.trackParametersCovariance.rows(), 36);
0109   // Check the projection matrix
0110   BOOST_CHECK_EQUAL(alignState.projectionMatrix.rows(), 12);
0111   BOOST_CHECK_EQUAL(alignState.projectionMatrix.cols(), 36);
0112   const Matrix<2, 6> proj = alignState.projectionMatrix.block<2, 6>(0, 0);
0113   const Matrix<2, 6> refProj = Matrix<2, 6>::Identity();
0114   CHECK_CLOSE_ABS(proj, refProj, 1e-10);
0115   // Check the residual
0116   BOOST_CHECK_EQUAL(alignState.residual.size(), 12);
0117   // Check the residual covariance
0118   BOOST_CHECK_EQUAL(alignState.residualCovariance.rows(), 12);
0119   // Check the alignment to residual derivative
0120   BOOST_CHECK_EQUAL(alignState.alignmentToResidualDerivative.rows(), 12);
0121   BOOST_CHECK_EQUAL(alignState.alignmentToResidualDerivative.cols(), 30);
0122   // Check the chi2 derivative
0123   BOOST_CHECK_EQUAL(alignState.alignmentToChi2Derivative.size(), 30);
0124   BOOST_CHECK_EQUAL(alignState.alignmentToChi2SecondDerivative.rows(), 30);
0125 
0126   // Test the align method
0127   std::vector<std::vector<TestSourceLink>> trajCollection;
0128   trajCollection.reserve(10);
0129   std::vector<BoundTrackParameters> sParametersCollection;
0130   sParametersCollection.reserve(10);
0131   for (const auto& traj : trajectories) {
0132     trajCollection.push_back(traj.sourceLinks);
0133     sParametersCollection.push_back(*traj.startParameters);
0134   }
0135   auto alignRes =
0136       alignZero.align(trajCollection, sParametersCollection, alignOptions);
0137 
0138   // BOOST_CHECK(alignRes.ok());
0139 }