Skip to content

Commit

Permalink
Merge branch 'main' into ranges-of
Browse files Browse the repository at this point in the history
  • Loading branch information
AJPfleger authored Sep 4, 2024
2 parents 69aef36 + 9e1d9ef commit 1f44567
Show file tree
Hide file tree
Showing 51 changed files with 1,478 additions and 724 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
fetch-depth: 0 # To prevent shallow clone

- name: 'Download artifact'
uses: actions/github-script@v7
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ build_exatrkx_cpu:
- git checkout $HEAD_SHA
- cd ..
- mkdir build
# Here we only do a minimal build without examples to save ressources
# Here we only do a minimal build without examples to save resources
- >
cmake -B build -S src
--preset=gitlab-ci-exatrkx
Expand Down
34 changes: 33 additions & 1 deletion Core/include/Acts/EventData/SubspaceHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ inline static bool checkSubspaceIndices(const Container& container,
if (subspaceSize > fullSize) {
return false;
}
if (container.size() != subspaceSize) {
if (static_cast<std::size_t>(container.size()) != subspaceSize) {
return false;
}
for (auto it = container.begin(); it != container.end();) {
Expand Down Expand Up @@ -115,6 +115,36 @@ class SubspaceHelperBase {
auto begin() const { return self().begin(); }
auto end() const { return self().end(); }

bool contains(std::uint8_t index) const {
return std::find(begin(), end(), index) != end();
}
std::size_t indexOf(std::uint8_t index) const {
auto it = std::find(begin(), end(), index);
return it != end() ? std::distance(begin(), it) : kFullSize;
}

template <typename EigenDerived>
ActsVector<kFullSize> expandVector(
const Eigen::DenseBase<EigenDerived>& vector) const {
ActsVector<kFullSize> result = ActsVector<kFullSize>::Zero();
for (auto [i, index] : enumerate(*this)) {
result(index) = vector(i);
}
return result;
}

template <typename EigenDerived>
FullSquareMatrix expandMatrix(
const Eigen::DenseBase<EigenDerived>& matrix) const {
FullSquareMatrix result = FullSquareMatrix::Zero();
for (auto [i, indexI] : enumerate(*this)) {
for (auto [j, indexJ] : enumerate(*this)) {
result(indexI, indexJ) = matrix(i, j);
}
}
return result;
}

FullSquareMatrix fullProjector() const {
FullSquareMatrix result = FullSquareMatrix::Zero();
for (auto [i, index] : enumerate(*this)) {
Expand Down Expand Up @@ -168,6 +198,7 @@ class VariableSubspaceHelper

bool empty() const { return m_indices.empty(); }
std::size_t size() const { return m_indices.size(); }
const Container& indices() const { return m_indices; }

IndexType operator[](std::size_t i) const { return m_indices[i]; }

Expand Down Expand Up @@ -215,6 +246,7 @@ class FixedSubspaceHelper

bool empty() const { return m_indices.empty(); }
std::size_t size() const { return m_indices.size(); }
const Container& indices() const { return m_indices; }

IndexType operator[](std::uint32_t i) const { return m_indices[i]; }

Expand Down
3 changes: 2 additions & 1 deletion Core/include/Acts/Material/HomogeneousSurfaceMaterial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class HomogeneousSurfaceMaterial : public ISurfaceMaterial {
/// @copydoc ISurfaceMaterial::materialSlab(const Vector3&) const
///
/// @note the input parameter is ignored
const MaterialSlab& materialSlab(const Vector3& gp) const final;
const MaterialSlab& materialSlab(const Vector3& gp = Vector3{0., 0.,
0.}) const final;

/// The inherited methods - for MaterialSlab access
using ISurfaceMaterial::materialSlab;
Expand Down
1 change: 1 addition & 0 deletions Examples/Algorithms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_subdirectory(Geometry)
add_subdirectory(MaterialMapping)
add_subdirectory(Printers)
add_subdirectory(Propagation)
add_subdirectory_if(Traccc ACTS_BUILD_PLUGIN_TRACCC)
add_subdirectory(TrackFinding)
add_subdirectory_if(TrackFindingExaTrkX ACTS_BUILD_EXAMPLES_EXATRKX)
add_subdirectory_if(TrackFindingML ACTS_BUILD_PLUGIN_ONNX)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2021 CERN for the benefit of the Acts project
// Copyright (C) 2021-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -40,9 +40,10 @@ struct DigitizedParameters {
///
/// To be used also by the e I/O system
///
/// @return a variant measurement
Measurement createMeasurement(const DigitizedParameters& dParams,
const IndexSourceLink& isl) noexcept(false);
/// @return the measurement proxy
ActsExamples::VariableBoundMeasurementProxy createMeasurement(
MeasurementContainer& container, const DigitizedParameters& dParams,
const IndexSourceLink& isl) noexcept(false);

/// Construct the constituents of a measurement.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of the Acts project.
//
// Copyright (C) 2021 CERN for the benefit of the Acts project
// Copyright (C) 2021-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down Expand Up @@ -268,8 +268,7 @@ ActsExamples::ProcessCode ActsExamples::DigitizationAlgorithm::execute(
// be added at the end.
sourceLinks.insert(sourceLinks.end(), sourceLink);

measurements.emplace_back(
createMeasurement(dParameters, sourceLink));
createMeasurement(measurements, dParameters, sourceLink);
clusters.emplace_back(std::move(dParameters.cluster));
// this digitization does hit merging so there can be more than one
// mapping entry for each digitized hit.
Expand Down
47 changes: 23 additions & 24 deletions Examples/Algorithms/Digitization/src/MeasurementCreation.cpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
// This file is part of the Acts project.
//
// Copyright (C) 2021 CERN for the benefit of the Acts project
// Copyright (C) 2021-2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "ActsExamples/Digitization/MeasurementCreation.hpp"

#include "Acts/EventData/MeasurementHelpers.hpp"
#include "Acts/EventData/SourceLink.hpp"
#include "ActsExamples/EventData/IndexSourceLink.hpp"
#include "ActsExamples/EventData/Measurement.hpp"

#include <stdexcept>
#include <string>
#include <utility>

ActsExamples::Measurement ActsExamples::createMeasurement(
const DigitizedParameters& dParams, const IndexSourceLink& isl) {
ActsExamples::VariableBoundMeasurementProxy ActsExamples::createMeasurement(
MeasurementContainer& container, const DigitizedParameters& dParams,
const IndexSourceLink& isl) {
Acts::SourceLink sl{isl};
switch (dParams.indices.size()) {
case 1u: {
auto [indices, par, cov] = measurementConstituents<1>(dParams);
return ActsExamples::Measurement(std::move(sl), indices, par, cov);
}
case 2u: {
auto [indices, par, cov] = measurementConstituents<2>(dParams);
return ActsExamples::Measurement(std::move(sl), indices, par, cov);
};
case 3u: {
auto [indices, par, cov] = measurementConstituents<3>(dParams);
return ActsExamples::Measurement(std::move(sl), indices, par, cov);
};
case 4u: {
auto [indices, par, cov] = measurementConstituents<4>(dParams);
return ActsExamples::Measurement(std::move(sl), indices, par, cov);
};
default:
std::string errorMsg = "Invalid/mismatching measurement dimension: " +
std::to_string(dParams.indices.size());
throw std::runtime_error(errorMsg.c_str());

if (dParams.indices.size() > 4u) {
std::string errorMsg = "Invalid/mismatching measurement dimension: " +
std::to_string(dParams.indices.size());
throw std::runtime_error(errorMsg.c_str());
}

return Acts::visit_measurement(
dParams.indices.size(), [&](auto dim) -> VariableBoundMeasurementProxy {
auto [indices, par, cov] = measurementConstituents<dim>(dParams);
FixedBoundMeasurementProxy<dim> measurement =
container.makeMeasurement<dim>();
measurement.setSourceLink(sl);
measurement.setSubspaceIndices(indices);
measurement.parameters() = par;
measurement.covariance() = cov;
return measurement;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#include <string>
#include <unordered_map>

namespace Acts {
class Surface;
}

namespace ActsExamples {

class PropagatorInterface;
Expand Down
17 changes: 17 additions & 0 deletions Examples/Algorithms/Traccc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
add_library(ActsExamplesTraccc INTERFACE)

target_include_directories(
ActsExamplesTraccc
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

target_link_libraries(
ActsExamplesTraccc
INTERFACE
ActsCore
ActsExamplesFramework
ActsExamplesPropagation
ActsPluginDetray
)

install(TARGETS ActsExamplesTraccc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// This file is part of the Acts project.
//
// Copyright (C) 2024 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#pragma once

#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "Acts/Utilities/Result.hpp"
#include "ActsExamples/EventData/PropagationSummary.hpp"
#include "ActsExamples/Propagation/PropagationAlgorithm.hpp"
#include "ActsExamples/Propagation/PropagatorInterface.hpp"
#include "ActsExamples/Traccc/DetrayStore.hpp"

#include <detray/navigation/navigator.hpp>
#include <detray/utils/inspectors.hpp>

namespace ActsExamples {

/// Define the algebra type
using DetrayAlgebraType = typename Acts::DetrayHostDetector::algebra_type;

/// Type that holds the intersection information
using DetrayIntersection =
detray::intersection2D<typename Acts::DetrayHostDetector::surface_type,
DetrayAlgebraType>;

/// Inspector that records all encountered surfaces
using DetrayObjectTracer =
detray::navigation::object_tracer<DetrayIntersection, detray::dvector,
detray::navigation::status::e_on_module,
detray::navigation::status::e_on_portal>;

/// Inspector that prints the navigator state from within the navigator's
/// method calls (cannot be done with an actor)
using DetrayPrintInspector = detray::navigation::print_inspector;

template <typename propagator_t, typename detray_store_t>
class DetrayPropagator : public PropagatorInterface {
public:
/// Create a DetrayPropagator
///
/// @param propagator The actual detray propagator to wrap
/// @param detrayStore The detray store to access the detector
/// @param logger The logger instance
DetrayPropagator(propagator_t&& propagator,
std::shared_ptr<const detray_store_t> detrayStore,
std::unique_ptr<const Acts::Logger> logger =
Acts::getDefaultLogger("DetrayPropagator",
Acts::Logging::INFO))
: PropagatorInterface(),
m_propagator(std::move(propagator)),
m_detrayStore(std::move(detrayStore)),
m_logger(std::move(logger)) {}

///@brief Execute a propagation for charged particle parameters
///
///@param context The algorithm context
///@param cfg The propagation algorithm configuration
///@param logger A logger wrapper instance
///@param startParameters The start parameters
///@return PropagationOutput
Acts::Result<PropagationOutput> execute(
const AlgorithmContext& context,
[[maybe_unused]] const PropagationAlgorithm::Config& cfg,
const Acts::Logger& logger,
const Acts::BoundTrackParameters& startParameters) const final {
// Get the geometry context form the algorithm context
const auto& geoContext = context.geoContext;
// Get the track information
const Acts::Vector3 position = startParameters.position(geoContext);
const Acts::Vector3 direction = startParameters.momentum().normalized();

ACTS_VERBOSE("Starting propagation at " << position.transpose()
<< " with direction "
<< direction.transpose());

// Now follow that ray with the same track and check, if we find
// the same volumes and distances along the way
detray::free_track_parameters<DetrayAlgebraType> track(
{position.x(), position.y(), position.z()}, 0.f,
{direction.x(), direction.y(), direction.z()},
startParameters.charge());

typename propagator_t::state propagation(track, m_detrayStore->detector);

// Run the actual propagation
m_propagator.propagate(propagation);

// Retrieve navigation information
auto& inspector = propagation._navigation.inspector();
auto& objectTracer = inspector.template get<DetrayObjectTracer>();

PropagationSummary summary(startParameters);
// Translate the objects into the steps
for (const auto& object : objectTracer.object_trace) {
// Get the position of the object
const auto& dposition = object.pos;
const auto& sfDesription = object.intersection.sf_desc;
const auto sf =
detray::tracking_surface{m_detrayStore->detector, sfDesription};
Acts::GeometryIdentifier geoID{sf.source()};
// Create a step from the object
Acts::detail::Step step;
step.position = Acts::Vector3(dposition[0], dposition[1], dposition[2]);
step.geoID = geoID;
step.navDir = object.intersection.direction ? Acts::Direction::Forward
: Acts::Direction::Backward;
summary.steps.emplace_back(step);
}
RecordedMaterial recordedMaterial;
return std::pair{std::move(summary), std::move(recordedMaterial)};
}

private:
/// The propagator @todo fix when propagate() method is const in detray
mutable propagator_t m_propagator;

/// The detray detector store and memory resource
std::shared_ptr<const detray_store_t> m_detrayStore = nullptr;

/// The logging instance
std::unique_ptr<const Acts::Logger> m_logger = nullptr;

const Acts::Logger& logger() const { return *m_logger; }
};

} // namespace ActsExamples
Loading

0 comments on commit 1f44567

Please sign in to comment.