Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:11:31

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Common.hpp"
0013 #include "Acts/Definitions/Direction.hpp"
0014 #include "Acts/Definitions/TrackParametrization.hpp"
0015 #include "Acts/Definitions/Units.hpp"
0016 #include "Acts/EventData/Charge.hpp"
0017 #include "Acts/EventData/GenericBoundTrackParameters.hpp"
0018 #include "Acts/EventData/GenericCurvilinearTrackParameters.hpp"
0019 #include "Acts/EventData/MultiComponentTrackParameters.hpp"
0020 #include "Acts/EventData/MultiTrajectory.hpp"
0021 #include "Acts/EventData/TrackContainer.hpp"
0022 #include "Acts/EventData/TrackParameters.hpp"
0023 #include "Acts/EventData/TrackProxy.hpp"
0024 #include "Acts/EventData/TrackStatePropMask.hpp"
0025 #include "Acts/EventData/VectorMultiTrajectory.hpp"
0026 #include "Acts/EventData/VectorTrackContainer.hpp"
0027 #include "Acts/EventData/detail/TestSourceLink.hpp"
0028 #include "Acts/Geometry/GeometryIdentifier.hpp"
0029 #include "Acts/Propagator/MultiEigenStepperLoop.hpp"
0030 #include "Acts/Propagator/Navigator.hpp"
0031 #include "Acts/Propagator/Propagator.hpp"
0032 #include "Acts/Propagator/StraightLineStepper.hpp"
0033 #include "Acts/Surfaces/PlaneSurface.hpp"
0034 #include "Acts/Surfaces/Surface.hpp"
0035 #include "Acts/Tests/CommonHelpers/LineSurfaceStub.hpp"
0036 #include "Acts/Tests/CommonHelpers/MeasurementsCreator.hpp"
0037 #include "Acts/TrackFitting/BetheHeitlerApprox.hpp"
0038 #include "Acts/TrackFitting/GainMatrixUpdater.hpp"
0039 #include "Acts/TrackFitting/GaussianSumFitter.hpp"
0040 #include "Acts/TrackFitting/GsfMixtureReduction.hpp"
0041 #include "Acts/TrackFitting/GsfOptions.hpp"
0042 #include "Acts/Utilities/Delegate.hpp"
0043 #include "Acts/Utilities/Holders.hpp"
0044 #include "Acts/Utilities/Result.hpp"
0045 #include "Acts/Utilities/UnitVectors.hpp"
0046 #include "Acts/Utilities/Zip.hpp"
0047 
0048 #include <algorithm>
0049 #include <array>
0050 #include <functional>
0051 #include <map>
0052 #include <memory>
0053 #include <optional>
0054 #include <random>
0055 #include <string>
0056 #include <string_view>
0057 #include <tuple>
0058 #include <vector>
0059 
0060 #include "FitterTestsCommon.hpp"
0061 
0062 namespace {
0063 
0064 using namespace Acts;
0065 using namespace Acts::Test;
0066 using namespace Acts::detail::Test;
0067 using namespace Acts::UnitLiterals;
0068 
0069 static const auto electron = ParticleHypothesis::electron();
0070 
0071 Acts::GainMatrixUpdater kfUpdater;
0072 
0073 FitterTester tester;
0074 
0075 GsfExtensions<VectorMultiTrajectory> getExtensions() {
0076   GsfExtensions<VectorMultiTrajectory> extensions;
0077   extensions.calibrator
0078       .connect<&testSourceLinkCalibrator<VectorMultiTrajectory>>();
0079   extensions.updater
0080       .connect<&Acts::GainMatrixUpdater::operator()<VectorMultiTrajectory>>(
0081           &kfUpdater);
0082   extensions.surfaceAccessor
0083       .connect<&TestSourceLink::SurfaceAccessor::operator()>(
0084           &tester.surfaceAccessor);
0085   extensions.mixtureReducer.connect<&Acts::reduceMixtureWithKLDistance>();
0086   return extensions;
0087 }
0088 
0089 using Stepper = Acts::MultiEigenStepperLoop<>;
0090 using Propagator = Acts::Propagator<Stepper, Acts::Navigator>;
0091 using BetheHeitlerApprox = AtlasBetheHeitlerApprox<6, 5>;
0092 using GSF =
0093     GaussianSumFitter<Propagator, BetheHeitlerApprox, VectorMultiTrajectory>;
0094 
0095 const GSF gsfZero(makeConstantFieldPropagator<Stepper>(tester.geometry, 0_T),
0096                   makeDefaultBetheHeitlerApprox());
0097 
0098 std::default_random_engine rng(42);
0099 
0100 auto makeDefaultGsfOptions() {
0101   return GsfOptions<VectorMultiTrajectory>{tester.geoCtx, tester.magCtx,
0102                                            tester.calCtx, getExtensions(),
0103                                            PropagatorPlainOptions()};
0104 }
0105 
0106 // A Helper type to allow us to put the MultiComponentBoundTrackParameters into
0107 // the function so that it can also be used as GenericBoundTrackParameters for
0108 // the MeasurementsCreator
0109 struct MultiCmpsParsInterface : public BoundTrackParameters {
0110   MultiComponentBoundTrackParameters multi_pars;
0111 
0112   MultiCmpsParsInterface(const MultiComponentBoundTrackParameters &p)
0113       : BoundTrackParameters(p.referenceSurface().getSharedPtr(),
0114                              p.parameters(), p.covariance(), electron),
0115         multi_pars(p) {}
0116 
0117   operator MultiComponentBoundTrackParameters() const { return multi_pars; }
0118 };
0119 
0120 auto makeParameters() {
0121   // create covariance matrix from reasonable standard deviations
0122   Acts::BoundVector stddev;
0123   stddev[Acts::eBoundLoc0] = 100_um;
0124   stddev[Acts::eBoundLoc1] = 100_um;
0125   stddev[Acts::eBoundTime] = 25_ns;
0126   stddev[Acts::eBoundPhi] = 2_degree;
0127   stddev[Acts::eBoundTheta] = 2_degree;
0128   stddev[Acts::eBoundQOverP] = 1 / 100_GeV;
0129   Acts::BoundSquareMatrix cov = stddev.cwiseProduct(stddev).asDiagonal();
0130 
0131   // define a track in the transverse plane along x
0132   Acts::Vector4 mPos4(-3_m, 0., 0., 42_ns);
0133   Acts::CurvilinearTrackParameters cp(mPos4, 0_degree, 90_degree, 1_e / 1_GeV,
0134                                       cov, electron);
0135 
0136   // Construct bound multi component parameters from curvilinear ones
0137   Acts::BoundVector deltaLOC0 = Acts::BoundVector::Zero();
0138   deltaLOC0[eBoundLoc0] = 0.5_mm;
0139 
0140   Acts::BoundVector deltaLOC1 = Acts::BoundVector::Zero();
0141   deltaLOC1[eBoundLoc1] = 0.5_mm;
0142 
0143   Acts::BoundVector deltaQOP = Acts::BoundVector::Zero();
0144   deltaQOP[eBoundQOverP] = 0.01_GeV;
0145 
0146   std::vector<std::tuple<double, BoundVector, BoundSquareMatrix>> cmps = {
0147       {0.2, cp.parameters(), cov},
0148       {0.2, cp.parameters() + deltaLOC0 + deltaLOC1 + deltaQOP, cov},
0149       {0.2, cp.parameters() + deltaLOC0 - deltaLOC1 - deltaQOP, cov},
0150       {0.2, cp.parameters() - deltaLOC0 + deltaLOC1 + deltaQOP, cov},
0151       {0.2, cp.parameters() - deltaLOC0 - deltaLOC1 - deltaQOP, cov}};
0152 
0153   return MultiCmpsParsInterface(MultiComponentBoundTrackParameters(
0154       cp.referenceSurface().getSharedPtr(), cmps, electron));
0155 }
0156 
0157 }  // namespace
0158 
0159 BOOST_AUTO_TEST_SUITE(TrackFittingGsf)
0160 
0161 BOOST_AUTO_TEST_CASE(ZeroFieldNoSurfaceForward) {
0162   auto multi_pars = makeParameters();
0163   auto options = makeDefaultGsfOptions();
0164 
0165   tester.test_ZeroFieldNoSurfaceForward(gsfZero, options, multi_pars, rng, true,
0166                                         false, false);
0167 }
0168 
0169 BOOST_AUTO_TEST_CASE(ZeroFieldWithSurfaceForward) {
0170   auto multi_pars = makeParameters();
0171   auto options = makeDefaultGsfOptions();
0172 
0173   tester.test_ZeroFieldWithSurfaceForward(gsfZero, options, multi_pars, rng,
0174                                           true, false, false);
0175 }
0176 
0177 BOOST_AUTO_TEST_CASE(ZeroFieldWithSurfaceBackward) {
0178   auto multi_pars = makeParameters();
0179   auto options = makeDefaultGsfOptions();
0180 
0181   tester.test_ZeroFieldWithSurfaceBackward(gsfZero, options, multi_pars, rng,
0182                                            true, false, false);
0183 }
0184 
0185 BOOST_AUTO_TEST_CASE(ZeroFieldWithSurfaceAtExit) {
0186   auto multi_pars = makeParameters();
0187   auto options = makeDefaultGsfOptions();
0188 
0189   tester.test_ZeroFieldWithSurfaceBackward(gsfZero, options, multi_pars, rng,
0190                                            true, false, false);
0191 }
0192 
0193 BOOST_AUTO_TEST_CASE(ZeroFieldShuffled) {
0194   auto multi_pars = makeParameters();
0195   auto options = makeDefaultGsfOptions();
0196 
0197   tester.test_ZeroFieldShuffled(gsfZero, options, multi_pars, rng, true, false,
0198                                 false);
0199 }
0200 
0201 BOOST_AUTO_TEST_CASE(ZeroFieldWithHole) {
0202   auto options = makeDefaultGsfOptions();
0203   auto multi_pars = makeParameters();
0204 
0205   tester.test_ZeroFieldWithHole(gsfZero, options, multi_pars, rng, true, false,
0206                                 false);
0207 }
0208 
0209 BOOST_AUTO_TEST_CASE(ZeroFieldWithOutliers) {
0210   // fitter options w/o target surface. outlier distance is set to be below the
0211   // default outlier distance in the `MeasurementsCreator`
0212   TestOutlierFinder tof{5_mm};
0213   auto options = makeDefaultGsfOptions();
0214   options.extensions.outlierFinder
0215       .connect<&TestOutlierFinder::operator()<VectorMultiTrajectory>>(&tof);
0216 
0217   auto multi_pars = makeParameters();
0218 
0219   tester.test_ZeroFieldWithOutliers(gsfZero, options, multi_pars, rng, true,
0220                                     false, false);
0221 }
0222 
0223 BOOST_AUTO_TEST_CASE(WithFinalMultiComponentState) {
0224   Acts::TrackContainer tracks{Acts::VectorTrackContainer{},
0225                               Acts::VectorMultiTrajectory{}};
0226   using namespace Acts::GsfConstants;
0227   std::string key(kFinalMultiComponentStateColumn);
0228   tracks.template addColumn<FinalMultiComponentState>(key);
0229 
0230   auto multi_pars = makeParameters();
0231   auto measurements =
0232       createMeasurements(tester.simPropagator, tester.geoCtx, tester.magCtx,
0233                          multi_pars, tester.resolutions, rng);
0234   auto sourceLinks = tester.prepareSourceLinks(measurements.sourceLinks);
0235   auto options = makeDefaultGsfOptions();
0236 
0237   // create a boundless target surface near the tracker exit
0238   Acts::Vector3 center(-3._m, 0., 0.);
0239   Acts::Vector3 normal(1., 0., 0.);
0240   auto targetSurface =
0241       Acts::Surface::makeShared<Acts::PlaneSurface>(center, normal);
0242 
0243   options.referenceSurface = targetSurface.get();
0244 
0245   auto res = gsfZero.fit(sourceLinks.begin(), sourceLinks.end(), multi_pars,
0246                          options, tracks);
0247 
0248   BOOST_REQUIRE(res.ok());
0249   BOOST_CHECK(res->template component<FinalMultiComponentState>(
0250                      kFinalMultiComponentStateColumn)
0251                   .has_value());
0252 }
0253 
0254 BOOST_AUTO_TEST_SUITE_END()