Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 07:50:28

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 "ActsExamples/Vertexing/IterativeVertexFinderAlgorithm.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Propagator/SympyStepper.hpp"
0013 #include "Acts/Propagator/VoidNavigator.hpp"
0014 #include "Acts/Utilities/Logger.hpp"
0015 #include "Acts/Utilities/Result.hpp"
0016 #include "Acts/Vertexing/IterativeVertexFinder.hpp"
0017 #include "Acts/Vertexing/TrackAtVertex.hpp"
0018 #include "Acts/Vertexing/Vertex.hpp"
0019 #include "ActsExamples/EventData/ProtoVertex.hpp"
0020 #include "ActsExamples/Framework/AlgorithmContext.hpp"
0021 
0022 #include <chrono>
0023 #include <ostream>
0024 #include <stdexcept>
0025 #include <system_error>
0026 
0027 #include "VertexingHelpers.hpp"
0028 
0029 namespace ActsExamples {
0030 
0031 IterativeVertexFinderAlgorithm::IterativeVertexFinderAlgorithm(
0032     const Config& config, Acts::Logging::Level level)
0033     : IAlgorithm("IterativeVertexFinder", level), m_cfg(config) {
0034   if (m_cfg.inputTrackParameters.empty()) {
0035     throw std::invalid_argument("Missing input track parameter collection");
0036   }
0037   if (m_cfg.outputProtoVertices.empty()) {
0038     throw std::invalid_argument("Missing output proto vertices collection");
0039   }
0040   if (m_cfg.outputVertices.empty()) {
0041     throw std::invalid_argument("Missing output vertices collection");
0042   }
0043 
0044   m_inputTrackParameters.initialize(m_cfg.inputTrackParameters);
0045   m_outputProtoVertices.initialize(m_cfg.outputProtoVertices);
0046   m_outputVertices.initialize(m_cfg.outputVertices);
0047 }
0048 
0049 ProcessCode IterativeVertexFinderAlgorithm::execute(
0050     const AlgorithmContext& ctx) const {
0051   // retrieve input tracks and convert into the expected format
0052 
0053   const auto& inputTrackParameters = m_inputTrackParameters(ctx);
0054   // TODO change this from pointers to tracks parameters to actual tracks
0055   auto inputTracks = makeInputTracks(inputTrackParameters);
0056 
0057   if (inputTrackParameters.size() != inputTracks.size()) {
0058     ACTS_ERROR("Input track containers do not align: "
0059                << inputTrackParameters.size() << " != " << inputTracks.size());
0060   }
0061 
0062   for (const auto& trk : inputTrackParameters) {
0063     if (trk.covariance() && trk.covariance()->determinant() <= 0) {
0064       // actually we should consider this as an error but I do not want the CI
0065       // to fail
0066       ACTS_WARNING("input track " << trk << " has det(cov) = "
0067                                   << trk.covariance()->determinant());
0068     }
0069   }
0070 
0071   // Set up SympyStepper
0072   Acts::SympyStepper stepper(m_cfg.bField);
0073 
0074   // Set up propagator with void navigator
0075   auto propagator = std::make_shared<Propagator>(
0076       stepper, Acts::VoidNavigator{}, logger().cloneWithSuffix("Propagator"));
0077   // Setup the vertex fitter
0078   Fitter::Config vertexFitterCfg;
0079   vertexFitterCfg.extractParameters
0080       .connect<&Acts::InputTrack::extractParameters>();
0081   // Setup the track linearizer
0082   Linearizer::Config linearizerCfg;
0083   linearizerCfg.bField = m_cfg.bField;
0084   linearizerCfg.propagator = propagator;
0085   Linearizer linearizer(linearizerCfg,
0086                         logger().cloneWithSuffix("HelicalTrackLinearizer"));
0087 
0088   vertexFitterCfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(
0089       &linearizer);
0090   Fitter vertexFitter(vertexFitterCfg,
0091                       logger().cloneWithSuffix("FullBilloirVertexFitter"));
0092 
0093   // Setup the seed finder
0094   Acts::ImpactPointEstimator::Config ipEstCfg(m_cfg.bField, propagator);
0095   Acts::ImpactPointEstimator ipEst(
0096       ipEstCfg, logger().cloneWithSuffix("ImpactPointEstimator"));
0097 
0098   Acts::GaussianTrackDensity::Config densityCfg;
0099   densityCfg.extractParameters.connect<&Acts::InputTrack::extractParameters>();
0100   auto seeder = std::make_shared<Seeder>(
0101       Seeder::Config{Acts::GaussianTrackDensity(densityCfg)});
0102   // Set up the actual vertex finder
0103   Finder::Config finderCfg(std::move(vertexFitter), seeder, ipEst);
0104   finderCfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&linearizer);
0105 
0106   finderCfg.maxVertices = m_cfg.maxIterations;
0107   finderCfg.reassignTracksAfterFirstFit = false;
0108   finderCfg.extractParameters.connect<&Acts::InputTrack::extractParameters>();
0109   finderCfg.field = m_cfg.bField;
0110   Finder finder(std::move(finderCfg), logger().clone());
0111   Acts::IVertexFinder::State state{std::in_place_type<Finder::State>,
0112                                    *m_cfg.bField, ctx.magFieldContext};
0113   Options finderOpts(ctx.geoContext, ctx.magFieldContext);
0114 
0115   // find vertices
0116   auto result = finder.find(inputTracks, finderOpts, state);
0117 
0118   VertexCollection vertices;
0119   if (result.ok()) {
0120     vertices = std::move(result.value());
0121   } else {
0122     ACTS_ERROR("Error in vertex finder: " << result.error().message());
0123   }
0124 
0125   // show some debug output
0126   ACTS_DEBUG("Found " << vertices.size() << " vertices in event");
0127   for (const auto& vtx : vertices) {
0128     ACTS_DEBUG("Found vertex at " << vtx.fullPosition().transpose() << " with "
0129                                   << vtx.tracks().size() << " tracks.");
0130   }
0131 
0132   // store proto vertices extracted from the found vertices
0133   m_outputProtoVertices(ctx, makeProtoVertices(inputTracks, vertices));
0134 
0135   // store found vertices
0136   m_outputVertices(ctx, std::move(vertices));
0137 
0138   return ProcessCode::SUCCESS;
0139 }
0140 
0141 }  // namespace ActsExamples