Skip to content
25 changes: 25 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,31 @@ find_package(
atomic
regex)

# Find Eigen3 (required by ACTS)
find_package(Eigen3 CONFIG REQUIRED)

# GNUInstallDirs must be included before ACTS is configured as a sub-project;
# ACTS only calls include(GNUInstallDirs) when it is the top-level project, so
# CMAKE_INSTALL_INCLUDEDIR would otherwise be empty and its install() calls fail.
include(GNUInstallDirs)

# Find or fetch ACTS - must be at top level so both Ecal and Tracking can use it
find_package(Acts 47.0.0 QUIET)
if (NOT Acts_FOUND)
message(STATUS "Did not find Acts >= 47.0.0, downloading and compiling v47.0.0")
Comment thread
tomeichlersmith marked this conversation as resolved.
include(FetchContent)
FetchContent_Declare(
Acts
URL https://github.com/acts-project/acts/archive/refs/tags/v47.0.0.tar.gz
URL_HASH MD5=833c02edee49827f25be74c80d8ee654
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
FetchContent_MakeAvailable(Acts)
FetchContent_GetProperties(Acts)
include_directories(SYSTEM "${Acts_SOURCE_DIR}/Core/include")
else()
message(STATUS "Found Acts ${Acts_VERSION}")
endif()

# FunctionalCoreTest.cxx doesnt comply with clang-tidy but that's ok
set_source_files_properties(Framework/test/FunctionalCoreTest.cxx PROPERTIES COMPILE_OPTIONS "-Wno-null-dereference")
Expand Down
6 changes: 2 additions & 4 deletions Ecal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ setup_library(
find_package(ONNXRuntime 1.2.0)

find_package(Eigen3 CONFIG REQUIRED)

# Find ACTS for track finding in ECAL
find_package(Acts REQUIRED COMPONENTS Core)
# Acts is set up by the top-level CMakeLists.txt

setup_library(module Ecal
dependencies ROOT::Physics
Framework::Framework Recon::Event Recon::Recon Tools::Tools DetDescr::DetDescr
ONNXRuntime::Interface Ecal::Event Tracking::Event Tracking::Tracking SimCore::Event
Eigen3::Eigen ActsCore
Eigen3::Eigen Acts::Core
)

setup_test(dependencies Ecal::Ecal)
Expand Down
2 changes: 2 additions & 0 deletions Ecal/include/Ecal/EcalTrackFinderProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "Acts/Surfaces/RectangleBounds.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/TrackFinding/CombinatorialKalmanFilter.hpp"
#include "Acts/TrackFinding/MeasurementSelector.hpp"
#include "Acts/TrackFinding/TrackStateCreator.hpp"
#include "Acts/TrackFitting/GainMatrixUpdater.hpp"

// C++
Expand Down
79 changes: 39 additions & 40 deletions Ecal/src/Ecal/EcalTrackFinderProcessor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@

// ACTS
#include "Acts/Definitions/Units.hpp"
#include "Acts/EventData/BoundTrackParameters.hpp"
#include "Acts/EventData/MultiTrajectory.hpp"
#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/EventData/TransformationHelpers.hpp"
#include "Acts/Geometry/CuboidVolumeBuilder.hpp"
#include "Acts/Geometry/GeometryContext.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Geometry/TrackingGeometryBuilder.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/MagneticField/MagneticFieldContext.hpp"
#include "Acts/Propagator/AbortList.hpp"
#include "Acts/Propagator/ActionList.hpp"
#include "Acts/Propagator/ActorList.hpp"
#include "Acts/Propagator/MaterialInteractor.hpp"
#include "Acts/Propagator/StandardAborters.hpp"
#include "Acts/Propagator/detail/SteppingLogger.hpp"
Expand Down Expand Up @@ -143,7 +142,8 @@ void EcalTrackFinderProcessor::onNewRun(const ldmx::RunHeader&) {
ecal_vol_cfg.name = "EcalVolume";
ecal_vol_cfg.layerCfg = layer_configs;
ecal_vol_cfg.volumeMaterial =
std::make_shared<Acts::HomogeneousVolumeMaterial>(Acts::Material());
std::make_shared<Acts::HomogeneousVolumeMaterial>(
Acts::Material::Vacuum());

// Build the tracking geometry
Acts::CuboidVolumeBuilder cvb;
Expand Down Expand Up @@ -240,9 +240,8 @@ void EcalTrackFinderProcessor::createEcalSurfaces() {
Acts::Surface::makeShared<Acts::PlaneSurface>(transform, bounds);

// Assign a geometry ID (use layer as volume, 0 as layer in ACTS sense)
Acts::GeometryIdentifier geo_id;
geo_id.setVolume(layer);
geo_id.setLayer(0);
Acts::GeometryIdentifier geo_id =
Acts::GeometryIdentifier().withVolume(layer).withLayer(0);
surface->assignGeometryId(geo_id);

layer_surfaces_[layer] = surface;
Expand Down Expand Up @@ -404,7 +403,7 @@ std::vector<ldmx::Track> EcalTrackFinderProcessor::findSeeds(
// For a plane surface, normal is the third column of rotation (z-direction in
// local frame)
Acts::Vector3 ref_normal =
reference_surface_->transform(gctx).rotation().col(2);
reference_surface_->localToGlobalTransform(gctx).rotation().col(2);
Acts::Vector3 ref_center = reference_surface_->center(gctx);

double t =
Expand All @@ -416,7 +415,7 @@ std::vector<ldmx::Track> EcalTrackFinderProcessor::findSeeds(
Acts::Vector3 seed_mom = p_estimate * direction;

// Charge (assume positive)
Acts::ActsScalar q = Acts::UnitConstants::e;
double q = Acts::UnitConstants::e;

// Convert to bound parameters at reference surface
Acts::FreeVector seed_free =
Expand All @@ -441,7 +440,7 @@ std::vector<ldmx::Track> EcalTrackFinderProcessor::findSeeds(
stddev[Acts::eBoundQOverP] = 0.5 / p_estimate; // 50% uncertainty
stddev[Acts::eBoundTime] = 10.0 * Acts::UnitConstants::ns;

Acts::BoundSquareMatrix bound_cov = stddev.cwiseProduct(stddev).asDiagonal();
Acts::BoundMatrix bound_cov = stddev.cwiseProduct(stddev).asDiagonal();

// Create ldmx::Track seed
ldmx::Track seed;
Expand Down Expand Up @@ -568,18 +567,7 @@ void EcalTrackFinderProcessor::produce(framework::Event& event) {

tracking::sim::LdmxMeasurementCalibrator calibrator{measurements};

Acts::CombinatorialKalmanFilterExtensions<TrackContainer> ckf_extensions;
ckf_extensions.calibrator
.connect<&tracking::sim::LdmxMeasurementCalibrator::calibrate<
Acts::VectorMultiTrajectory>>(&calibrator);
ckf_extensions.updater.connect<
&Acts::GainMatrixUpdater::operator()<Acts::VectorMultiTrajectory>>(
&kf_updater);
ckf_extensions.measurementSelector
.connect<&Acts::MeasurementSelector::select<Acts::VectorMultiTrajectory>>(
&meas_sel);

// Setup source link accessor
// Setup source link accessor iterator type and lambda
struct SourceLinkAccIt {
using BaseIt = decltype(geo_id_sl_map.begin());
BaseIt it_;
Expand Down Expand Up @@ -613,11 +601,25 @@ void EcalTrackFinderProcessor::produce(framework::Event& event) {
return {SourceLinkAccIt{begin}, SourceLinkAccIt{end}};
};

Acts::SourceLinkAccessorDelegate<SourceLinkAccIt>
source_link_accessor_delegate;
source_link_accessor_delegate
// v46: calibrator and measurementSelector moved to TrackStateCreator
Acts::TrackStateCreator<SourceLinkAccIt, TrackContainer> track_state_creator;
track_state_creator.sourceLinkAccessor
.connect<&decltype(source_link_accessor)::operator(),
decltype(source_link_accessor)>(&source_link_accessor);
track_state_creator.calibrator
.connect<&tracking::sim::LdmxMeasurementCalibrator::calibrate<
Acts::VectorMultiTrajectory>>(&calibrator);
track_state_creator.measurementSelector
.connect<&Acts::MeasurementSelector::select<Acts::VectorMultiTrajectory>>(
&meas_sel);

Acts::CombinatorialKalmanFilterExtensions<TrackContainer> ckf_extensions;
ckf_extensions.updater.connect<
&Acts::GainMatrixUpdater::operator()<Acts::VectorMultiTrajectory>>(
&kf_updater);
ckf_extensions.createTrackStates.connect<&Acts::TrackStateCreator<
SourceLinkAccIt, TrackContainer>::createTrackStates>(
&track_state_creator);

// Create track container
Acts::VectorTrackContainer vtc;
Expand All @@ -640,18 +642,16 @@ void EcalTrackFinderProcessor::produce(framework::Event& event) {
<< " loc1=" << param_vec[1] << " phi=" << param_vec[2]
<< " theta=" << param_vec[3] << " qop=" << param_vec[4];

Acts::BoundSquareMatrix cov_mat =
Acts::BoundMatrix cov_mat =
tracking::sim::utils::unpackCov(seed.getPerigeeCov());

auto part_hypo{Acts::SinglyChargedParticleHypothesis::electron()};
auto part_hypo{Acts::ParticleHypothesis::electron()};
Acts::BoundTrackParameters start_params(reference_surface_, param_vec,
cov_mat, part_hypo);

// Setup CKF options
const Acts::CombinatorialKalmanFilterOptions<SourceLinkAccIt,
TrackContainer>
ckf_options(gctx, mctx, cctx, source_link_accessor_delegate,
ckf_extensions, propagator_options);
const Acts::CombinatorialKalmanFilterOptions<TrackContainer> ckf_options(
gctx, mctx, cctx, ckf_extensions, propagator_options);

// Run CKF
auto results = ckf_->findTracks(start_params, ckf_options, tc);
Expand Down Expand Up @@ -766,11 +766,10 @@ void EcalTrackFinderProcessor::produce(framework::Event& event) {

// Add measurement indices
for (const auto ts : track.trackStatesReversed()) {
if (ts.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag) &&
ts.hasUncalibratedSourceLink()) {
const acts_examples::IndexSourceLink sl =
ts.getUncalibratedSourceLink()
.template get<acts_examples::IndexSourceLink>();
if (ts.typeFlags().isMeasurement() && ts.hasUncalibratedSourceLink()) {
Acts::SourceLink usl = ts.getUncalibratedSourceLink();
const acts_examples::IndexSourceLink& sl =
usl.get<acts_examples::IndexSourceLink>();
trk.addMeasurementIndex(sl.index());
}
}
Expand Down Expand Up @@ -832,11 +831,11 @@ void EcalTrackFinderProcessor::produce(framework::Event& event) {
} else {
// Fallback: sum on-track hit energies only
for (const auto ts : track.trackStatesReversed()) {
if (ts.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag) &&
if (ts.typeFlags().isMeasurement() &&
ts.hasUncalibratedSourceLink()) {
const acts_examples::IndexSourceLink sl =
ts.getUncalibratedSourceLink()
.template get<acts_examples::IndexSourceLink>();
Acts::SourceLink usl = ts.getUncalibratedSourceLink();
const acts_examples::IndexSourceLink& sl =
usl.get<acts_examples::IndexSourceLink>();
track_energy += measurement_energies[sl.index()];
}
}
Expand Down
24 changes: 2 additions & 22 deletions Tracking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,7 @@ setup_library(
)

find_package(Eigen3 CONFIG REQUIRED)
# if you want to try an alternate Acts, you can
# 1. comment out the stuff here and replace with add_subdirectory(acts)
# 2. git clone acts into this directory and choose your version
find_package(Acts QUIET)
if (NOT Acts_FOUND)
message(STATUS "Did not find Acts, downloading and compiling it here")
include(FetchContent)
FetchContent_Declare(
Acts
URL https://github.com/acts-project/acts/archive/refs/tags/v36.0.0.tar.gz
URL_HASH MD5=f543dd8ba030bea2e4ee2f1b07dbe7c0
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
)
FetchContent_MakeAvailable(Acts)
FetchContent_GetProperties(Acts)
# Adding Acts as "SYSTEM"
# which will silence compiler warnings from these 3rd party softwares
include_directories(SYSTEM "${Acts_SOURCE_DIR}/Core/include")
else()
message(STATUS "Found Acts ${Acts_VERSION}")
endif()
# Acts is set up by the top-level CMakeLists.txt

file(GLOB SRC_FILES CONFIGURE_DEPENDS
${PROJECT_SOURCE_DIR}/src/Tracking/Sim/[a-zA-z]*.cxx
Expand All @@ -55,7 +35,7 @@ list(APPEND SRC_FILES
setup_library(module Tracking
dependencies Framework::Configure
Framework::Framework
ActsCore
Acts::Core
Geant4::Interface
ROOT::Physics
Tracking::Event
Expand Down
2 changes: 1 addition & 1 deletion Tracking/include/Tracking/Reco/ActsUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/Definitions/Units.hpp"
#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/EventData/BoundTrackParameters.hpp"
#include "Acts/Surfaces/PerigeeSurface.hpp"

namespace tracking {
Expand Down
29 changes: 17 additions & 12 deletions Tracking/include/Tracking/Reco/CKFProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "Acts/Definitions/Common.hpp"
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/Definitions/Units.hpp"
#include "Acts/EventData/TrackParameters.hpp"
#include "Acts/EventData/BoundTrackParameters.hpp"
#include "Acts/Utilities/Logger.hpp"

// geometry
Expand All @@ -35,13 +35,13 @@

// propagation testing
#include "Acts/MagneticField/ConstantBField.hpp"
#include "Acts/Propagator/AbortList.hpp"
#include "Acts/Propagator/ActionList.hpp"
#include "Acts/Propagator/DenseEnvironmentExtension.hpp"
#include "Acts/Propagator/ActorList.hpp"
#include "Acts/Propagator/EigenStepperDenseExtension.hpp"
#include "Acts/Propagator/MaterialInteractor.hpp"
#include "Acts/Propagator/Navigator.hpp"
#include "Acts/Propagator/Propagator.hpp"
#include "Acts/Propagator/StandardAborters.hpp"
#include "Acts/Propagator/VoidNavigator.hpp"
#include "Acts/Propagator/detail/SteppingLogger.hpp"
#include "Acts/Surfaces/PerigeeSurface.hpp"
#include "Acts/Utilities/Logger.hpp"
Expand All @@ -55,7 +55,7 @@
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/TrackFinding/CombinatorialKalmanFilter.hpp"
#include "Acts/TrackFinding/MeasurementSelector.hpp"
#include "Acts/TrackFitting/GainMatrixSmoother.hpp"
#include "Acts/TrackFinding/TrackStateCreator.hpp"
#include "Acts/TrackFitting/GainMatrixUpdater.hpp"
#include "Acts/Utilities/CalibrationContext.hpp"

Expand All @@ -78,13 +78,14 @@
#include "Tracking/Sim/BFieldXYZUtils.h"
// mg Aug 2024 not sure if these are needed...
using Updater = Acts::GainMatrixUpdater;
using Smoother = Acts::GainMatrixSmoother;

using ActionList =
Acts::ActionList<Acts::detail::SteppingLogger, Acts::MaterialInteractor>;
using AbortList = Acts::AbortList<Acts::EndOfWorldReached>;
Acts::ActorList<Acts::detail::SteppingLogger, Acts::MaterialInteractor,
Acts::EndOfWorldReached>;

using CkfPropagator = Acts::Propagator<Acts::EigenStepper<>, Acts::Navigator>;
using ExtrapPropagator =
Acts::Propagator<Acts::EigenStepper<>, Acts::VoidNavigator>;
using TrackContainer = Acts::TrackContainer<Acts::VectorTrackContainer,
Acts::VectorMultiTrajectory>;

Expand Down Expand Up @@ -222,24 +223,28 @@ class CKFProcessor final : public TrackingGeometryUser {
const Acts::CombinatorialKalmanFilter<CkfPropagator, TrackContainer>>
ckf_;

// Track Extrapolator Tool
std::shared_ptr<tracking::reco::TrackExtrapolatorTool<CkfPropagator>>
// Track Extrapolator Tool (uses VoidNavigator to propagate freely to any
// surface)
std::unique_ptr<const ExtrapPropagator> propagator_extrap_;
std::shared_ptr<tracking::reco::TrackExtrapolatorTool<ExtrapPropagator>>
trk_extrap_;

// Zero-B CKF as fallback
std::unique_ptr<const CkfPropagator> propagator_zero_b_;
std::unique_ptr<
const Acts::CombinatorialKalmanFilter<CkfPropagator, TrackContainer>>
ckf_zero_b_;
std::shared_ptr<tracking::reco::TrackExtrapolatorTool<CkfPropagator>>
std::unique_ptr<const ExtrapPropagator> propagator_extrap_zero_b_;
std::shared_ptr<tracking::reco::TrackExtrapolatorTool<ExtrapPropagator>>
trk_extrap_zero_b_;

// Const-B (1.5T) CKF as fallback for tagger
std::unique_ptr<const CkfPropagator> propagator_const_b_;
std::unique_ptr<
const Acts::CombinatorialKalmanFilter<CkfPropagator, TrackContainer>>
ckf_const_b_;
std::shared_ptr<tracking::reco::TrackExtrapolatorTool<CkfPropagator>>
std::unique_ptr<const ExtrapPropagator> propagator_extrap_const_b_;
std::shared_ptr<tracking::reco::TrackExtrapolatorTool<ExtrapPropagator>>
trk_extrap_const_b_;

/// n seeds and n tracks
Expand Down
Loading