ATLAS Offline Software
Loading...
Searching...
No Matches
TrackParamsEstimationTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include "Acts/Seeding/EstimateTrackParamsFromSeed.hpp"
9#include "Acts/EventData/TransformationHelpers.hpp"
10
11#include <algorithm>
12#include <ranges>
13
14namespace ActsTrk {
16 const std::string& name,
17 const IInterface* parent)
18 : base_class(type, name, parent)
19 {}
20
22 {
23 ATH_MSG_INFO( "Initializing " << name() << "..." );
24
25 ATH_MSG_DEBUG( "Properties Summary:" );
26 ATH_MSG_DEBUG( " " << m_sigmaLoc0 );
27 ATH_MSG_DEBUG( " " << m_sigmaLoc1 );
28 ATH_MSG_DEBUG( " " << m_sigmaPhi );
31 ATH_MSG_DEBUG( " " << m_sigmaT0 );
34 ATH_MSG_DEBUG( " " << m_firstSp );
35
36 m_logger = makeActsAthenaLogger(this, "Acts");
37
38 m_extrapolator = Extrapolator(Stepper(std::make_shared<ATLASMagneticFieldWrapper>()), Navigator(), logger().cloneWithSuffix("Prop"));
39
41
42 return StatusCode::SUCCESS;
43 }
44
45 std::optional<Acts::BoundTrackParameters>
47 const ActsTrk::Seed& seed,
48 bool useTopSp,
49 const Acts::GeometryContext& geoContext,
50 const Acts::MagneticFieldContext& magFieldContext,
51 std::function<const Acts::Surface&(const ActsTrk::Seed& seed, bool useTopSp)> retrieveSurface) const
52 {
53 const auto& sp_collection = seed.sp();
54 if ( sp_collection.size() < 3 ) return std::nullopt;
55 const xAOD::SpacePoint* bottom_sp = (useTopSp && m_bFieldMode != 2) ? sp_collection.back() : sp_collection.front();
56
57 // Magnetic Field
58 ATLASMagneticFieldWrapper magneticField;
59 Acts::MagneticFieldProvider::Cache magFieldCache = magneticField.makeCache( magFieldContext );
60 Acts::Vector3 bField = *magneticField.getField( Acts::Vector3(bottom_sp->x(), bottom_sp->y(), bottom_sp->z()),
61 magFieldCache );
62 if (m_bFieldMode == 1) {
63 bField[0] = 0.0;
64 bField[1] = 0.0;
65 }
66
67 // Get the surface
68 const Acts::Surface& surface = retrieveSurface(seed, useTopSp);
69
71 seed,
72 useTopSp,
73 geoContext,
74 magFieldContext,
75 surface,
76 bField);
77 }
78
79 std::optional<Acts::BoundTrackParameters>
81 const ActsTrk::Seed& seed,
82 bool useTopSp,
83 const Acts::GeometryContext& geoContext,
84 const Acts::MagneticFieldContext& magFieldContext,
85 const Acts::Surface& surface,
86 const Acts::Vector3& bField) const
87 {
88 // Get SPs
89 const auto& sp_collection = seed.sp();
90 const std::size_t nSp = sp_collection.size();
91 if (nSp < 3) return std::nullopt;
92
93 // Function to extract the values from sp_collection
94 auto sp_collection_extract = std::views::transform([&sp_collection, useTopSp](std::size_t i) {
95 return sp_collection.at(useTopSp ? sp_collection.size() - i - 1 : i);
96 });
97
98 // Compute free parameters
99 Acts::FreeVector freeParams = Acts::estimateTrackParamsFromSeed(m_spacePointIndicesFun(nSp) | sp_collection_extract, bField);
100
101 if (m_useLongSeeds == 1 && nSp > 3ul) {
102 auto spacePointIndicesFun2 = [](std::size_t nSp) -> std::array<std::size_t, 3> {
103 return {0, nSp / 2ul, nSp - 1};
104 };
105 Acts::FreeVector freeParams2 = Acts::estimateTrackParamsFromSeed(spacePointIndicesFun2(nSp) | sp_collection_extract, bField);
106 ATH_MSG_DEBUG("update seed p = " << 1.0 / freeParams[Acts::eFreeQOverP] << " to " << 1.0 / freeParams2[Acts::eFreeQOverP]);
107 freeParams[Acts::eFreeQOverP] = freeParams2[Acts::eFreeQOverP];
108 }
109
110 if (useTopSp) {
111 // reverse direction so momentum vector pointing outwards
112 freeParams = Acts::reflectFreeParameters(freeParams);
113 }
114
115 // Convert free params to curvilinear params for extrapolation
116 Acts::BoundTrackParameters curvilinearParams = Acts::BoundTrackParameters::createCurvilinear(
117 freeParams.segment<4>(Acts::eFreePos0),
118 freeParams.segment<3>(Acts::eFreeDir0),
119 freeParams[Acts::eFreeQOverP],
120 std::nullopt,
121 Acts::ParticleHypothesis::pion());
122
123 // Extrapolate to surface
124 Acts::PropagatorPlainOptions propOptions(geoContext, magFieldContext);
125 propOptions.direction = Acts::Direction::fromScalarZeroAsPositive(
126 surface.intersect(
127 geoContext,
128 freeParams.segment<3>(Acts::eFreePos0),
129 freeParams.segment<3>(Acts::eFreeDir0)
130 ).closest().pathLength());
131 auto boundParamsResult = m_extrapolator->propagateToSurface(curvilinearParams, surface, propOptions);
132 if (!boundParamsResult.ok()) {
133 ATH_MSG_DEBUG("Extrapolation failed");
134 return std::nullopt;
135 }
136
137 // Get extrapolated parameters
138 Acts::BoundTrackParameters boundParams = *boundParamsResult;
139
140 // Estimate covariance
141 Acts::EstimateTrackParamCovarianceConfig covarianceEstimationConfig = {
143 .initialSigmaPtRel = m_initialSigmaPtRel,
144 .initialVarInflation = Eigen::Map<const Acts::BoundVector>(m_initialVarInflation.value().data()),
145 .noTimeVarInflation = 1.0,
146 };
147 boundParams.covariance() = Acts::estimateTrackParamCovariance(
148 covarianceEstimationConfig,
149 boundParams.parameters(),
150 false);
151
152 return boundParams;
153 }
154
155 // Function to return which 3 SPs of a seed to use
157 if (m_useLongSeeds == 2) {
158 return [](std::size_t nSp) -> std::array<std::size_t, 3> {
159 if (nSp > 3ul)
160 return {0, nSp / 2ul, nSp - 1};
161 else
162 return {0, 1, 2};
163 };
164 } else if (m_firstSp > 0ul) {
165 std::size_t firstSp = m_firstSp;
166 return [firstSp](std::size_t nSp) -> std::array<std::size_t, 3> {
167 if (nSp > 3ul) {
168 std::size_t first = std::min(firstSp, nSp - 3ul);
169 return {first, first + 1, first + 2};
170 } else
171 return {0, 1, 2};
172 };
173 } else {
174 return [](std::size_t) -> std::array<std::size_t, 3> {
175 return {0, 1, 2};
176 };
177 }
178 };
179
180}
181// namespace ActsTrk
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
std::unique_ptr< const Acts::Logger > makeActsAthenaLogger(IMessageSvc *svc, const std::string &name, int level, std::optional< std::string > parent_name)
Acts::Result< Acts::Vector3 > getField(const Acts::Vector3 &position, Acts::MagneticFieldProvider::Cache &gcache) const override
MagneticFieldProvider::Cache makeCache(const Acts::MagneticFieldContext &mctx) const override
std::function< std::array< std::size_t, 3 >(std::size_t)> SpacePointIndicesFun_t
const Acts::Logger & logger() const
Private access to the logger.
std::unique_ptr< const Acts::Logger > m_logger
logging instance
SpacePointIndicesFun_t spacePointIndicesFun() const override
TrackParamsEstimationTool(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< std::vector< double > > m_initialVarInflation
Gaudi::Property< std::size_t > m_firstSp
std::optional< Extrapolator > m_extrapolator
virtual std::optional< Acts::BoundTrackParameters > estimateTrackParameters(const ActsTrk::Seed &seed, bool useTopSp, const Acts::GeometryContext &geoContext, const Acts::MagneticFieldContext &magFieldContext, std::function< const Acts::Surface &(const ActsTrk::Seed &seed, bool useTopSp)> retrieveSurface) const override
float z() const
float y() const
float x() const
The AlignStoreProviderAlg loads the rigid alignment corrections and pipes them through the readout ge...