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