Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:12:54

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