From 8fe820fc6e6828c45cde8040ec35a2a82f248820 Mon Sep 17 00:00:00 2001 From: Frederik Date: Thu, 20 Jun 2024 17:26:55 +0200 Subject: [PATCH] Format --- .../Acts/Geometry/GeometryHierarchyMap.hpp | 5 +- .../Digitization/DigitizationAlgorithm.hpp | 3 +- .../src/DigitizationAlgorithm.cpp | 11 +- .../Common/Conversion/CellMapConversion.hpp | 4 +- .../Conversion/DigitizationConversion.hpp | 2 +- .../Conversion/MeasurementConversion.hpp | 32 ++- .../ActsExamples/Traccc/Common/Converter.hpp | 269 +++++++++--------- .../Traccc/Common/Measurement/Debug.hpp | 15 +- .../Common/Measurement/MeasurementMatch.hpp | 85 ++++-- .../Common/TracccChainAlgorithmBase.hpp | 117 ++++---- .../Traccc/Common/TracccChainConfig.hpp | 42 +-- .../Traccc/Common/Util/IndexMap.hpp | 145 +++++----- .../src/Conversion/CellMapConversion.cpp | 67 +++-- .../src/Conversion/DigitizationConversion.cpp | 28 +- .../src/Conversion/MeasurementConversion.cpp | 5 +- .../Traccc/Common/src/Debug/Debug.cpp | 137 ++++----- .../Common/src/TracccChainAlgorithmBase.cpp | 63 ++-- .../Traccc/Host/TracccChainAlgorithm.hpp | 52 ++-- .../ActsExamples/Traccc/Host/Types.hpp | 35 ++- .../Traccc/Host/src/TracccChainAlgorithm.cpp | 70 +++-- 20 files changed, 631 insertions(+), 556 deletions(-) diff --git a/Core/include/Acts/Geometry/GeometryHierarchyMap.hpp b/Core/include/Acts/Geometry/GeometryHierarchyMap.hpp index c4a19d45e91e..63735ac00821 100644 --- a/Core/include/Acts/Geometry/GeometryHierarchyMap.hpp +++ b/Core/include/Acts/Geometry/GeometryHierarchyMap.hpp @@ -93,10 +93,11 @@ class GeometryHierarchyMap { /// Return the number of stored elements. Size size() const { return m_values.size(); } - // Return the geometry identifier - value pairs (i.e., it reconstructs the input). + // Return the geometry identifier - value pairs (i.e., it reconstructs the + // input). const std::vector getElements() const { std::vector res; - for (std::size_t i = 0; i < size(); i++){ + for (std::size_t i = 0; i < size(); i++) { res.push_back({m_ids[i], m_values[i]}); } return res; diff --git a/Examples/Algorithms/Digitization/include/ActsExamples/Digitization/DigitizationAlgorithm.hpp b/Examples/Algorithms/Digitization/include/ActsExamples/Digitization/DigitizationAlgorithm.hpp index 1989c137cdcb..9163fae710de 100644 --- a/Examples/Algorithms/Digitization/include/ActsExamples/Digitization/DigitizationAlgorithm.hpp +++ b/Examples/Algorithms/Digitization/include/ActsExamples/Digitization/DigitizationAlgorithm.hpp @@ -95,7 +95,8 @@ class DigitizationAlgorithm final : public IAlgorithm { /// Geometric digtizer ActsFatras::Channelizer m_channelizer; - using CellsMap = std::map>; + using CellsMap = + std::map>; ReadDataHandle m_simContainerReadHandle{this, "SimHitContainer"}; diff --git a/Examples/Algorithms/Digitization/src/DigitizationAlgorithm.cpp b/Examples/Algorithms/Digitization/src/DigitizationAlgorithm.cpp index e971f61ded86..da3c36dd0ed7 100644 --- a/Examples/Algorithms/Digitization/src/DigitizationAlgorithm.cpp +++ b/Examples/Algorithms/Digitization/src/DigitizationAlgorithm.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -153,7 +154,7 @@ ActsExamples::ProcessCode ActsExamples::DigitizationAlgorithm::execute( // Some statistics std::size_t skippedHits = 0; - + // Some algorithms do the clusterization themselves such as the traccc chain. // Thus we need to store the cell data from the simulation. CellsMap cellsMap; @@ -217,8 +218,6 @@ ActsExamples::ProcessCode ActsExamples::DigitizationAlgorithm::execute( simHit, *surfacePtr, ctx.geoContext, driftDir, cfg.segmentation, cfg.thickness); - - if (!channelsRes.ok() || channelsRes->empty()) { ACTS_DEBUG( "Geometric channelization did not work, skipping this hit.") @@ -266,7 +265,7 @@ ActsExamples::ProcessCode ActsExamples::DigitizationAlgorithm::execute( // Store the data of the cells from the simulation. std::vector cells; for (auto& [dParameters, simhits] : digitizeParametersResult) { - for (auto cell : dParameters.cluster.channels){ + for (auto cell : dParameters.cluster.channels) { cells.push_back(std::move(cell)); } } @@ -327,9 +326,9 @@ ActsExamples::DigitizationAlgorithm::localParameters( Acts::ActsScalar totalWeight = 0.; Acts::Vector2 m(0., 0.); - std::size_t b0min = SIZE_MAX; + std::size_t b0min = std::numeric_limits::max(); std::size_t b0max = 0; - std::size_t b1min = SIZE_MAX; + std::size_t b1min = std::numeric_limits::max(); std::size_t b1max = 0; // Combine the channels for (const auto& ch : channels) { diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Conversion/CellMapConversion.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Conversion/CellMapConversion.hpp index 387ab6a31ffc..61ec39fe5cc1 100644 --- a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Conversion/CellMapConversion.hpp +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Conversion/CellMapConversion.hpp @@ -20,8 +20,8 @@ // System include(s). #include #include -#include #include +#include namespace ActsExamples::Traccc::Common::Conversion { @@ -31,4 +31,4 @@ namespace ActsExamples::Traccc::Common::Conversion { std::map> tracccCellsMap( const std::map>& map); -} +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Conversion/DigitizationConversion.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Conversion/DigitizationConversion.hpp index dc4328290d88..715962a5f523 100644 --- a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Conversion/DigitizationConversion.hpp +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Conversion/DigitizationConversion.hpp @@ -26,4 +26,4 @@ namespace ActsExamples::Traccc::Common::Conversion { traccc::digitization_config tracccConfig( const Acts::GeometryHierarchyMap& config); -} +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Conversion/MeasurementConversion.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Conversion/MeasurementConversion.hpp index a6c99464db1b..1cd806b4dc8c 100644 --- a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Conversion/MeasurementConversion.hpp +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Conversion/MeasurementConversion.hpp @@ -32,10 +32,10 @@ #include "traccc/edm/track_state.hpp" // System include(s) -#include -#include #include #include +#include +#include #include namespace ActsExamples::Traccc::Common::Conversion { @@ -43,8 +43,7 @@ namespace ActsExamples::Traccc::Common::Conversion { /// @brief Converts a traccc bound index to an Acts bound index. /// @param tracccBoundIndex the traccc bound index. /// @returns an Acts bound index. -Acts::BoundIndices boundIndex( - const traccc::bound_indices tracccBoundIndex); +Acts::BoundIndices boundIndex(const traccc::bound_indices tracccBoundIndex); /// @brief Creates an Acts measurement from a traccc measurement. /// @tparam the dimension of the Acts measurement (subspace size). @@ -158,16 +157,19 @@ inline Acts::ActsVector<2> getVariance( /// @return A vector of Acts bound variant measurements. /// @note The type IndexSourceLink is used for the measurements' source links. template -inline auto createActsMeasurements(const detector_t& detector, const std::vector& measurements){ - std::vector measurementContainer; - for (const traccc::measurement& m : measurements) - { - Acts::GeometryIdentifier moduleGeoId(detector.surface(m.surface_link).source); - Index measurementIdx = measurementContainer.size(); - IndexSourceLink idxSourceLink{moduleGeoId, measurementIdx}; - measurementContainer.push_back(boundVariantMeasurement(m, Acts::SourceLink{idxSourceLink})); - } - return measurementContainer; +inline auto createActsMeasurements( + const detector_t& detector, + const std::vector& measurements) { + std::vector measurementContainer; + for (const traccc::measurement& m : measurements) { + Acts::GeometryIdentifier moduleGeoId( + detector.surface(m.surface_link).source); + Index measurementIdx = measurementContainer.size(); + IndexSourceLink idxSourceLink{moduleGeoId, measurementIdx}; + measurementContainer.push_back( + boundVariantMeasurement(m, Acts::SourceLink{idxSourceLink})); + } + return measurementContainer; } -} +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Converter.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Converter.hpp index c881adf2281f..dea5c6eae121 100644 --- a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Converter.hpp +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Converter.hpp @@ -13,22 +13,22 @@ #include "Acts/Plugins/Traccc/TrackConversion.hpp" // Acts Examples include(s) +#include "ActsExamples/EventData/Track.hpp" #include "ActsExamples/Traccc/Common/Conversion/CellMapConversion.hpp" #include "ActsExamples/Traccc/Common/Conversion/DigitizationConversion.hpp" #include "ActsExamples/Traccc/Common/Conversion/MeasurementConversion.hpp" -#include "ActsExamples/Traccc/Common/Measurement/MeasurementMatch.hpp" #include "ActsExamples/Traccc/Common/Measurement/Debug.hpp" +#include "ActsExamples/Traccc/Common/Measurement/MeasurementMatch.hpp" #include "ActsExamples/Traccc/Common/Util/IndexMap.hpp" -#include "ActsExamples/EventData/Track.hpp" // Acts include(s) -#include "Acts/Utilities/Logger.hpp" -#include "ActsExamples/EventData/Measurement.hpp" +#include "Acts/Definitions/Algebra.hpp" #include "Acts/EventData//TrackContainer.hpp" -#include "Acts/EventData/VectorTrackContainer.hpp" #include "Acts/EventData/VectorMultiTrajectory.hpp" +#include "Acts/EventData/VectorTrackContainer.hpp" #include "Acts/Geometry/TrackingGeometry.hpp" -#include "Acts/Definitions/Algebra.hpp" +#include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/EventData/Measurement.hpp" // Detray include(s). #include "detray/core/detector.hpp" @@ -41,148 +41,158 @@ // System include(s) #include -#include #include +#include namespace ActsExamples::Traccc::Common { /// @brief Class for converting Acts data to traccc data. class Converter { -private: - -using detector_t = detray::detector; - -const Acts::TrackingGeometry& trackingGeometry; -const detector_t& detector; - -// Cache the converted digitalization configuration, the surface transforms, and the barcode map. -const traccc::digitization_config digitizationConfig; -const traccc::geometry surfaceTransforms; -const std::map barcodeMap; - -const Acts::Logger& actsLogger; - -/// @brief Writes the number of traccc measurements and Acts measurements to the logger. -/// If the number of measurements do not matching a warning is shown. -/// @param tracccMeasurements the traccc measurements. -/// @param measurements the Acts measurements. -template -void logMeasurementCountComparison( - const std::vector& tracccMeasurements, - const std::vector& measurements) const { - - if (tracccMeasurements.size() != measurements.size()){ - std::stringstream ss; - ss << "Number of measurements do not match (traccc: " - << tracccMeasurements.size() - << ", acts: " << measurements.size() - << ")\n" - << "Perhaps mergeCommonCorner or doMerge is false in the digitization algorithm config?"; - ACTS_WARNING(ss.str()); - }else{ - std::stringstream ss; - ss << "Number of Acts and Traccc measurements match (count: " - << measurements.size() << ")"; - ACTS_INFO(ss.str()); + private: + using detector_t = + detray::detector; + + const Acts::TrackingGeometry& trackingGeometry; + const detector_t& detector; + + // Cache the converted digitalization configuration, the surface transforms, + // and the barcode map. + const traccc::digitization_config digitizationConfig; + const traccc::geometry surfaceTransforms; + const std::map barcodeMap; + + const Acts::Logger& actsLogger; + + /// @brief Writes the number of traccc measurements and Acts measurements to the logger. + /// If the number of measurements do not matching a warning is shown. + /// @param tracccMeasurements the traccc measurements. + /// @param measurements the Acts measurements. + template + void logMeasurementCountComparison( + const std::vector& tracccMeasurements, + const std::vector& measurements) const { + if (tracccMeasurements.size() != measurements.size()) { + std::stringstream ss; + ss << "Number of measurements do not match (traccc: " + << tracccMeasurements.size() << ", acts: " << measurements.size() + << ")\n" + << "Perhaps mergeCommonCorner or doMerge is false in the digitization " + "algorithm config?"; + ACTS_WARNING(ss.str()); + } else { + std::stringstream ss; + ss << "Number of Acts and Traccc measurements match (count: " + << measurements.size() << ")"; + ACTS_INFO(ss.str()); } - -} - -/// @brief Creates a map from traccc measurements to acts measurements. -/// The traccc elements will map to an acts measurement that it is equivalent to. -/// The resulting map is assumed to be bijective, thus if any element is unable to find a match an error is thrown. -/// @param tracccMeasurements the traccc measurements. -/// @param measurements the acts measurements. -/// @return A map from traccc measurement to acts bound variant measurement. -template -std::map measurementConversionMap( - const std::vector& tracccMeasurements, - const std::vector& measurements) const{ - + } + + /// @brief Creates a map from traccc measurements to acts measurements. + /// The traccc elements will map to an acts measurement that it is equivalent + /// to. The resulting map is assumed to be bijective, thus if any element is + /// unable to find a match an error is thrown. + /// @param tracccMeasurements the traccc measurements. + /// @param measurements the acts measurements. + /// @return A map from traccc measurement to acts bound variant measurement. + template + std::map + measurementConversionMap( + const std::vector& tracccMeasurements, + const std::vector& measurements) const { logMeasurementCountComparison(tracccMeasurements, measurements); - auto convertedMeasurements = Conversion::createActsMeasurements(detector, tracccMeasurements); + auto convertedMeasurements = + Conversion::createActsMeasurements(detector, tracccMeasurements); auto indexMap = Measurement::matchMap(convertedMeasurements, measurements); - ACTS_DEBUG(std::string("Traccc (1) and Acts (2) measurement index pairing information:\n") + Measurement::pairingStatistics(convertedMeasurements, measurements, indexMap)); + ACTS_DEBUG(std::string("Traccc (1) and Acts (2) measurement index pairing " + "information:\n") + + Measurement::pairingStatistics(convertedMeasurements, + measurements, indexMap)); return Util::referenceMap(tracccMeasurements, measurements, indexMap); -} - -template class holder_t> -void mapMeasurements(Acts::TrackContainer& trackContainer, const std::map map) const { - for (auto track : trackContainer){ - for (auto trackState : track.trackStates()){ - const auto tracccMeasurement = trackState.getUncalibratedSourceLink().template get(); - const Acts::BoundVariantMeasurement& measurement = map.at(tracccMeasurement); - std::visit( - [&trackState](auto& m) { - trackState.setUncalibratedSourceLink(m.sourceLink()); - trackState.setCalibrated(m); - }, - measurement); - } + } + + template class holder_t> + void mapMeasurements( + Acts::TrackContainer& + trackContainer, + const std::map map) + const { + for (auto track : trackContainer) { + for (auto trackState : track.trackStates()) { + const auto tracccMeasurement = trackState.getUncalibratedSourceLink() + .template get(); + const Acts::BoundVariantMeasurement& measurement = + map.at(tracccMeasurement); + std::visit( + [&trackState](auto& m) { + trackState.setUncalibratedSourceLink(m.sourceLink()); + trackState.setCalibrated(m); + }, + measurement); + } } -} - -protected: -const Acts::Logger& logger() const { return actsLogger; } - -public: - -Converter( - const Acts::TrackingGeometry& tg, - const detector_t& det, - const traccc::digitization_config& dc, - const traccc::geometry& sf, - const std::map& bm, - const Acts::Logger& l -): - trackingGeometry(tg), - detector(det), - digitizationConfig(dc), - surfaceTransforms(sf), - barcodeMap(bm), - actsLogger(l) -{} - -/// @brief Converts a map of cells to traccc cells and modules. -/// @param map The geometry id -> cell collection map which corresponds to each geometry's cells. -/// @param mr The memory resource to use. -/// @returns a tuple containing traccc input data, i.e. (cells, modules). -auto convertCells(const std::map>& map, vecmem::memory_resource* mr) const { + } + + protected: + const Acts::Logger& logger() const { return actsLogger; } + + public: + Converter(const Acts::TrackingGeometry& tg, const detector_t& det, + const traccc::digitization_config& dc, const traccc::geometry& sf, + const std::map& bm, + const Acts::Logger& l) + : trackingGeometry(tg), + detector(det), + digitizationConfig(dc), + surfaceTransforms(sf), + barcodeMap(bm), + actsLogger(l) {} + + /// @brief Converts a map of cells to traccc cells and modules. + /// @param map The geometry id -> cell collection map which corresponds to each geometry's cells. + /// @param mr The memory resource to use. + /// @returns a tuple containing traccc input data, i.e. (cells, modules). + auto convertCells( + const std::map>& map, + vecmem::memory_resource* mr) const { auto tcm = Conversion::tracccCellsMap(map); auto res = Acts::TracccPlugin::createCellsAndModules( - mr, tcm, &surfaceTransforms, &digitizationConfig, &barcodeMap); + mr, tcm, &surfaceTransforms, &digitizationConfig, &barcodeMap); std::stringstream ss; - ss << "Successfully converted Acts cells (obtained " << std::get<0>(res).size() << " traccc cells and " + ss << "Successfully converted Acts cells (obtained " + << std::get<0>(res).size() << " traccc cells and " << std::get<1>(res).size() << " traccc modules)"; ACTS_INFO(ss.str()) return res; -} - -/// @brief Converts a container of traccc tracks to a container of Acts tracks. -/// The given traccc measurements are compared with the given acts measurements to determine the mapping between measurements -/// and ensure that the two collections of measurements are equivalent. -/// The newly created Acts tracks will use measurements from the acts measurement container. -/// The Acts measurements provided will be used for setting both the calibrated and uncalibrated measurements/sourcelinks. -/// @param tracccTrackContainer The traccc tracks. -/// @param tracccMeasurements the traccc measurements. -/// @param measurements the Acts measurements. -/// @return An Acts const track container. -template -auto convertTracks( - traccc_track_container_t& tracccTrackContainer, - const std::vector& tracccMeasurements, - const std::vector& measurements -) const { + } + + /// @brief Converts a container of traccc tracks to a container of Acts tracks. + /// The given traccc measurements are compared with the given acts + /// measurements to determine the mapping between measurements and ensure that + /// the two collections of measurements are equivalent. The newly created Acts + /// tracks will use measurements from the acts measurement container. The Acts + /// measurements provided will be used for setting both the calibrated and + /// uncalibrated measurements/sourcelinks. + /// @param tracccTrackContainer The traccc tracks. + /// @param tracccMeasurements the traccc measurements. + /// @param measurements the Acts measurements. + /// @return An Acts const track container. + template + auto convertTracks( + traccc_track_container_t& tracccTrackContainer, + const std::vector& tracccMeasurements, + const std::vector& measurements) const { auto trackContainer = std::make_shared(); auto trackStateContainer = std::make_shared(); TrackContainer tracks(trackContainer, trackStateContainer); - Acts::TracccPlugin::makeTracks(tracccTrackContainer, tracks, detector, trackingGeometry); + Acts::TracccPlugin::makeTracks(tracccTrackContainer, tracks, detector, + trackingGeometry); std::stringstream ss; ss << "Converted " << tracccTrackContainer.size() << " traccc tracks"; @@ -190,20 +200,21 @@ auto convertTracks( auto mcm = measurementConversionMap(tracccMeasurements, measurements); - ACTS_INFO("Found a 1:1 mapping of indexes between traccc and Acts measurements"); + ACTS_INFO( + "Found a 1:1 mapping of indexes between traccc and Acts measurements"); mapMeasurements(tracks, mcm); ACTS_INFO("Updated track state measurements"); ConstTrackContainer constTracks{ - std::make_shared(std::move(*trackContainer)), - std::make_shared(std::move(*trackStateContainer)) - }; + std::make_shared( + std::move(*trackContainer)), + std::make_shared( + std::move(*trackStateContainer))}; return constTracks; -} - + } }; -} // namespace ActsExamples \ No newline at end of file +} // namespace ActsExamples::Traccc::Common \ No newline at end of file diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Measurement/Debug.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Measurement/Debug.hpp index 51753b5b7250..fa5036302637 100644 --- a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Measurement/Debug.hpp +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Measurement/Debug.hpp @@ -15,10 +15,11 @@ #include #include #include -#include #include +#include -// This file is for debugging and for getting the matching between two collections of measurements as a string. +// This file is for debugging and for getting the matching between two +// collections of measurements as a string. namespace ActsExamples::Traccc::Common::Measurement { @@ -26,8 +27,12 @@ namespace ActsExamples::Traccc::Common::Measurement { /// @param measurements1 the measurements (1). /// @param measurements2 the measurements (2). /// @param indexMap the index map: measurements1 indices -> measurement2 indices. -/// The index map describes which elements are related in the two measurement collections. +/// The index map describes which elements are related in the two measurement +/// collections. /// @return a string formatted as a table. -std::string pairingStatistics(const std::vector& measurements1, const std::vector& measurements2, const std::map& indexMap); +std::string pairingStatistics( + const std::vector& measurements1, + const std::vector& measurements2, + const std::map& indexMap); -} +} // namespace ActsExamples::Traccc::Common::Measurement diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Measurement/MeasurementMatch.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Measurement/MeasurementMatch.hpp index 0cd8e4baa103..1027a75ab2de 100644 --- a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Measurement/MeasurementMatch.hpp +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Measurement/MeasurementMatch.hpp @@ -8,67 +8,90 @@ #pragma once - // Acts include(s) #include "Acts/Geometry/GeometryIdentifier.hpp" // Acts examples include(s) -#include "ActsExamples/EventData/Measurement.hpp" #include "ActsExamples/EventData/IndexSourceLink.hpp" +#include "ActsExamples/EventData/Measurement.hpp" #include "ActsExamples/Traccc/Common/Util/IndexMap.hpp" // System include(s). #include #include -#include -#include #include +#include +#include -// This file is for matching similar measurements in two collections of measurements. +// This file is for matching similar measurements in two collections of +// measurements. -namespace ActsExamples::Traccc::Common::Measurement{ +namespace ActsExamples::Traccc::Common::Measurement { /// @brief Get the geometry ID from the measurement through its source link. /// @note Sourcelink is assumed to be of type IndexSourceLink. -inline Acts::GeometryIdentifier getGeometryID(const Acts::BoundVariantMeasurement& measurement){ - return std::visit([](auto& m){ - return m.sourceLink().template get().geometryId(); - }, measurement); +inline Acts::GeometryIdentifier getGeometryID( + const Acts::BoundVariantMeasurement& measurement) { + return std::visit( + [](auto& m) { + return m.sourceLink() + .template get() + .geometryId(); + }, + measurement); } /// @brief Checks if two measurements are equal based on their geometry ID and position alone. /// @param measurement1 the first measurement. /// @param measurement2 the second measurement. /// @param maxDistance the tolerance of the difference in local position. -/// The maximum distance between the local positions of the measurements must be less or equal to this value to be considered equal. +/// The maximum distance between the local positions of the measurements must be +/// less or equal to this value to be considered equal. /// @returns true or false depending on whether they are considered equal. -inline bool measurementEqual(const Acts::BoundVariantMeasurement& measurement1, const Acts::BoundVariantMeasurement& measurement2, const double maxDistance = .001){ - auto gidEq = getGeometryID(measurement1) == getGeometryID(measurement2); - - auto sqNorm = (Conversion::getLocal(measurement1) - Conversion::getLocal(measurement2)).squaredNorm(); - auto locEq = sqNorm <= maxDistance * maxDistance; +inline bool measurementEqual(const Acts::BoundVariantMeasurement& measurement1, + const Acts::BoundVariantMeasurement& measurement2, + const double maxDistance = .001) { + auto gidEq = getGeometryID(measurement1) == getGeometryID(measurement2); + + auto sqNorm = + (Conversion::getLocal(measurement1) - Conversion::getLocal(measurement2)) + .squaredNorm(); + auto locEq = sqNorm <= maxDistance * maxDistance; - return gidEq && locEq; + return gidEq && locEq; } /// @brief Generates a hash for the measurement. -/// This hash is used for the locality sensitive hashing to calculate the match map. -/// Thus, this hash is not sensitive to small variations in position that could could from numerical errors. -inline std::size_t measurementHash(const Acts::BoundVariantMeasurement& measurement){ - // The hash function can be optimized to reduce collisions. - return static_cast(getGeometryID(measurement).value()); +/// This hash is used for the locality sensitive hashing to calculate the match +/// map. Thus, this hash is not sensitive to small variations in position that +/// could could from numerical errors. +inline std::size_t measurementHash( + const Acts::BoundVariantMeasurement& measurement) { + // The hash function can be optimized to reduce collisions. + return static_cast(getGeometryID(measurement).value()); } -namespace{ -const auto wrappedHash = std::function(measurementHash); -const auto wrappedEq = std::function( - [](const Acts::BoundVariantMeasurement& m1, const Acts::BoundVariantMeasurement& m2) { return measurementEqual(m1, m2); }); -} +namespace { +const auto wrappedHash = + std::function( + measurementHash); +const auto wrappedEq = + std::function( + [](const Acts::BoundVariantMeasurement& m1, + const Acts::BoundVariantMeasurement& m2) { + return measurementEqual(m1, m2); + }); +} // namespace /// @brief Creates a match map by matching the elements in two collection based on their geometry id and approximate position. -/// The two collections of measurements are assumed to contain the same measurements. However, equivalent measurements may be at different indices in the collections. This function determines which indexes correspond to matching measurements. -inline auto matchMap(const std::vector& from, const std::vector& to){ - return Util::matchMap(from, to, wrappedHash, wrappedEq); +/// The two collections of measurements are assumed to contain the same +/// measurements. However, equivalent measurements may be at different indices +/// in the collections. This function determines which indexes correspond to +/// matching measurements. +inline auto matchMap(const std::vector& from, + const std::vector& to) { + return Util::matchMap(from, to, wrappedHash, wrappedEq); } -} +} // namespace ActsExamples::Traccc::Common::Measurement diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/TracccChainAlgorithmBase.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/TracccChainAlgorithmBase.hpp index d73869d6e64a..ea8e16e2d3f7 100644 --- a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/TracccChainAlgorithmBase.hpp +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/TracccChainAlgorithmBase.hpp @@ -9,18 +9,18 @@ #pragma once // Acts include(s) +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/Geometry/TrackingGeometry.hpp" +#include "Acts/MagneticField/ConstantBField.hpp" +#include "Acts/MagneticField/MagneticFieldProvider.hpp" #include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/Digitization/DigitizationConfig.hpp" #include "ActsExamples/EventData/Cluster.hpp" #include "ActsExamples/EventData/IndexSourceLink.hpp" #include "ActsExamples/EventData/Measurement.hpp" #include "ActsExamples/Framework/DataHandle.hpp" #include "ActsExamples/Framework/IAlgorithm.hpp" #include "ActsExamples/Framework/ProcessCode.hpp" -#include "ActsExamples/Digitization/DigitizationConfig.hpp" -#include "Acts/Geometry/TrackingGeometry.hpp" -#include "Acts/MagneticField/MagneticFieldProvider.hpp" -#include "Acts/MagneticField/ConstantBField.hpp" -#include "Acts/Definitions/Algebra.hpp" // Acts Examples include(s) #include "ActsExamples/Traccc/Common/Converter.hpp" @@ -41,15 +41,15 @@ namespace ActsExamples::Traccc::Common { - class TracccChainAlgorithmBase : public IAlgorithm { -public: - -using DetectorHostType = detray::detector; -using FieldType = Acts::CovfiePlugin::ConstantField; -using CellsMapType = std::map>; - -struct Config { + public: + using DetectorHostType = + detray::detector; + using FieldType = Acts::CovfiePlugin::ConstantField; + using CellsMapType = + std::map>; + + struct Config { std::string inputCells; std::string inputMeasurements; std::string outputTracks; @@ -57,52 +57,51 @@ struct Config { std::shared_ptr field; Acts::GeometryHierarchyMap digitizationConfigs; std::shared_ptr chainConfig; -}; - -/// Construct the traccc algorithm. -/// -/// @param cfg is the algorithm configuration -/// @param lvl is the logging level -TracccChainAlgorithmBase(Config cfg, Acts::Logging::Level lvl); - -/// Const access to the config -const Config& config() const { return m_cfg; } - -protected: - -Config m_cfg; - -ReadDataHandle m_inputCells{this, "InputCells"}; -ReadDataHandle m_inputMeasurements{this, "InputMeasurements"}; -WriteDataHandle m_outputTracks{this, "OutputTracks"}; - -// Memory resource, detector, and converter should be declared in that order to ensure order of destructor call. -vecmem::host_memory_resource hostMemoryResource; -const DetectorHostType detector; -const FieldType field; -const Converter converter; - -private: - -/// @brief Test if the configuration is valid. -void TestValidConfig(){ - if (m_cfg.inputCells.empty()) { - throw std::invalid_argument("Missing input cells"); + }; + + /// Construct the traccc algorithm. + /// + /// @param cfg is the algorithm configuration + /// @param lvl is the logging level + TracccChainAlgorithmBase(Config cfg, Acts::Logging::Level lvl); + + /// Const access to the config + const Config& config() const { return m_cfg; } + + protected: + Config m_cfg; + + ReadDataHandle m_inputCells{this, "InputCells"}; + ReadDataHandle m_inputMeasurements{this, + "InputMeasurements"}; + WriteDataHandle m_outputTracks{this, "OutputTracks"}; + + // Memory resource, detector, and converter should be declared in that order + // to ensure order of destructor call. + vecmem::host_memory_resource hostMemoryResource; + const DetectorHostType detector; + const FieldType field; + const Converter converter; + + private: + /// @brief Test if the configuration is valid. + void TestValidConfig() { + if (m_cfg.inputCells.empty()) { + throw std::invalid_argument("Missing input cells"); + } + + if (m_cfg.field == nullptr) { + throw std::invalid_argument("Missing field"); + } + + if (m_cfg.trackingGeometry == nullptr) { + throw std::invalid_argument("Missing track geometry"); + } + + if (m_cfg.digitizationConfigs.empty()) { + throw std::invalid_argument("Missing digitization configuration"); + } } - - if (m_cfg.field == nullptr) { - throw std::invalid_argument("Missing field"); - } - - if (m_cfg.trackingGeometry == nullptr) { - throw std::invalid_argument("Missing track geometry"); - } - - if (m_cfg.digitizationConfigs.empty()) { - throw std::invalid_argument("Missing digitization configuration"); - } -} - }; -} // namespace ActsExamples \ No newline at end of file +} // namespace ActsExamples::Traccc::Common \ No newline at end of file diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/TracccChainConfig.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/TracccChainConfig.hpp index d05e9aa42049..10b1584ac0c3 100644 --- a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/TracccChainConfig.hpp +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/TracccChainConfig.hpp @@ -12,33 +12,33 @@ #include "traccc/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.hpp" #include "traccc/clusterization/clusterization_algorithm.hpp" #include "traccc/clusterization/spacepoint_formation_algorithm.hpp" +#include "traccc/definitions/primitives.hpp" #include "traccc/finding/finding_algorithm.hpp" +#include "traccc/finding/finding_config.hpp" #include "traccc/fitting/fitting_algorithm.hpp" +#include "traccc/fitting/fitting_config.hpp" #include "traccc/seeding/seeding_algorithm.hpp" #include "traccc/seeding/track_params_estimation.hpp" -#include "traccc/finding/finding_config.hpp" -#include "traccc/fitting/fitting_config.hpp" -#include "traccc/definitions/primitives.hpp" namespace ActsExamples::Traccc::Common { -struct TracccChainConfig{ - - using ScalarType = traccc::scalar; - - using SeedfinderConfigType = typename traccc::seedfinder_config; - using SpacepointGridConfigType = typename traccc::spacepoint_grid_config; - using SeedfilterConfigType = typename traccc::seedfilter_config; - using FindingConfigType = typename traccc::finding_config; - using FittingConfigType = typename traccc::fitting_config; - using AmbiguityResolutionConfigType = typename traccc::greedy_ambiguity_resolution_algorithm::config_t; - - SeedfinderConfigType seedfinderConfig; - SpacepointGridConfigType spacepointGridConfig{seedfinderConfig}; - SeedfilterConfigType seedfilterConfig; - FindingConfigType findingConfig; - FittingConfigType fittingConfig; - AmbiguityResolutionConfigType ambiguityResolutionConfig; +struct TracccChainConfig { + using ScalarType = traccc::scalar; + + using SeedfinderConfigType = typename traccc::seedfinder_config; + using SpacepointGridConfigType = typename traccc::spacepoint_grid_config; + using SeedfilterConfigType = typename traccc::seedfilter_config; + using FindingConfigType = typename traccc::finding_config; + using FittingConfigType = typename traccc::fitting_config; + using AmbiguityResolutionConfigType = + typename traccc::greedy_ambiguity_resolution_algorithm::config_t; + + SeedfinderConfigType seedfinderConfig; + SpacepointGridConfigType spacepointGridConfig{seedfinderConfig}; + SeedfilterConfigType seedfilterConfig; + FindingConfigType findingConfig; + FittingConfigType fittingConfig; + AmbiguityResolutionConfigType ambiguityResolutionConfig; }; -} +} // namespace ActsExamples::Traccc::Common diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Util/IndexMap.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Util/IndexMap.hpp index a3ba4f17482e..8408954312ce 100644 --- a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Util/IndexMap.hpp +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Common/Util/IndexMap.hpp @@ -11,42 +11,46 @@ // System include(s). #include #include -#include -#include #include -#include +#include #include +#include +#include namespace ActsExamples::Traccc::Common::Util { - -/// @brief -/// @tparam T -/// @tparam A +/// @brief +/// @tparam T +/// @tparam A /// @param out the index into the candidate indices vector. /// Taking this index into the candidate indices vector will get the index in . -/// @param element -/// @param candidateIdxs -/// @param candidateVec -/// @param eqFn -/// @return +/// @param element +/// @param candidateIdxs +/// @param candidateVec +/// @param eqFn +/// @return template -auto findMatchIdx(std::size_t* out, const T& element, const std::vector& candidateIdxs, const std::vector& candidateVec, const std::function& eqFn){ - for (std::size_t i = 0; i < candidateIdxs.size(); i++){ - auto idx = candidateIdxs[i]; - if (eqFn(element, candidateVec[idx])){ - *out = i; - return true; - } +auto findMatchIdx(std::size_t* out, const T& element, + const std::vector& candidateIdxs, + const std::vector& candidateVec, + const std::function& eqFn) { + for (std::size_t i = 0; i < candidateIdxs.size(); i++) { + auto idx = candidateIdxs[i]; + if (eqFn(element, candidateVec[idx])) { + *out = i; + return true; } - return false; + } + return false; } /// @brief Determines which pairs of indices in the two vectors contain items that are equal. -/// Each item in the vector 'from̈́' must be equal to at least 1 item in the vector 'to'. -/// Furthermore, if the flag 'bijection' is enabled each element in ̈́'to' and 'from' can only be paired with exactly 1 element. -/// @note When 'bijection' is corresponds to the assumption that the two vectors contain exactly the same elements. -/// The ordering in the vectors may however be different (determining the difference in the order is where this function can be helpful). +/// Each item in the vector 'from̈́' must be equal to at least 1 item in the +/// vector 'to'. Furthermore, if the flag 'bijection' is enabled each element in +/// ̈́'to' and 'from' can only be paired with exactly 1 element. +/// @note When 'bijection' is corresponds to the assumption that the two vectors contain exactly the same elements. +/// The ordering in the vectors may however be different (determining the +/// difference in the order is where this function can be helpful). /// @param from a vector (the retutned map's domain). /// @param to a vector (the returned map's codomain). /// @param lshFn the hashing function used for locality sensitive hashing. Any items that could potential be equal should have the same hash value. @@ -54,43 +58,51 @@ auto findMatchIdx(std::size_t* out, const T& element, const std::vector index ('to' vector). template -inline auto matchMap(const std::vector& from, const std::vector& to, const std::function& lshFn, const std::function& eqFn, const bool bijection = true){ - // By composition of functions, we can combine the maps "index ('from' vector) -> hash value" and "hash value -> index ('to' vector)" - // to obtain "index ('from' vector) -> index ('to' vector)". +inline auto matchMap(const std::vector& from, + const std::vector& to, + const std::function& lshFn, + const std::function& eqFn, + const bool bijection = true) { + // By composition of functions, we can combine the maps "index ('from' vector) + // -> hash value" and "hash value -> index ('to' vector)" to obtain "index + // ('from' vector) -> index ('to' vector)". - if (bijection && from.size() != to.size()){ - throw std::runtime_error("Cannot create a bijection as domain and codomain do not have the same cardinality"); - } - - // We start by creating the map "hash value -> index ('to' vector)". + if (bijection && from.size() != to.size()) { + throw std::runtime_error( + "Cannot create a bijection as domain and codomain do not have the same " + "cardinality"); + } - // Since there can be collisions with the hash values - // each hash value maps to a bucket of indices rather than a single index. + // We start by creating the map "hash value -> index ('to' vector)". - std::unordered_map> map1; - for (std::size_t toIdx = 0; toIdx < to.size(); toIdx++){ - auto& toElement = to[toIdx]; - auto toElementHash = lshFn(toElement); - map1[toElementHash].push_back(toIdx); - } + // Since there can be collisions with the hash values + // each hash value maps to a bucket of indices rather than a single index. - // We can build the map "index in 'from' -> index in 'to'" directly. - std::map res; - for (std::size_t fromIdx = 0; fromIdx < from.size(); fromIdx++){ - auto& fromElement = from[fromIdx]; - auto fromElementHash = lshFn(fromElement); - // We now find the exact element to match fromElement with in the bucket. - auto& candidateIdxs = map1[fromElementHash]; - std::size_t idx; - if (candidateIdxs.empty() || !findMatchIdx(&idx, fromElement, candidateIdxs, to, eqFn)){ - throw std::runtime_error("Could not find a match for an element"); - } - res[fromIdx] = candidateIdxs[idx]; - if (bijection){ - candidateIdxs.erase(candidateIdxs.begin()+idx); - } + std::unordered_map> map1; + for (std::size_t toIdx = 0; toIdx < to.size(); toIdx++) { + auto& toElement = to[toIdx]; + auto toElementHash = lshFn(toElement); + map1[toElementHash].push_back(toIdx); + } + + // We can build the map "index in 'from' -> index in 'to'" directly. + std::map res; + for (std::size_t fromIdx = 0; fromIdx < from.size(); fromIdx++) { + auto& fromElement = from[fromIdx]; + auto fromElementHash = lshFn(fromElement); + // We now find the exact element to match fromElement with in the bucket. + auto& candidateIdxs = map1[fromElementHash]; + std::size_t idx; + if (candidateIdxs.empty() || + !findMatchIdx(&idx, fromElement, candidateIdxs, to, eqFn)) { + throw std::runtime_error("Could not find a match for an element"); + } + res[fromIdx] = candidateIdxs[idx]; + if (bijection) { + candidateIdxs.erase(candidateIdxs.begin() + idx); } - return res; + } + return res; } /// @brief Creates a map from elements in one vector to another. @@ -100,15 +112,16 @@ inline auto matchMap(const std::vector& from, const std::vector& /// @param indexMap a map of indices in the first collection to indices in the second collection. /// @returns the map: element in first collection -> element in second collection. template -std::map referenceMap(const std::vector& from, const std::vector& to, const std::map& indexMap){ - assert(from.size() == to.size()); - std::map res; - for (const auto [i, j] : indexMap){ - res.emplace(std::piecewise_construct, - std::forward_as_tuple(from[i]), - std::forward_as_tuple(to[j])); - } - return res; +std::map referenceMap( + const std::vector& from, const std::vector& to, + const std::map& indexMap) { + assert(from.size() == to.size()); + std::map res; + for (const auto [i, j] : indexMap) { + res.emplace(std::piecewise_construct, std::forward_as_tuple(from[i]), + std::forward_as_tuple(to[j])); + } + return res; } -} \ No newline at end of file +} // namespace ActsExamples::Traccc::Common::Util \ No newline at end of file diff --git a/Examples/Algorithms/Traccc/Common/src/Conversion/CellMapConversion.cpp b/Examples/Algorithms/Traccc/Common/src/Conversion/CellMapConversion.cpp index 2af0c7c31660..8cdaf21ed816 100644 --- a/Examples/Algorithms/Traccc/Common/src/Conversion/CellMapConversion.cpp +++ b/Examples/Algorithms/Traccc/Common/src/Conversion/CellMapConversion.cpp @@ -10,8 +10,8 @@ #include "Acts/Geometry/GeometryIdentifier.hpp" // Acts Examples include(s) -#include "ActsExamples/Traccc/Common/Conversion/CellMapConversion.hpp" #include "ActsExamples/EventData/Cluster.hpp" +#include "ActsExamples/Traccc/Common/Conversion/CellMapConversion.hpp" // Traccc include(s) #include "traccc/edm/cell.hpp" @@ -19,36 +19,38 @@ // System include(s). #include #include -#include #include +#include namespace ActsExamples::Traccc::Common::Conversion { /// @brief Gets the time of the cell. /// @note Currently, it always returns 0. -inline float getTime(const Cluster::Cell& /*cell*/){ - return 0.f; +inline float getTime(const Cluster::Cell& /*cell*/) { + return 0.f; } /// @brief Gets the activation of the cell. -inline float getActivation(const Cluster::Cell& cell){ - return static_cast(cell.activation); +inline float getActivation(const Cluster::Cell& cell) { + return static_cast(cell.activation); } /// @brief Gets the row of the cell. -inline unsigned int getRow(const Cluster::Cell& cell){ - if (cell.bin[0] > UINT_MAX) { - throw std::runtime_error("Overflow will occur when casting to unsigned int."); - } - return static_cast(cell.bin[0]); +inline unsigned int getRow(const Cluster::Cell& cell) { + if (cell.bin[0] > UINT_MAX) { + throw std::runtime_error( + "Overflow will occur when casting to unsigned int."); + } + return static_cast(cell.bin[0]); } /// @brief Gets the column of the cell. -inline unsigned int getColumn(const Cluster::Cell& cell){ - if (cell.bin[0] > UINT_MAX) { - throw std::runtime_error("Overflow will occur when casting to unsigned int."); - } - return static_cast(cell.bin[1]); +inline unsigned int getColumn(const Cluster::Cell& cell) { + if (cell.bin[0] > UINT_MAX) { + throw std::runtime_error( + "Overflow will occur when casting to unsigned int."); + } + return static_cast(cell.bin[1]); } /// @brief Creates a traccc cell from a generic cell type. @@ -56,31 +58,26 @@ inline unsigned int getColumn(const Cluster::Cell& cell){ /// @param moduleLink the module link value to set for the traccc cell that is created. /// @returns a traccc cell. /// @note the functions getRow(cell_t), getColumn(cell_t), getActivation(cell_t), getTime(cell_t) are expected. -inline traccc::cell tracccCell(const Cluster::Cell& cell, const traccc::cell::link_type moduleLink = 0){ - return traccc::cell{ - getRow(cell), - getColumn(cell), - getActivation(cell), - getTime(cell), - moduleLink - }; +inline traccc::cell tracccCell(const Cluster::Cell& cell, + const traccc::cell::link_type moduleLink = 0) { + return traccc::cell{getRow(cell), getColumn(cell), getActivation(cell), + getTime(cell), moduleLink}; } /// @brief Converts a "geometry ID -> generic cell collection type" map to a "geometry ID -> traccc cell collection" map. /// @note The function sets the module link of the cells in the output to 0. /// @return Map from geometry ID to its cell data (as a vector of traccc cell data) std::map> tracccCellsMap( - const std::map>& map) - { - std::map> tracccCellMap; - for (const auto& [geometryID, cells] : map){ - std::vector tracccCells; - for (const auto& cell : cells){ - tracccCells.push_back(tracccCell(cell)); - } - tracccCellMap.insert({geometryID.value(), std::move(tracccCells)}); + const std::map>& map) { + std::map> tracccCellMap; + for (const auto& [geometryID, cells] : map) { + std::vector tracccCells; + for (const auto& cell : cells) { + tracccCells.push_back(tracccCell(cell)); } - return tracccCellMap; + tracccCellMap.insert({geometryID.value(), std::move(tracccCells)}); + } + return tracccCellMap; } -} +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/src/Conversion/DigitizationConversion.cpp b/Examples/Algorithms/Traccc/Common/src/Conversion/DigitizationConversion.cpp index 33b5f1a11ba0..dcd7e616dfed 100644 --- a/Examples/Algorithms/Traccc/Common/src/Conversion/DigitizationConversion.cpp +++ b/Examples/Algorithms/Traccc/Common/src/Conversion/DigitizationConversion.cpp @@ -12,21 +12,21 @@ #include "Acts/Utilities/BinUtility.hpp" // Acts Examples include(s) -#include "ActsExamples/Traccc/Common/Conversion/DigitizationConversion.hpp" #include "ActsExamples/Digitization/DigitizationConfig.hpp" +#include "ActsExamples/Traccc/Common/Conversion/DigitizationConversion.hpp" // Traccc include(s) #include "traccc/io/digitization_config.hpp" // System include(s). -#include #include - +#include + namespace ActsExamples::Traccc::Common::Conversion { /// @brief Get the segmentation from a DigiComponentsConfig. -inline Acts::BinUtility getSegmentation(const DigiComponentsConfig& dcc){ - return dcc.geometricDigiConfig.segmentation; +inline Acts::BinUtility getSegmentation(const DigiComponentsConfig& dcc) { + return dcc.geometricDigiConfig.segmentation; } /// @brief Creates a traccc digitalization config from an Acts geometry hierarchy map @@ -34,13 +34,15 @@ inline Acts::BinUtility getSegmentation(const DigiComponentsConfig& dcc){ /// @param config the Acts geometry hierarchy map that contains the digitization configuration. /// @return a traccc digitization config. traccc::digitization_config tracccConfig( - const Acts::GeometryHierarchyMap& config){ - using ElementType = std::pair; - std::vector vec; - for (auto& e : config.getElements()){ - vec.push_back({e.first, traccc::module_digitization_config{getSegmentation(e.second)}}); - } - return traccc::digitization_config(vec); + const Acts::GeometryHierarchyMap& config) { + using ElementType = + std::pair; + std::vector vec; + for (auto& e : config.getElements()) { + vec.push_back({e.first, traccc::module_digitization_config{ + getSegmentation(e.second)}}); + } + return traccc::digitization_config(vec); } -} +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/src/Conversion/MeasurementConversion.cpp b/Examples/Algorithms/Traccc/Common/src/Conversion/MeasurementConversion.cpp index e8b11c627723..d759770a324f 100644 --- a/Examples/Algorithms/Traccc/Common/src/Conversion/MeasurementConversion.cpp +++ b/Examples/Algorithms/Traccc/Common/src/Conversion/MeasurementConversion.cpp @@ -20,8 +20,7 @@ namespace ActsExamples::Traccc::Common::Conversion { /// @brief Converts a traccc bound index to an Acts bound index. /// @param tracccBoundIndex the traccc bound index. /// @returns an Acts bound index. -Acts::BoundIndices boundIndex( - const traccc::bound_indices tracccBoundIndex) { +Acts::BoundIndices boundIndex(const traccc::bound_indices tracccBoundIndex) { switch (tracccBoundIndex) { case traccc::bound_indices::e_bound_loc0: return Acts::BoundIndices::eBoundLoc0; @@ -42,4 +41,4 @@ Acts::BoundIndices boundIndex( } } -} +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/src/Debug/Debug.cpp b/Examples/Algorithms/Traccc/Common/src/Debug/Debug.cpp index 80434c0e7a26..4da7868fb558 100644 --- a/Examples/Algorithms/Traccc/Common/src/Debug/Debug.cpp +++ b/Examples/Algorithms/Traccc/Common/src/Debug/Debug.cpp @@ -16,101 +16,102 @@ // System include(s). #include #include -#include #include +#include #include -// This file is for debugging and for getting the matching between two collections of measurements as a string. +// This file is for debugging and for getting the matching between two +// collections of measurements as a string. namespace ActsExamples::Traccc::Common::Measurement { -namespace{ +namespace { /// @returns a nicely formated string of a vector representing a point. -std::string toString(const Acts::ActsVector<2>& vec){ - std::stringstream ss; - ss << "(" << vec[0] << ", " << vec[1] << ")"; - return ss.str(); +std::string toString(const Acts::ActsVector<2>& vec) { + std::stringstream ss; + ss << "(" << vec[0] << ", " << vec[1] << ")"; + return ss.str(); } /// @brief Structure to hold table data struct MeasurementMatchRow { - std::size_t idx1; - Acts::ActsVector<2> local1; - Acts::ActsVector<2> variance1; + std::size_t idx1; + Acts::ActsVector<2> local1; + Acts::ActsVector<2> variance1; - std::size_t idx2; - Acts::ActsVector<2> local2; - Acts::ActsVector<2> variance2; + std::size_t idx2; + Acts::ActsVector<2> local2; + Acts::ActsVector<2> variance2; - Acts::ActsScalar distanceLocal; + Acts::ActsScalar distanceLocal; }; /// @brief Creates a table with data and measurements aligned according to the index map. /// @param measurements1 the measurements (1). /// @param measurements2 the measurements (2). /// @param indexMap the index map: measurements1 indices -> measurement2 indices. -/// The index map describes which elements are related in the two measurement collections. +/// The index map describes which elements are related in the two measurement +/// collections. /// @return a vector of MeasurementMatchRow. -auto createTable(const std::vector& measurements1, const std::vector& measurements2, const std::map& indexMap){ - std::vector table; - for (std::size_t idx1 = 0; idx1 < measurements1.size(); ++idx1){ - MeasurementMatchRow row; - auto measurement1 = measurements1[idx1]; - row.idx1 = idx1; - row.local1 = Conversion::getLocal(measurement1); - row.variance1 = Conversion::getVariance(measurement1); - - auto idx2 = indexMap.at(idx1); - auto measurement2 = measurements2[idx2]; - row.idx2 = idx2; - row.local2 = Conversion::getLocal(measurement2); - row.variance2 = Conversion::getVariance(measurement2); - - row.distanceLocal = (row.local1 - row.local2).norm(); - table.push_back(row); - } - return table; +auto createTable( + const std::vector& measurements1, + const std::vector& measurements2, + const std::map& indexMap) { + std::vector table; + for (std::size_t idx1 = 0; idx1 < measurements1.size(); ++idx1) { + MeasurementMatchRow row; + auto measurement1 = measurements1[idx1]; + row.idx1 = idx1; + row.local1 = Conversion::getLocal(measurement1); + row.variance1 = Conversion::getVariance(measurement1); + + auto idx2 = indexMap.at(idx1); + auto measurement2 = measurements2[idx2]; + row.idx2 = idx2; + row.local2 = Conversion::getLocal(measurement2); + row.variance2 = Conversion::getVariance(measurement2); + + row.distanceLocal = (row.local1 - row.local2).norm(); + table.push_back(row); + } + return table; } -} +} // namespace /// @brief Creates a string with the data of the measurements and their relation according to the index map. /// @param measurements1 the measurements (1). /// @param measurements2 the measurements (2). /// @param indexMap the index map: measurements1 indices -> measurement2 indices. -/// The index map describes which elements are related in the two measurement collections. +/// The index map describes which elements are related in the two measurement +/// collections. /// @return a string formatted as a table. -std::string pairingStatistics(const std::vector& measurements1, const std::vector& measurements2, const std::map& indexMap) { - - auto table = createTable(measurements1, measurements2, indexMap); - - std::stringstream ss; - - // Column headers - ss << std::setw(6) << "Idx1" - << std::setw(25) << "Local1" - << std::setw(35) << "Variance1" - << std::setw(20) << "Idx2" - << std::setw(25) << "Local2" - << std::setw(35) << "Variance2" - << std::setw(25) << "Distance Local" - << std::endl; - - // Line separator - ss << std::string(173, '-') << std::endl; - - // Print each row - for (const auto& row : table) { - ss << std::setw(6) << row.idx1 - << std::setw(25) << toString(row.local1) - << std::setw(35) << toString(row.variance1) - << std::setw(20) << row.idx2 - << std::setw(25) << toString(row.local2) - << std::setw(35) << toString(row.variance2) - << std::setw(25) << std::fixed << std::setprecision(2) << row.distanceLocal - << std::endl; - } - return ss.str(); +std::string pairingStatistics( + const std::vector& measurements1, + const std::vector& measurements2, + const std::map& indexMap) { + auto table = createTable(measurements1, measurements2, indexMap); + + std::stringstream ss; + + // Column headers + ss << std::setw(6) << "Idx1" << std::setw(25) << "Local1" << std::setw(35) + << "Variance1" << std::setw(20) << "Idx2" << std::setw(25) << "Local2" + << std::setw(35) << "Variance2" << std::setw(25) << "Distance Local" + << std::endl; + + // Line separator + ss << std::string(173, '-') << std::endl; + + // Print each row + for (const auto& row : table) { + ss << std::setw(6) << row.idx1 << std::setw(25) << toString(row.local1) + << std::setw(35) << toString(row.variance1) << std::setw(20) << row.idx2 + << std::setw(25) << toString(row.local2) << std::setw(35) + << toString(row.variance2) << std::setw(25) << std::fixed + << std::setprecision(2) << row.distanceLocal << std::endl; + } + return ss.str(); } -} \ No newline at end of file +} // namespace ActsExamples::Traccc::Common::Measurement \ No newline at end of file diff --git a/Examples/Algorithms/Traccc/Common/src/TracccChainAlgorithmBase.cpp b/Examples/Algorithms/Traccc/Common/src/TracccChainAlgorithmBase.cpp index 5d70926ce730..b9bf48132539 100644 --- a/Examples/Algorithms/Traccc/Common/src/TracccChainAlgorithmBase.cpp +++ b/Examples/Algorithms/Traccc/Common/src/TracccChainAlgorithmBase.cpp @@ -24,49 +24,52 @@ #include #include -namespace{ +namespace { -// Temporarily used to get the corresponding detray detector for the Acts geometry. -// Will be replaced when the detray plugin containing geometry conversion is complete. +// Temporarily used to get the corresponding detray detector for the Acts +// geometry. Will be replaced when the detray plugin containing geometry +// conversion is complete. template -inline auto readDetector(vecmem::memory_resource* mr, const std::string& detectorFilePath, const std::string& materialFilePath = "", const std::string& gridFilePath = "") -{ - // Set up the detector reader configuration. - detray::io::detector_reader_config cfg; - cfg.add_file(detectorFilePath); - if (!materialFilePath.empty()) { - cfg.add_file(materialFilePath); - } - if (!gridFilePath.empty()) { - cfg.add_file(gridFilePath); - } +inline auto readDetector(vecmem::memory_resource* mr, + const std::string& detectorFilePath, + const std::string& materialFilePath = "", + const std::string& gridFilePath = "") { + // Set up the detector reader configuration. + detray::io::detector_reader_config cfg; + cfg.add_file(detectorFilePath); + if (!materialFilePath.empty()) { + cfg.add_file(materialFilePath); + } + if (!gridFilePath.empty()) { + cfg.add_file(gridFilePath); + } - // Read the detector. - auto [det, names] = detray::io::read_detector(*mr, cfg); - return std::move(det); + // Read the detector. + auto [det, names] = detray::io::read_detector(*mr, cfg); + return std::move(det); } -} +} // namespace /// Construct the traccc algorithm. /// /// @param cfg is the algorithm configuration /// @param lvl is the logging level -ActsExamples::Traccc::Common::TracccChainAlgorithmBase::TracccChainAlgorithmBase( - Config cfg, Acts::Logging::Level lvl) +ActsExamples::Traccc::Common::TracccChainAlgorithmBase:: + TracccChainAlgorithmBase(Config cfg, Acts::Logging::Level lvl) : ActsExamples::IAlgorithm("TracccChainAlgorithm", lvl), m_cfg(std::move(cfg)), - detector((TestValidConfig(), readDetector(&hostMemoryResource, "/home/frederik/Desktop/CERN-TECH/input/odd-detray_geometry_detray.json"))), + detector((TestValidConfig(), readDetector( + &hostMemoryResource, + "/home/frederik/Desktop/CERN-TECH/input/" + "odd-detray_geometry_detray.json"))), field(Acts::CovfiePlugin::covfieField(*m_cfg.field)), - converter{ - *m_cfg.trackingGeometry, - detector, - Conversion::tracccConfig(m_cfg.digitizationConfigs), - traccc::io::alt_read_geometry(detector), - Acts::TracccPlugin::createBarcodeMap(detector), - logger() - } -{ + converter{*m_cfg.trackingGeometry, + detector, + Conversion::tracccConfig(m_cfg.digitizationConfigs), + traccc::io::alt_read_geometry(detector), + Acts::TracccPlugin::createBarcodeMap(detector), + logger()} { m_inputCells.initialize(m_cfg.inputCells); m_inputMeasurements.initialize(m_cfg.inputMeasurements); m_outputTracks.initialize(m_cfg.outputTracks); diff --git a/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/TracccChainAlgorithm.hpp b/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/TracccChainAlgorithm.hpp index 9e61b6c60ba4..84469bb59c74 100644 --- a/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/TracccChainAlgorithm.hpp +++ b/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/TracccChainAlgorithm.hpp @@ -17,32 +17,34 @@ namespace ActsExamples::Traccc::Host { - class TracccChainAlgorithm final : public Common::TracccChainAlgorithmBase { -public: - -/// Construct the traccc algorithm. -/// -/// @param cfg is the algorithm configuration -/// @param lvl is the logging level -TracccChainAlgorithm(Config cfg, Acts::Logging::Level lvl); - -/// Run the algorithm. -/// -/// @param ctx is the algorithm context with event information -/// @return a process code indication success or failure -ProcessCode execute(const AlgorithmContext& ctx) const override; - -private: - using HostTypes = typename ActsExamples::Chain::Host::Types; - - typename HostTypes::ClusterizationAlgorithmType clusterizationAlgorithm; - typename HostTypes::SpacepointFormationAlgorithmType spacepointFormationAlgorithm; - typename HostTypes::SeedingAlgorithmType seedingAlgorithm; - typename HostTypes::TrackParametersEstimationAlgorithmType trackParametersEstimationAlgorithm; - typename HostTypes::FindingAlgorithmType findingAlgorithm; - typename HostTypes::FittingAlgorithmType fittingAlgorithm; - typename HostTypes::AmbiguityResolutionAlgorithmType ambiguityResolutionAlgorithm; + public: + /// Construct the traccc algorithm. + /// + /// @param cfg is the algorithm configuration + /// @param lvl is the logging level + TracccChainAlgorithm(Config cfg, Acts::Logging::Level lvl); + + /// Run the algorithm. + /// + /// @param ctx is the algorithm context with event information + /// @return a process code indication success or failure + ProcessCode execute(const AlgorithmContext& ctx) const override; + + private: + using HostTypes = + typename ActsExamples::Chain::Host::Types; + + typename HostTypes::ClusterizationAlgorithmType clusterizationAlgorithm; + typename HostTypes::SpacepointFormationAlgorithmType + spacepointFormationAlgorithm; + typename HostTypes::SeedingAlgorithmType seedingAlgorithm; + typename HostTypes::TrackParametersEstimationAlgorithmType + trackParametersEstimationAlgorithm; + typename HostTypes::FindingAlgorithmType findingAlgorithm; + typename HostTypes::FittingAlgorithmType fittingAlgorithm; + typename HostTypes::AmbiguityResolutionAlgorithmType + ambiguityResolutionAlgorithm; }; } // namespace ActsExamples::Traccc::Host \ No newline at end of file diff --git a/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/Types.hpp b/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/Types.hpp index 5f7a205b68c5..d3c904a66e7f 100644 --- a/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/Types.hpp +++ b/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/Types.hpp @@ -13,11 +13,11 @@ #include "traccc/clusterization/clusterization_algorithm.hpp" #include "traccc/clusterization/spacepoint_formation_algorithm.hpp" #include "traccc/finding/finding_algorithm.hpp" +#include "traccc/finding/finding_config.hpp" #include "traccc/fitting/fitting_algorithm.hpp" +#include "traccc/fitting/fitting_config.hpp" #include "traccc/seeding/seeding_algorithm.hpp" #include "traccc/seeding/track_params_estimation.hpp" -#include "traccc/finding/finding_config.hpp" -#include "traccc/fitting/fitting_config.hpp" // Detray include(s). #include "detray/core/detector.hpp" @@ -27,18 +27,25 @@ namespace ActsExamples::Chain::Host { template struct Types { - using DetectorType = detray::detector; - using StepperType = detray::rk_stepper>; - using NavigatorType = detray::navigator; - using FitterType = traccc::kalman_fitter; + using DetectorType = + detray::detector; + using StepperType = + detray::rk_stepper>; + using NavigatorType = detray::navigator; + using FitterType = traccc::kalman_fitter; - using ClusterizationAlgorithmType = traccc::host::clusterization_algorithm; - using SpacepointFormationAlgorithmType = traccc::host::spacepoint_formation_algorithm; - using SeedingAlgorithmType = traccc::seeding_algorithm; - using TrackParametersEstimationAlgorithmType = traccc::track_params_estimation; - using FindingAlgorithmType = traccc::finding_algorithm; - using FittingAlgorithmType = traccc::fitting_algorithm; - using AmbiguityResolutionAlgorithmType = traccc::greedy_ambiguity_resolution_algorithm; + using ClusterizationAlgorithmType = traccc::host::clusterization_algorithm; + using SpacepointFormationAlgorithmType = + traccc::host::spacepoint_formation_algorithm; + using SeedingAlgorithmType = traccc::seeding_algorithm; + using TrackParametersEstimationAlgorithmType = + traccc::track_params_estimation; + using FindingAlgorithmType = + traccc::finding_algorithm; + using FittingAlgorithmType = traccc::fitting_algorithm; + using AmbiguityResolutionAlgorithmType = + traccc::greedy_ambiguity_resolution_algorithm; }; -} +} // namespace ActsExamples::Chain::Host diff --git a/Examples/Algorithms/Traccc/Host/src/TracccChainAlgorithm.cpp b/Examples/Algorithms/Traccc/Host/src/TracccChainAlgorithm.cpp index 11978b1dfa16..fe8e9b310b66 100644 --- a/Examples/Algorithms/Traccc/Host/src/TracccChainAlgorithm.cpp +++ b/Examples/Algorithms/Traccc/Host/src/TracccChainAlgorithm.cpp @@ -14,62 +14,71 @@ #include #include #include -#include -#include #include - #include +#include +#include ActsExamples::Traccc::Host::TracccChainAlgorithm::TracccChainAlgorithm( Config cfg, Acts::Logging::Level lvl) - : ActsExamples::Traccc::Common::TracccChainAlgorithmBase(std::move(cfg), std::move(lvl)), - clusterizationAlgorithm(hostMemoryResource), - spacepointFormationAlgorithm(hostMemoryResource), - seedingAlgorithm(m_cfg.chainConfig->seedfinderConfig, m_cfg.chainConfig->spacepointGridConfig, m_cfg.chainConfig->seedfilterConfig, hostMemoryResource), - trackParametersEstimationAlgorithm(hostMemoryResource), - findingAlgorithm(m_cfg.chainConfig->findingConfig), - fittingAlgorithm(m_cfg.chainConfig->fittingConfig), - ambiguityResolutionAlgorithm(m_cfg.chainConfig->ambiguityResolutionConfig) -{} - -ActsExamples::ProcessCode ActsExamples::Traccc::Host::TracccChainAlgorithm::execute( -const ActsExamples::AlgorithmContext& ctx) const { - + : ActsExamples::Traccc::Common::TracccChainAlgorithmBase(std::move(cfg), + std::move(lvl)), + clusterizationAlgorithm(hostMemoryResource), + spacepointFormationAlgorithm(hostMemoryResource), + seedingAlgorithm(m_cfg.chainConfig->seedfinderConfig, + m_cfg.chainConfig->spacepointGridConfig, + m_cfg.chainConfig->seedfilterConfig, hostMemoryResource), + trackParametersEstimationAlgorithm(hostMemoryResource), + findingAlgorithm(m_cfg.chainConfig->findingConfig), + fittingAlgorithm(m_cfg.chainConfig->fittingConfig), + ambiguityResolutionAlgorithm( + m_cfg.chainConfig->ambiguityResolutionConfig) {} + +ActsExamples::ProcessCode +ActsExamples::Traccc::Host::TracccChainAlgorithm::execute( + const ActsExamples::AlgorithmContext& ctx) const { vecmem::host_memory_resource mr; - typename HostTypes::ClusterizationAlgorithmType::output_type measurements{&mr}; - typename HostTypes::SpacepointFormationAlgorithmType::output_type spacepoints{&mr}; + typename HostTypes::ClusterizationAlgorithmType::output_type measurements{ + &mr}; + typename HostTypes::SpacepointFormationAlgorithmType::output_type spacepoints{ + &mr}; typename HostTypes::SeedingAlgorithmType::output_type seeds{&mr}; - typename HostTypes::TrackParametersEstimationAlgorithmType::output_type params{&mr}; + typename HostTypes::TrackParametersEstimationAlgorithmType::output_type + params{&mr}; typename HostTypes::FindingAlgorithmType::output_type trackCandidates{&mr}; typename HostTypes::FittingAlgorithmType::output_type trackStates{&mr}; - typename HostTypes::AmbiguityResolutionAlgorithmType::output_type resolvedTrackStates{&mr}; + typename HostTypes::AmbiguityResolutionAlgorithmType::output_type + resolvedTrackStates{&mr}; const auto cellsMap = m_inputCells(ctx); auto [cells, modules] = converter.convertCells(cellsMap, &mr); - measurements = clusterizationAlgorithm(vecmem::get_data(cells), vecmem::get_data(modules)); - + measurements = clusterizationAlgorithm(vecmem::get_data(cells), + vecmem::get_data(modules)); + ACTS_INFO("Ran the clusterization algorithm"); - spacepoints = spacepointFormationAlgorithm(vecmem::get_data(measurements), vecmem::get_data(modules)); - + spacepoints = spacepointFormationAlgorithm(vecmem::get_data(measurements), + vecmem::get_data(modules)); + ACTS_INFO("Ran the spacepoint formation algorithm"); seeds = seedingAlgorithm(spacepoints); - + ACTS_INFO("Ran the seeding algorithm"); const typename FieldType::view_t fieldView(field); // Traccc expects a field vector of a constant field. - params = trackParametersEstimationAlgorithm(spacepoints, seeds, fieldView.at(0.f,0.f,0.f)); - + params = trackParametersEstimationAlgorithm(spacepoints, seeds, + fieldView.at(0.f, 0.f, 0.f)); + ACTS_INFO("Ran the parameters estimation algorithm"); trackCandidates = findingAlgorithm(detector, field, measurements, params); - + ACTS_INFO("Ran the finding algorithm"); trackStates = fittingAlgorithm(detector, field, trackCandidates); @@ -77,11 +86,12 @@ const ActsExamples::AlgorithmContext& ctx) const { ACTS_INFO("Ran the fitting algorithm"); resolvedTrackStates = ambiguityResolutionAlgorithm(trackStates); - + ACTS_INFO("Ran the ambiguity resolution algorithm"); const auto actsMeasurements = m_inputMeasurements(ctx); - auto result = converter.convertTracks(resolvedTrackStates, measurements, actsMeasurements); + auto result = converter.convertTracks(resolvedTrackStates, measurements, + actsMeasurements); m_outputTracks(ctx, std::move(result)); return ActsExamples::ProcessCode::SUCCESS;