Skip to content

Commit e69bd9d

Browse files
wdconincepic-capybaragithub-actions[bot]
authored
fix: centralize Acts contexts for consistency (#2464)
### Briefly, what does this PR introduce? This PR centralizes all default-constructed Acts contexts to be consistent with each other and handed out (by const reference) by the ActsGeometryProvider. This ensures that any future run-dependent contexts can be provided without major changes. It also avoids the many deprecation warnings that are associated with default constructed contexts (when not gotten from a new static factory) in Acts v45 (acts-project/acts#4957). ### What kind of change does this PR introduce? - [x] Bug fix (issue: too many contexts) - [ ] New feature (issue #__) - [ ] Documentation update - [ ] Other: __ ### Please check if this PR fulfills the following: - [ ] Tests for the changes have been added - [ ] Documentation has been added / updated - [ ] Changes have been communicated to collaborators ### Does this PR introduce breaking changes? What changes might users need to make to their code? No. ### Does this PR change default behavior? No. --------- Co-authored-by: epic-capybara <139920704+epic-capybara@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 9d8ab3b commit e69bd9d

File tree

10 files changed

+57
-34
lines changed

10 files changed

+57
-34
lines changed

src/algorithms/tracking/ActsGeometryProvider.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
#include <Acts/Definitions/Units.hpp>
88
#include <Acts/Geometry/GeometryContext.hpp>
99
#include <Acts/Geometry/TrackingGeometry.hpp>
10+
#include <Acts/MagneticField/MagneticFieldContext.hpp>
1011
#include <Acts/MagneticField/MagneticFieldProvider.hpp>
1112
#include <Acts/Surfaces/Surface.hpp>
13+
#include <Acts/Utilities/CalibrationContext.hpp>
1214
#include <Acts/Visualization/ViewConfig.hpp>
1315
#include <DD4hep/Detector.h>
1416
#include <DD4hep/Fields.h>
@@ -63,6 +65,10 @@ class ActsGeometryProvider {
6365
std::map<int64_t, dd4hep::rec::Surface*> getDD4hepSurfaceMap() const { return m_surfaceMap; }
6466

6567
const Acts::GeometryContext& getActsGeometryContext() const { return m_trackingGeoCtx; }
68+
const Acts::MagneticFieldContext& getActsMagneticFieldContext() const {
69+
return m_magneticFieldCtx;
70+
}
71+
const Acts::CalibrationContext& getActsCalibrationContext() const { return m_calibrationCtx; }
6672

6773
/// ACTS general logger that is used for running ACTS
6874
std::shared_ptr<spdlog::logger> getActsRelatedLogger() const { return m_log; }
@@ -83,7 +89,17 @@ class ActsGeometryProvider {
8389
std::map<int64_t, dd4hep::rec::Surface*> m_surfaceMap;
8490

8591
/// ACTS Tracking Geometry Context
92+
#if Acts_VERSION_MAJOR >= 45
93+
Acts::GeometryContext m_trackingGeoCtx = Acts::GeometryContext::dangerouslyDefaultConstruct();
94+
#else
8695
Acts::GeometryContext m_trackingGeoCtx;
96+
#endif
97+
98+
/// ACTS Magnetic Field Context
99+
Acts::MagneticFieldContext m_magneticFieldCtx;
100+
101+
/// ACTS Calibration Context
102+
Acts::CalibrationContext m_calibrationCtx;
87103

88104
/// ACTS Tracking Geometry
89105
std::shared_ptr<const Acts::TrackingGeometry> m_trackingGeo{nullptr};

src/algorithms/tracking/CKFTracking.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,12 @@ void CKFTracking::process(const Input& input, const Output& output) const {
223223
const auto acts_level = eicrecon::SpdlogToActsLevel(spdlog_level);
224224
ACTS_LOCAL_LOGGER(Acts::getDefaultLogger("CKF", acts_level));
225225

226-
Acts::PropagatorPlainOptions pOptions(m_geoctx, m_fieldctx);
226+
// Get run-scoped contexts from service
227+
const auto& gctx = m_geoSvc->getActsGeometryContext();
228+
const auto& mctx = m_geoSvc->getActsMagneticFieldContext();
229+
const auto& cctx = m_geoSvc->getActsCalibrationContext();
230+
231+
Acts::PropagatorPlainOptions pOptions(gctx, mctx);
227232
pOptions.maxSteps = 10000;
228233

229234
ActsExamples::PassThroughCalibrator pcalibrator;
@@ -271,10 +276,10 @@ void CKFTracking::process(const Input& input, const Output& output) const {
271276

272277
// Set the CombinatorialKalmanFilter options
273278
#if Acts_VERSION_MAJOR >= 39
274-
CKFTracking::TrackFinderOptions options(m_geoctx, m_fieldctx, m_calibctx, extensions, pOptions);
279+
CKFTracking::TrackFinderOptions options(gctx, mctx, cctx, extensions, pOptions);
275280
#else
276-
CKFTracking::TrackFinderOptions options(m_geoctx, m_fieldctx, m_calibctx, slAccessorDelegate,
277-
extensions, pOptions);
281+
CKFTracking::TrackFinderOptions options(gctx, mctx, cctx, slAccessorDelegate, extensions,
282+
pOptions);
278283
#endif
279284

280285
using Extrapolator = Acts::Propagator<Acts::EigenStepper<>, Acts::Navigator>;
@@ -290,7 +295,7 @@ void CKFTracking::process(const Input& input, const Output& output) const {
290295
Acts::Navigator({.trackingGeometry = m_geoSvc->trackingGeometry()},
291296
acts_logger().cloneWithSuffix("Navigator")),
292297
acts_logger().cloneWithSuffix("Propagator"));
293-
ExtrapolatorOptions extrapolationOptions(m_geoctx, m_fieldctx);
298+
ExtrapolatorOptions extrapolationOptions(gctx, mctx);
294299

295300
// Create track container
296301
auto trackContainer = std::make_shared<Acts::VectorTrackContainer>();
@@ -338,7 +343,7 @@ void CKFTracking::process(const Input& input, const Output& output) const {
338343
continue;
339344
}
340345

341-
auto smoothingResult = Acts::smoothTrack(m_geoctx, track, acts_logger());
346+
auto smoothingResult = Acts::smoothTrack(gctx, track, acts_logger());
342347
if (!smoothingResult.ok()) {
343348
debug("Smoothing for seed {} and track {} failed with error {}", iseed, track.index(),
344349
smoothingResult.error().message());

src/algorithms/tracking/CKFTracking.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55

66
#include <Acts/EventData/VectorMultiTrajectory.hpp>
77
#include <Acts/EventData/VectorTrackContainer.hpp>
8-
#include <Acts/Geometry/GeometryContext.hpp>
98
#include <Acts/Geometry/TrackingGeometry.hpp>
10-
#include <Acts/MagneticField/MagneticFieldContext.hpp>
119
#include <Acts/MagneticField/MagneticFieldProvider.hpp>
1210
#include <Acts/TrackFinding/CombinatorialKalmanFilter.hpp>
1311
#include <Acts/TrackFinding/MeasurementSelector.hpp>
14-
#include <Acts/Utilities/CalibrationContext.hpp>
1512
#include <Acts/Utilities/Logger.hpp>
1613
#include <Acts/Utilities/Result.hpp>
1714
#if Acts_VERSION_MAJOR < 39
@@ -90,9 +87,6 @@ class CKFTracking : public CKFTrackingAlgorithm, public WithPodConfig<eicrecon::
9087
std::shared_ptr<const ActsGeometryProvider> m_geoSvc{
9188
algorithms::ActsSvc::instance().acts_geometry_provider()};
9289
std::shared_ptr<const Acts::MagneticFieldProvider> m_BField{m_geoSvc->getFieldProvider()};
93-
Acts::MagneticFieldContext m_fieldctx{};
94-
Acts::GeometryContext m_geoctx{};
95-
Acts::CalibrationContext m_calibctx{};
9690

9791
Acts::MeasurementSelector::Config m_sourcelinkSelectorCfg;
9892

src/algorithms/tracking/IterativeVertexFinder.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <utility>
4444
#include <vector>
4545

46+
#include "ActsGeometryProvider.h"
4647
#include "algorithms/tracking/IterativeVertexFinderConfig.h"
4748
#include "extensions/spdlog/SpdlogToActs.h"
4849

@@ -101,8 +102,14 @@ void eicrecon::IterativeVertexFinder::process(const Input& input, const Output&
101102
finderCfg.trackLinearizer.connect<&Linearizer::linearizeTrack>(&linearizer);
102103
finderCfg.field = m_BField;
103104
VertexFinder finder(std::move(finderCfg));
104-
Acts::IVertexFinder::State state(std::in_place_type<VertexFinder::State>, *m_BField, m_fieldctx);
105-
VertexFinderOptions finderOpts(m_geoctx, m_fieldctx);
105+
106+
// Get run-scoped contexts from service
107+
const auto& gctx = m_geoSvc->getActsGeometryContext();
108+
const auto& mctx = m_geoSvc->getActsMagneticFieldContext();
109+
110+
Acts::IVertexFinder::State state(std::in_place_type<VertexFinder::State>, *m_BField, mctx);
111+
112+
VertexFinderOptions finderOpts(gctx, mctx);
106113

107114
std::vector<Acts::InputTrack> inputTracks;
108115
std::vector<Acts::BoundTrackParameters> trackParameters;

src/algorithms/tracking/IterativeVertexFinder.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
#include <Acts/EventData/VectorMultiTrajectory.hpp>
88
#include <Acts/EventData/VectorTrackContainer.hpp>
9-
#include <Acts/Geometry/GeometryContext.hpp>
10-
#include <Acts/MagneticField/MagneticFieldContext.hpp>
119
#include <Acts/MagneticField/MagneticFieldProvider.hpp>
1210
#include <algorithms/algorithm.h>
1311
#include <edm4eic/ReconstructedParticleCollection.h>
@@ -45,7 +43,5 @@ class IterativeVertexFinder : public IterativeVertexFinderAlgorithm,
4543
std::shared_ptr<const ActsGeometryProvider> m_geoSvc{
4644
algorithms::ActsSvc::instance().acts_geometry_provider()};
4745
std::shared_ptr<const Acts::MagneticFieldProvider> m_BField{m_geoSvc->getFieldProvider()};
48-
Acts::GeometryContext m_geoctx{};
49-
Acts::MagneticFieldContext m_fieldctx{};
5046
};
5147
} // namespace eicrecon

src/algorithms/tracking/SpacePoint.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ class SpacePoint : public edm4eic::TrackerHit {
3838
float t() const { return getTime(); }
3939
float varianceT() const { return getTimeError(); }
4040

41-
bool isOnSurface() const {
41+
bool isOnSurface(const Acts::GeometryContext& gctx) const {
4242
if (m_surface == nullptr) {
4343
return false;
4444
}
45-
return m_surface->isOnSurface(Acts::GeometryContext(), {x(), y(), z()}, {0, 0, 0});
45+
return m_surface->isOnSurface(gctx, {x(), y(), z()}, {0, 0, 0});
4646
}
4747
};
4848

src/algorithms/tracking/TrackPropagation.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,12 @@ TrackPropagation::propagate(const edm4eic::Track& /* track */,
277277
Acts::Navigator({.trackingGeometry = m_geoSvc->trackingGeometry()},
278278
logger().cloneWithSuffix("Navigator")),
279279
logger().cloneWithSuffix("Propagator"));
280-
PropagatorOptions propagationOptions(m_geoContext, m_fieldContext);
280+
281+
// Get run-scoped contexts from service
282+
const auto& gctx = m_geoSvc->getActsGeometryContext();
283+
const auto& mctx = m_geoSvc->getActsMagneticFieldContext();
284+
285+
PropagatorOptions propagationOptions(gctx, mctx);
281286

282287
auto result = propagator.propagate(initBoundParams, *targetSurf, propagationOptions);
283288

@@ -299,7 +304,7 @@ TrackPropagation::propagate(const edm4eic::Track& /* track */,
299304
trace(" path len = {}", pathLength);
300305

301306
// Position:
302-
auto projectionPos = trackStateParams.position(m_geoContext);
307+
auto projectionPos = trackStateParams.position(gctx);
303308
const decltype(edm4eic::TrackPoint::position) position{static_cast<float>(projectionPos(0)),
304309
static_cast<float>(projectionPos(1)),
305310
static_cast<float>(projectionPos(2))};

src/algorithms/tracking/TrackPropagation.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
#include <Acts/EventData/TrackProxy.hpp>
99
#include <Acts/EventData/VectorMultiTrajectory.hpp>
1010
#include <Acts/EventData/VectorTrackContainer.hpp>
11-
#include <Acts/Geometry/GeometryContext.hpp>
1211
#include <Acts/Geometry/GeometryIdentifier.hpp>
13-
#include <Acts/MagneticField/MagneticFieldContext.hpp>
1412
#include <Acts/Surfaces/Surface.hpp>
1513
#include <Acts/Utilities/Result.hpp>
1614
#include <ActsExamples/EventData/Track.hpp>
@@ -101,8 +99,6 @@ class TrackPropagation : public TrackPropagationAlgorithm,
10199
void propagateToSurfaceList(const Input& input, const Output& output) const;
102100

103101
private:
104-
Acts::GeometryContext m_geoContext;
105-
Acts::MagneticFieldContext m_fieldContext;
106102
std::shared_ptr<const ActsGeometryProvider> m_geoSvc{
107103
algorithms::ActsSvc::instance().acts_geometry_provider()};
108104
const dd4hep::Detector* m_detector{algorithms::GeoSvc::instance().detector()};

src/algorithms/tracking/TrackerMeasurementFromHits.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include <Acts/Definitions/Algebra.hpp>
77
#include <Acts/Definitions/TrackParametrization.hpp>
88
#include <Acts/Definitions/Units.hpp>
9-
#include <Acts/Geometry/GeometryContext.hpp>
109
#include <Acts/Geometry/GeometryIdentifier.hpp>
1110
#include <Acts/Surfaces/Surface.hpp>
1211
#include <Acts/Utilities/Result.hpp>
@@ -22,7 +21,6 @@
2221
#include <edm4eic/CovDiag3f.h>
2322
#include <edm4hep/Vector2f.h>
2423
#include <edm4hep/Vector3f.h>
25-
#include <fmt/core.h>
2624
#include <Eigen/Core>
2725
#include <exception>
2826
#include <unordered_map>
@@ -43,6 +41,9 @@ void TrackerMeasurementFromHits::process(const Input& input, const Output& outpu
4341
constexpr double mm_acts = Acts::UnitConstants::mm;
4442
constexpr double mm_conv = mm_acts / dd4hep::mm; // = 1/0.1
4543

44+
// Get run-scoped geometry context from service
45+
const auto& gctx = m_acts_context->getActsGeometryContext();
46+
4647
// output collections
4748
auto const& surfaceMap = m_acts_context->surfaceMap();
4849

@@ -88,10 +89,9 @@ void TrackerMeasurementFromHits::process(const Input& input, const Output& outpu
8889

8990
try {
9091
// transform global position into local coordinates
91-
// geometry context contains nothing here
9292
pos = surface
93-
->globalToLocal(Acts::GeometryContext(), {hit_pos.x, hit_pos.y, hit_pos.z},
94-
{0, 0, 0}, onSurfaceTolerance)
93+
->globalToLocal(gctx, {hit_pos.x, hit_pos.y, hit_pos.z}, {0, 0, 0},
94+
onSurfaceTolerance)
9595
.value();
9696

9797
} catch (std::exception& ex) {
@@ -111,9 +111,9 @@ void TrackerMeasurementFromHits::process(const Input& input, const Output& outpu
111111
auto local_position = (alignment.worldToLocal(
112112
{hit_pos.x / mm_conv, hit_pos.y / mm_conv, hit_pos.z / mm_conv})) *
113113
mm_conv;
114-
double surf_center_x = surface->center(Acts::GeometryContext()).transpose()[0];
115-
double surf_center_y = surface->center(Acts::GeometryContext()).transpose()[1];
116-
double surf_center_z = surface->center(Acts::GeometryContext()).transpose()[2];
114+
double surf_center_x = surface->center(gctx).transpose()[0];
115+
double surf_center_y = surface->center(gctx).transpose()[1];
116+
double surf_center_z = surface->center(gctx).transpose()[2];
117117
trace(" hit position : {:>10.2f} {:>10.2f} {:>10.2f}", hit_pos.x, hit_pos.y, hit_pos.z);
118118
trace(" local position : {:>10.2f} {:>10.2f} {:>10.2f}", local_position.x(),
119119
local_position.y(), local_position.z());

src/tests/geometry_navigation_test/GeometryNavigationSteps_processor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ class GeometryNavigationSteps_processor
4343
private:
4444
/// Directory to store histograms to
4545
TDirectory* m_dir_main{};
46+
#if Acts_VERSION_MAJOR >= 45
47+
Acts::GeometryContext m_geoContext = Acts::GeometryContext::dangerouslyDefaultConstruct();
48+
#else
4649
Acts::GeometryContext m_geoContext;
50+
#endif
4751
Acts::MagneticFieldContext m_fieldContext;
4852
std::shared_ptr<spdlog::logger> m_log;
4953
};

0 commit comments

Comments
 (0)