diff --git a/Examples/Algorithms/Traccc/CMakeLists.txt b/Examples/Algorithms/Traccc/CMakeLists.txt index 11837f12298..b3f4781ecd7 100644 --- a/Examples/Algorithms/Traccc/CMakeLists.txt +++ b/Examples/Algorithms/Traccc/CMakeLists.txt @@ -14,4 +14,10 @@ target_link_libraries( ActsPluginDetray ) +add_subdirectory(Common) +target_link_libraries(ActsExamplesTraccc INTERFACE ActsExamplesTracccCommon) + +add_subdirectory(Host) +target_link_libraries(ActsExamplesTraccc INTERFACE ActsExamplesTracccHost) + install(TARGETS ActsExamplesTraccc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/Examples/Algorithms/Traccc/Common/CMakeLists.txt b/Examples/Algorithms/Traccc/Common/CMakeLists.txt new file mode 100644 index 00000000000..af7d423890b --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/CMakeLists.txt @@ -0,0 +1,28 @@ +add_library( + ActsExamplesTracccCommon + SHARED + src/Conversion/CellMapConversion.cpp + src/Conversion/DigitizationConversion.cpp + src/Conversion/MeasurementConversion.cpp + src/Conversion/SeedConversion.cpp + src/Conversion/SpacePointConversion.cpp +) + +target_include_directories( + ActsExamplesTracccCommon + PUBLIC $ +) + +target_link_libraries( + ActsExamplesTracccCommon + PUBLIC + ActsPluginDetray + ActsPluginTraccc + ActsExamplesFramework + ActsExamplesDigitization +) + +install( + TARGETS ActsExamplesTracccCommon + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/CellMapConversion.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/CellMapConversion.hpp new file mode 100644 index 00000000000..b5b5991158c --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/CellMapConversion.hpp @@ -0,0 +1,29 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "ActsExamples/EventData/Cluster.hpp" + +#include +#include +#include +#include + +#include "traccc/edm/cell.hpp" + +namespace ActsExamples::Traccc::Common::Conversion { + +/// @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); + +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/DigitizationConversion.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/DigitizationConversion.hpp new file mode 100644 index 00000000000..5ac7821603f --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/DigitizationConversion.hpp @@ -0,0 +1,24 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/GeometryHierarchyMap.hpp" +#include "Acts/Plugins/Traccc/DigitizationConfig.hpp" +#include "ActsExamples/Digitization/DigitizationConfig.hpp" + +namespace ActsExamples::Traccc::Common::Conversion { + +/// @brief Creates a traccc digitalization config from an Acts geometry hierarchy map +/// that contains the digitization configuration. +/// @param config the Acts geometry hierarchy map that contains the digitization configuration. +/// @return a traccc digitization config. +Acts::TracccPlugin::DigitizationConfig tracccConfig( + const Acts::GeometryHierarchyMap& config); + +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/MeasurementConversion.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/MeasurementConversion.hpp new file mode 100644 index 00000000000..5b6387bf67e --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/MeasurementConversion.hpp @@ -0,0 +1,78 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/Definitions/TrackParametrization.hpp" +#include "Acts/EventData/SourceLink.hpp" +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp" +#include "ActsExamples/EventData/IndexSourceLink.hpp" +#include "ActsExamples/EventData/Measurement.hpp" + +#include +#include +#include +#include +#include +#include +#include + +#include "detray/core/detector.hpp" +#include "detray/tracks/bound_track_parameters.hpp" +#include "traccc/definitions/qualifiers.hpp" +#include "traccc/definitions/track_parametrization.hpp" +#include "traccc/edm/measurement.hpp" +#include "traccc/edm/track_state.hpp" + +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); + +/// @brief Converts traccc measurements to acts measurements. +/// @param detector The detray detector, +/// @param measurements The traccc measurements, +/// @return A vector of Acts bound variant measurements. +/// @note The type IndexSourceLink is used for the measurements' source links. +template +inline MeasurementContainer convertTracccToActsMeasurements( + const detector_t& detector, iterator_t measurements_begin, + iterator_t measurements_end) { + MeasurementContainer measurementContainer; + + for (iterator_t i = measurements_begin; i != measurements_end; ++i) { + Acts::GeometryIdentifier moduleGeoId( + detector.surface((*i).surface_link).source); + Index measurementIdx = static_cast(measurementContainer.size()); + IndexSourceLink idxSourceLink{moduleGeoId, measurementIdx}; + + Eigen::Matrix + indices(2); + + for (unsigned int j = 0; j < 2; j++) { + indices[j] = + boundIndex(traccc::bound_indices((*i).subs.get_indices()[j])); + } + + measurementContainer.emplaceMeasurement<2>( + Acts::SourceLink{idxSourceLink}, indices, + Acts::TracccPlugin::detail::toActsVector<2>((*i).local), + Eigen::DiagonalMatrix( + Acts::TracccPlugin::detail::toActsVector<2>((*i).variance)) + .toDenseMatrix()); + } + + return measurementContainer; +} + +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/MeasurementMap.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/MeasurementMap.hpp new file mode 100644 index 00000000000..7ee62ad54ab --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/MeasurementMap.hpp @@ -0,0 +1,133 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "ActsExamples/EventData/Cluster.hpp" +#include "ActsExamples/EventData/IndexSourceLink.hpp" +#include "ActsExamples/EventData/Measurement.hpp" + +#include +#include +#include +#include + +#include "traccc/edm/cell.hpp" +#include "traccc/edm/measurement.hpp" + +namespace ActsExamples::Traccc::Common::Conversion { + +namespace { +template +std::map makeGenericMeasurementIndexMap( + const C1& fromMeasurements, const C2& toMeasurements, + M1GeoIdProj&& fromMeasurementGeoIdProjector, + M2GeoIdProj&& toMeasurementGeoIdProjector, + M1LocalProj&& fromMeasurementLocalProjector, + M2LocalProj&& toMeasurementLocalProjector, Acts::ActsScalar tol = 0.001) { + std::map outputMap; + + std::map> geometryMap; + + for (auto i = toMeasurements.cbegin(); i != toMeasurements.cend(); ++i) { + std::size_t key = toMeasurementGeoIdProjector(*i); + + geometryMap[key].push_back(std::distance(toMeasurements.cbegin(), i)); + } + + auto toProjectX = [&toMeasurementLocalProjector, + &toMeasurements](const std::size_t& i) { + return toMeasurementLocalProjector(toMeasurements.at(i)).first; + }; + + for (auto& i : geometryMap) { + std::ranges::sort(i.second, std::less{}, toProjectX); + } + + for (auto i = fromMeasurements.cbegin(); i != fromMeasurements.cend(); ++i) { + std::size_t key = fromMeasurementGeoIdProjector(*i); + + const std::vector& v = geometryMap[key]; + + auto targetX = fromMeasurementLocalProjector(*i).first; + + auto lo = + std::ranges::lower_bound(v, targetX - tol, std::less{}, toProjectX); + auto hi = + std::ranges::upper_bound(v, targetX + tol, std::less{}, toProjectX); + + bool found = false; + + for (auto j = lo; j != hi && !found; ++j) { + decltype(auto) c = toMeasurements.at(*j); + + if (std::abs(toMeasurementLocalProjector(c).first - + fromMeasurementLocalProjector(*i).first) <= tol && + std::abs(toMeasurementLocalProjector(c).second - + fromMeasurementLocalProjector(*i).second) <= tol) { + outputMap[std::distance(fromMeasurements.cbegin(), i)] = *j; + found = true; + } + } + } + + return outputMap; +} + +template +std::map makeTracccToActsMeasurementIndexMap( + const std::pmr::vector& tracccMeasurements, + const ActsExamples::MeasurementContainer& actsMeasurements, + const detector_t& detector) { + return makeGenericMeasurementIndexMap( + tracccMeasurements, actsMeasurements, + [&detector](const traccc::measurement& i) { + return detector.surface(i.surface_link).source; + }, + [](const ActsExamples::MeasurementContainer::ConstVariableProxy& i) { + return i.sourceLink() + .template get() + .geometryId() + .value(); + }, + [](const traccc::measurement& i) { + return std::make_pair(i.local[0], i.local[1]); + }, + [](const ActsExamples::MeasurementContainer::ConstVariableProxy& i) { + return std::make_pair(i.fullParameters()[0], i.fullParameters()[1]); + }); +} + +template +std::map makeActsToTracccMeasurementIndexMap( + const ActsExamples::MeasurementContainer& actsMeasurements, + const std::pmr::vector& tracccMeasurements, + const detector_t& detector) { + return makeGenericMeasurementIndexMap( + actsMeasurements, tracccMeasurements, + [](const ActsExamples::MeasurementContainer::ConstVariableProxy& i) { + return i.sourceLink() + .template get() + .geometryId() + .value(); + }, + [&detector](const traccc::measurement& i) { + return detector.surface(i.surface_link).source; + }, + [](const ActsExamples::MeasurementContainer::ConstVariableProxy& i) { + return std::make_pair(i.fullParameters()[0], i.fullParameters()[1]); + }, + [](const traccc::measurement& i) { + return std::make_pair(i.local[0], i.local[1]); + }); +} +} // namespace + +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/SeedConversion.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/SeedConversion.hpp new file mode 100644 index 00000000000..9358412a69e --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/SeedConversion.hpp @@ -0,0 +1,47 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/EventData/Seed.hpp" +#include "ActsExamples/EventData/SimSeed.hpp" +#include "ActsExamples/EventData/SimSpacePoint.hpp" + +#include +#include +#include + +#include "traccc/edm/seed.hpp" +#include "traccc/edm/spacepoint.hpp" +#include "vecmem/containers/vector.hpp" + +namespace ActsExamples::Traccc::Common::Conversion { + +/// @brief Converts a collection of traccc seeds and appends the result to the given outputContainer. +/// @param seeds the traccc seeds +/// @param SpacePointConv the spacepoint ConversionData (traccc space point -> acts space point). +/// @param outputContainer the container to put the converted space points into (an empty container is expected). +/// @returns The seed ConversionData (traccc seed -> acts seed). +SimSeedContainer convertTracccToActsSeeds( + std::vector>& + seeds, + const std::map& tracccToActsSpacepointIndexMap, + const std::vector& actsSpacepoints); + +/// @brief Converts a collection of seeds to traccc seeds and appends the result to the given outputContainer. +/// @param seeds theseeds +/// @param SpacePointConv the spacepoint ConversionData (acts space point -> traccc space point). +/// @param outputContainer the container to put the converted space points into (an empty container is expected). +/// @returns The seed ConversionData (acts seed -> traccc seed). +std::vector> +convertActsToTracccSeeds( + const SimSeedContainer& seeds, + const SimSpacePointContainer& actsSpacepoints, + const std::map& actsToTracccSpacepointIndexMap); + +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/SpacePointConversion.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/SpacePointConversion.hpp new file mode 100644 index 00000000000..0277193c75f --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/SpacePointConversion.hpp @@ -0,0 +1,57 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/EventData/SourceLink.hpp" +#include "ActsExamples/EventData/Measurement.hpp" +#include "ActsExamples/EventData/SimSpacePoint.hpp" +#include "ActsExamples/Traccc/Conversion/MeasurementConversion.hpp" + +#include +#include +#include +#include +#include + +#include "traccc/definitions/primitives.hpp" +#include "traccc/edm/measurement.hpp" +#include "traccc/edm/spacepoint.hpp" + +namespace ActsExamples::Traccc::Common::Conversion { + +/// @brief Converts a collection of traccc space points and appends the result to the given outputContainer. +/// @param spacepoints the traccc spacepoints. +/// @param meausrementConv the measurement ConversionData (traccc measurement -> acts bound variant measurement). +/// @param outputContainer the container to put the converted space points into (an empty container is expected). +/// @returns The spacepoint ConversionData (traccc space point -> acts space point) +std::pair> +convertTracccToActsSpacePoints( + std::vector>& + spacePoints, + const std::map& tracccToActsMeasurementIndexMap, + const MeasurementContainer& actsMeasurements); + +/// @brief Converts a collection of space points to traccc space points and appends the result to the given outputContainer. +/// @param spacepoints the traccc space points. +/// @param meausrementConv the measurement ConversionData (acts bound variant measurement -> traccc measurement). +/// @param outputContainer the container to put the converted space points into (an empty container is expected). +/// @returns The spacepoint ConversionData (acts space point -> traccc space point) +std::pair>, + std::map> +convertActsToTracccSpacePoints( + const SimSpacePointContainer& actsSpacePoints, + const std::map& actsToTracccMeasurementIndexMap, + const std::vector>& + tracccMeasurements); + +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/TrackConversion.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/TrackConversion.hpp new file mode 100644 index 00000000000..999b3823453 --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/TrackConversion.hpp @@ -0,0 +1,125 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/EventData/SourceLink.hpp" +#include "Acts/EventData/TrackContainer.hpp" +#include "Acts/EventData/VectorMultiTrajectory.hpp" +#include "Acts/EventData/VectorTrackContainer.hpp" +#include "Acts/Geometry/TrackingGeometry.hpp" +#include "Acts/Plugins/Traccc/TrackConversion.hpp" +#include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/EventData/Measurement.hpp" +#include "ActsExamples/EventData/Track.hpp" +#include "ActsExamples/Traccc/Conversion/MeasurementConversion.hpp" + +#include +#include +#include + +#include + +#include "detray/core/detector.hpp" +#include "traccc/edm/measurement.hpp" +#include "traccc/geometry/geometry.hpp" + +namespace ActsExamples::Traccc::Common::Conversion { + +/// @brief Maps the measurements of the track states from traccc measurements to acts measurements. +/// @param trackContainer the track container +/// @param map the measurement map. +template class holder_t> +void mapTrackStateMeasurements( + Acts::TrackContainer& + trackContainer, + const std::map& tracccToActsMeasurementIndexMap, + const MeasurementContainer& actsMeasurements, + std::unique_ptr _logger) { + ACTS_LOCAL_LOGGER(std::move(_logger)); + + std::size_t nFailedTrackStateConversions = 0; + + for (auto track : trackContainer) { + for (auto trackState : track.trackStates()) { + traccc::measurement tracccMeasurement = + trackState.getUncalibratedSourceLink() + .template get(); + + if (auto mapIt = tracccToActsMeasurementIndexMap.find( + tracccMeasurement.measurement_id); + mapIt != tracccToActsMeasurementIndexMap.cend()) { + Acts::SourceLink sl = actsMeasurements + .at(tracccToActsMeasurementIndexMap.at( + tracccMeasurement.measurement_id)) + .sourceLink(); + + trackState.setUncalibratedSourceLink(std::move(sl)); + } else { + nFailedTrackStateConversions++; + } + + // Set the calibrated source link, + trackState.allocateCalibrated(2); + assert(trackState.hasCalibrated()); + + trackState.template calibrated<2>() = + Acts::TracccPlugin::detail::toActsVector<2>(tracccMeasurement.local); + trackState.template calibratedCovariance<2>() = + Eigen::DiagonalMatrix( + Acts::TracccPlugin::detail::toActsVector<2>( + tracccMeasurement.variance)) + .toDenseMatrix(); + trackState.setBoundSubspaceIndices( + {Acts::BoundIndices::eBoundLoc0, Acts::BoundIndices::eBoundLoc1}); + } + } + + if (nFailedTrackStateConversions > 0) { + ACTS_WARNING("Failed to properly convert " << nFailedTrackStateConversions + << " track states!"); + } +} + +/// @brief Converts a container of traccc tracks to a container of Acts tracks. The +/// measurements conversion data provided will be used for updating both the +/// calibrated and uncalibrated measurements/sourcelinks. +/// @param tracccTrackContainer The traccc tracks. +/// @param measurementConv the traccc measurements to acts measurement conversion data. +/// @param trackingGeometry the tracking geometry. +/// @param trackingGeometry the detray detector. +/// @return An Acts const track container. +template +ConstTrackContainer convertTracccToActsTracks( + traccc_track_container_t& tracccTrackContainer, + const std::map& tracccToActsMeasurementIndexMap, + const MeasurementContainer& actsMeasurements, + const Acts::TrackingGeometry& trackingGeometry, const detector_t& detector, + std::unique_ptr _logger) { + auto trackContainer = std::make_shared(); + auto trackStateContainer = std::make_shared(); + TrackContainer tracks(trackContainer, trackStateContainer); + + Acts::TracccPlugin::makeTracks(tracccTrackContainer, tracks, detector, + trackingGeometry); + + mapTrackStateMeasurements(tracks, tracccToActsMeasurementIndexMap, + actsMeasurements, std::move(_logger)); + + ConstTrackContainer constTracks{ + std::make_shared( + std::move(*trackContainer)), + std::make_shared( + std::move(*trackStateContainer))}; + + return constTracks; +} + +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/include/ActsExamples/Traccc/DetrayPropagator.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/DetrayPropagator.hpp similarity index 100% rename from Examples/Algorithms/Traccc/include/ActsExamples/Traccc/DetrayPropagator.hpp rename to Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/DetrayPropagator.hpp diff --git a/Examples/Algorithms/Traccc/include/ActsExamples/Traccc/DetrayStore.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/DetrayStore.hpp similarity index 100% rename from Examples/Algorithms/Traccc/include/ActsExamples/Traccc/DetrayStore.hpp rename to Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/DetrayStore.hpp diff --git a/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/TracccChainConfig.hpp b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/TracccChainConfig.hpp new file mode 100644 index 00000000000..7d6a09cab45 --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/TracccChainConfig.hpp @@ -0,0 +1,54 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/TrackingGeometry.hpp" +#include "Acts/MagneticField/ConstantBField.hpp" +#include "ActsExamples/Digitization/DigitizationConfig.hpp" +#include "ActsExamples/Traccc/DetrayStore.hpp" + +#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" + +namespace ActsExamples::Traccc::Common { + +struct TracccChainConfig { + std::string inputCells; + std::string inputMeasurements; + std::string inputSpacePoints; + std::string inputSeeds; + std::string outputSpacePoints; + std::string outputSeeds; + std::string outputTracks; + + bool enableAmbiguityResolution; + + std::shared_ptr trackingGeometry = nullptr; + std::shared_ptr detrayStore = nullptr; + std::shared_ptr field = nullptr; + Acts::GeometryHierarchyMap digitizationConfigs; + + traccc::seedfinder_config seedfinderConfig; + traccc::spacepoint_grid_config spacepointGridConfig{seedfinderConfig}; + traccc::seedfilter_config seedfilterConfig; + traccc::finding_config findingConfig; + traccc::fitting_config fittingConfig; + traccc::greedy_ambiguity_resolution_algorithm::config_t + ambiguityResolutionConfig; +}; + +} // namespace ActsExamples::Traccc::Common diff --git a/Examples/Algorithms/Traccc/Common/src/Conversion/CellMapConversion.cpp b/Examples/Algorithms/Traccc/Common/src/Conversion/CellMapConversion.cpp new file mode 100644 index 00000000000..05c25a32d5f --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/src/Conversion/CellMapConversion.cpp @@ -0,0 +1,51 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#include "ActsExamples/Traccc/Conversion/CellMapConversion.hpp" + +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "ActsExamples/EventData/Cluster.hpp" + +#include +#include +#include +#include + +#include "traccc/edm/cell.hpp" + +namespace ActsExamples::Traccc::Common::Conversion { + +std::map> tracccCellsMap( + const std::map>& map) { + std::map> tracccCellMap; + for (const auto& [geometryID, cells] : map) { + std::vector tracccCells; + for (const auto& cell : cells) { + traccc::cell::link_type moduleLink = 0; + + tracccCells.emplace_back(static_cast(cell.bin[0]), + static_cast(cell.bin[1]), + static_cast(cell.activation), 0.f, + moduleLink); + } + std::ranges::sort(tracccCells, + [](const traccc::cell& lhs, const traccc::cell& rhs) { + if (lhs.module_link != rhs.module_link) { + return lhs.module_link < rhs.module_link; + } else if (lhs.channel1 != rhs.channel1) { + return (lhs.channel1 < rhs.channel1); + } else { + return (lhs.channel0 < rhs.channel0); + } + }); + tracccCellMap.insert({geometryID, 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 new file mode 100644 index 00000000000..73d36446586 --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/src/Conversion/DigitizationConversion.cpp @@ -0,0 +1,38 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#include "ActsExamples/Traccc/Conversion/DigitizationConversion.hpp" + +#include "Acts/Geometry/GeometryHierarchyMap.hpp" +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Plugins/Traccc/DigitizationConfig.hpp" +#include "Acts/Utilities/BinUtility.hpp" +#include "ActsExamples/Digitization/DigitizationConfig.hpp" + +#include +#include + +namespace ActsExamples::Traccc::Common::Conversion { + +Acts::TracccPlugin::DigitizationConfig tracccConfig( + const Acts::GeometryHierarchyMap& config) { + using ElementType = std::pair; + + std::vector vec; + + for (std::size_t i = 0; i < config.size(); i++) { + vec.push_back({config.idAt(i), + Acts::TracccPlugin::ModuleDigitizationConfig{ + config.valueAt(i).geometricDigiConfig.segmentation}}); + } + + return Acts::TracccPlugin::DigitizationConfig(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 new file mode 100644 index 00000000000..680b739bdbd --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/src/Conversion/MeasurementConversion.cpp @@ -0,0 +1,38 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#include "ActsExamples/Traccc/Conversion/MeasurementConversion.hpp" + +#include "Acts/Definitions/TrackParametrization.hpp" + +#include "traccc/definitions/track_parametrization.hpp" + +namespace ActsExamples::Traccc::Common::Conversion { + +Acts::BoundIndices boundIndex(const traccc::bound_indices tracccBoundIndex) { + switch (tracccBoundIndex) { + case traccc::bound_indices::e_bound_loc0: + return Acts::BoundIndices::eBoundLoc0; + case traccc::bound_indices::e_bound_loc1: + return Acts::BoundIndices::eBoundLoc1; + case traccc::bound_indices::e_bound_phi: + return Acts::BoundIndices::eBoundPhi; + case traccc::bound_indices::e_bound_theta: + return Acts::BoundIndices::eBoundTheta; + case traccc::bound_indices::e_bound_qoverp: + return Acts::BoundIndices::eBoundQOverP; + case traccc::bound_indices::e_bound_time: + return Acts::BoundIndices::eBoundTime; + case traccc::bound_indices::e_bound_size: + return Acts::BoundIndices::eBoundSize; + default: + throw std::runtime_error("Could not convert traccc bound index"); + } +} + +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/src/Conversion/SeedConversion.cpp b/Examples/Algorithms/Traccc/Common/src/Conversion/SeedConversion.cpp new file mode 100644 index 00000000000..a236ebc2ff9 --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/src/Conversion/SeedConversion.cpp @@ -0,0 +1,70 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#include "ActsExamples/Traccc/Conversion/SeedConversion.hpp" + +#include "Acts/EventData/Seed.hpp" +#include "ActsExamples/EventData/SimSeed.hpp" +#include "ActsExamples/EventData/SimSpacePoint.hpp" + +#include +#include +#include + +#include "traccc/edm/seed.hpp" +#include "traccc/edm/spacepoint.hpp" +#include "vecmem/containers/vector.hpp" + +namespace ActsExamples::Traccc::Common::Conversion { + +SimSeedContainer convertTracccToActsSeeds( + std::vector>& + seeds, + const std::map& tracccToActsSpacepointIndexMap, + const std::vector& actsSpacepoints) { + auto fn = [&tracccToActsSpacepointIndexMap, actsSpacepoints](auto& seed) { + return SimSeed( + actsSpacepoints.at(tracccToActsSpacepointIndexMap.at(seed.spB_link)), + actsSpacepoints.at(tracccToActsSpacepointIndexMap.at(seed.spM_link)), + actsSpacepoints.at(tracccToActsSpacepointIndexMap.at(seed.spT_link))); + }; + + SimSeedContainer outputContainer; + + std::ranges::transform(seeds, std::back_inserter(outputContainer), fn); + + return outputContainer; +} + +std::vector> +convertActsToTracccSeeds( + const SimSeedContainer& seeds, + const SimSpacePointContainer& actsSpacepoints, + const std::map& actsToTracccSpacepointIndexMap) { + auto fn = [&actsToTracccSpacepointIndexMap, + &actsSpacepoints](const SimSeed& seed) { + return traccc::seed{ + actsToTracccSpacepointIndexMap.at( + std::distance(actsSpacepoints.data(), seed.sp()[0])), + actsToTracccSpacepointIndexMap.at( + std::distance(actsSpacepoints.data(), seed.sp()[0])), + actsToTracccSpacepointIndexMap.at( + std::distance(actsSpacepoints.data(), seed.sp()[0])), + static_cast(seed.z()), + seed.seedQuality()}; + }; + + std::vector> + outputContainer; + + std::ranges::transform(seeds, std::back_inserter(outputContainer), fn); + + return outputContainer; +} + +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Common/src/Conversion/SpacePointConversion.cpp b/Examples/Algorithms/Traccc/Common/src/Conversion/SpacePointConversion.cpp new file mode 100644 index 00000000000..ea1bd387374 --- /dev/null +++ b/Examples/Algorithms/Traccc/Common/src/Conversion/SpacePointConversion.cpp @@ -0,0 +1,97 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/EventData/SourceLink.hpp" +#include "ActsExamples/EventData/Measurement.hpp" +#include "ActsExamples/EventData/SimSpacePoint.hpp" +#include "ActsExamples/Traccc/Conversion/MeasurementConversion.hpp" + +#include +#include +#include +#include +#include + +#include "traccc/definitions/primitives.hpp" +#include "traccc/edm/measurement.hpp" +#include "traccc/edm/spacepoint.hpp" + +namespace ActsExamples::Traccc::Common::Conversion { + +std::pair> +convertTracccToActsSpacePoints( + std::vector>& + spacePoints, + const std::map& tracccToActsMeasurementIndexMap, + const MeasurementContainer& actsMeasurements) { + SimSpacePointContainer convertedSpacePoints; + std::map outMap; + + for (std::size_t i = 0; i < spacePoints.size(); ++i) { + const traccc::spacepoint& spacePoint = spacePoints.at(i); + + const Acts::Vector3 globalPos(spacePoint.x(), spacePoint.y(), + spacePoint.z()); + const std::optional t = std::nullopt; + const Acts::ActsScalar varRho = 0; + const Acts::ActsScalar varZ = 0; + const std::optional varT = std::nullopt; + + if (auto measurementIndexIt = tracccToActsMeasurementIndexMap.find( + spacePoint.meas.measurement_id); + measurementIndexIt != tracccToActsMeasurementIndexMap.cend()) { + const Acts::SourceLink sourceLink = + actsMeasurements.at(measurementIndexIt->second).sourceLink(); + + boost::container::static_vector sourceLinks = { + sourceLink}; + + outMap[i] = convertedSpacePoints.size(); + convertedSpacePoints.emplace_back(globalPos, t, varRho, varZ, varT, + std::move(sourceLinks)); + } + } + + return std::make_pair(std::move(convertedSpacePoints), std::move(outMap)); +} + +std::pair>, + std::map> +convertActsToTracccSpacePoints( + const SimSpacePointContainer& actsSpacePoints, + const std::map& actsToTracccMeasurementIndexMap, + const std::vector>& + tracccMeasurements) { + std::vector> + outputContainer; + + std::map outputMap; + + for (std::size_t i = 0; i < actsSpacePoints.size(); ++i) { + const SimSpacePoint& spacePoint = actsSpacePoints.at(i); + + auto idx = spacePoint.sourceLinks()[0] + .get() + .index(); + + traccc::point3 global{spacePoint.x(), spacePoint.y(), spacePoint.z()}; + + outputMap[i] = outputContainer.size(); + outputContainer.emplace_back( + global, tracccMeasurements.at(actsToTracccMeasurementIndexMap.at(idx))); + } + + return std::make_pair(std::move(outputContainer), std::move(outputMap)); +} + +} // namespace ActsExamples::Traccc::Common::Conversion diff --git a/Examples/Algorithms/Traccc/Host/CMakeLists.txt b/Examples/Algorithms/Traccc/Host/CMakeLists.txt new file mode 100644 index 00000000000..4c1583194b5 --- /dev/null +++ b/Examples/Algorithms/Traccc/Host/CMakeLists.txt @@ -0,0 +1,13 @@ +add_library(ActsExamplesTracccHost SHARED src/TracccChainAlgorithm.cpp) + +target_include_directories( + ActsExamplesTracccHost + PUBLIC $ +) + +target_link_libraries(ActsExamplesTracccHost PUBLIC ActsExamplesTracccCommon) + +install( + TARGETS ActsExamplesTracccHost + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) diff --git a/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/TracccChainAlgorithm.hpp b/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/TracccChainAlgorithm.hpp new file mode 100644 index 00000000000..7ed20628a55 --- /dev/null +++ b/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/TracccChainAlgorithm.hpp @@ -0,0 +1,88 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Plugins/Covfie/FieldConversion.hpp" +#include "Acts/Plugins/Traccc/DigitizationConfig.hpp" +#include "ActsExamples/EventData/Cluster.hpp" +#include "ActsExamples/EventData/IndexSourceLink.hpp" +#include "ActsExamples/EventData/Measurement.hpp" +#include "ActsExamples/EventData/SimSeed.hpp" +#include "ActsExamples/EventData/Track.hpp" +#include "ActsExamples/Framework/DataHandle.hpp" +#include "ActsExamples/Framework/IAlgorithm.hpp" +#include "ActsExamples/Traccc/Host/Types.hpp" +#include "ActsExamples/Traccc/TracccChainConfig.hpp" + +#include +#include + +#include "traccc/geometry/geometry.hpp" + +namespace ActsExamples::Traccc::Host { + +class TracccChainAlgorithm : public IAlgorithm { + public: + using Config = Common::TracccChainConfig; + + /// Construct the traccc algorithm. + /// + /// @param cfg is the algorithm configuration + /// @param lvl is the logging level + TracccChainAlgorithm(const Config& cfg, Acts::Logging::Level lvl); + + private: + using field_t = + covfie::field>; + using detector_t = + detray::detector; + using cell_map_t = + std::map>; + + Config m_cfg; + vecmem::host_memory_resource m_hostMemoryResource; + const field_t m_field; + const std::map + m_surfaceTransforms; + const std::map + m_barcodeMap; + const Acts::TracccPlugin::DigitizationConfig m_digitizationConfig; + + using Types = ActsExamples::Traccc::Host::Types; + + typename Types::ClusterizationAlgorithmType clusterizationAlgorithm; + typename Types::SpacepointFormationAlgorithmType spacepointFormationAlgorithm; + typename Types::SeedingAlgorithmType seedingAlgorithm; + typename Types::TrackParametersEstimationAlgorithmType + trackParametersEstimationAlgorithm; + typename Types::FindingAlgorithmType findingAlgorithm; + typename Types::FittingAlgorithmType fittingAlgorithm; + typename Types::AmbiguityResolutionAlgorithmType ambiguityResolutionAlgorithm; + + ReadDataHandle m_inputCells{this, "InputCells"}; + ReadDataHandle m_inputMeasurements{this, + "InputMeasurements"}; + ReadDataHandle m_inputSpacePoints{this, + "InputSpacePoints"}; + ReadDataHandle m_inputSeeds{this, "InputSeeds"}; + WriteDataHandle> m_outputSpacePoints{ + this, "OutputSpacePoints"}; + WriteDataHandle> m_outputSeeds{this, "OutputSeeds"}; + WriteDataHandle m_outputTracks{this, "OutputTracks"}; + + public: + ActsExamples::ProcessCode execute( + const ActsExamples::AlgorithmContext& ctx) const override; + + const Config& config() const { return m_cfg; } +}; + +} // namespace ActsExamples::Traccc::Host diff --git a/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/Types.hpp b/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/Types.hpp new file mode 100644 index 00000000000..9395c551746 --- /dev/null +++ b/Examples/Algorithms/Traccc/Host/include/ActsExamples/Traccc/Host/Types.hpp @@ -0,0 +1,56 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include +#include + +#include "detray/core/detector.hpp" +#include "detray/propagator/rk_stepper.hpp" +#include "traccc/ambiguity_resolution/greedy_ambiguity_resolution_algorithm.hpp" +#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/geometry/silicon_detector_description.hpp" +#include "traccc/seeding/seeding_algorithm.hpp" +#include "traccc/seeding/track_params_estimation.hpp" + +namespace ActsExamples::Traccc::Host { + +struct Types { + using FieldType = + covfie::field>; + using DetectorType = + detray::detector; + using StepperType = + detray::rk_stepper>; + using NavigatorType = detray::navigator; + using FitterType = traccc::kalman_fitter; + + using SiliconDetectorDescriptionType = traccc::silicon_detector_description; + + 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::Traccc::Host diff --git a/Examples/Algorithms/Traccc/Host/src/TracccChainAlgorithm.cpp b/Examples/Algorithms/Traccc/Host/src/TracccChainAlgorithm.cpp new file mode 100644 index 00000000000..15ec38a7791 --- /dev/null +++ b/Examples/Algorithms/Traccc/Host/src/TracccChainAlgorithm.cpp @@ -0,0 +1,312 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#include "ActsExamples/Traccc/Host/TracccChainAlgorithm.hpp" + +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/Plugins/Traccc/BarcodeMap.hpp" +#include "Acts/Plugins/Traccc/CellConversion.hpp" +#include "Acts/Plugins/Traccc/SurfaceMap.hpp" +#include "Acts/Plugins/Traccc/TrackConversion.hpp" +#include "Acts/Utilities/Logger.hpp" +#include "ActsExamples/EventData/Measurement.hpp" +#include "ActsExamples/Traccc/Conversion/CellMapConversion.hpp" +#include "ActsExamples/Traccc/Conversion/DigitizationConversion.hpp" +#include "ActsExamples/Traccc/Conversion/MeasurementConversion.hpp" +#include "ActsExamples/Traccc/Conversion/MeasurementMap.hpp" +#include "ActsExamples/Traccc/Conversion/SeedConversion.hpp" +#include "ActsExamples/Traccc/Conversion/SpacePointConversion.hpp" +#include "ActsExamples/Traccc/Conversion/TrackConversion.hpp" + +#include +#include +#include +#include +#include + +#include "traccc/edm/measurement.hpp" + +ActsExamples::Traccc::Host::TracccChainAlgorithm::TracccChainAlgorithm( + const Common::TracccChainConfig& cfg, Acts::Logging::Level lvl) + : IAlgorithm("TracccHostChain", lvl), + m_cfg(cfg), + m_field(Acts::CovfiePlugin::covfieField( + m_cfg.field != nullptr ? *m_cfg.field + : throw std::invalid_argument( + "Missing magnetic field, without which " + "the traccc algorithm cannot run."))), + m_surfaceTransforms{Acts::TracccPlugin::createSurfaceMap( + m_cfg.detrayStore != nullptr + ? m_cfg.detrayStore->detector + : throw std::invalid_argument( + "Missing detray detector, without which the traccc " + "algorithm cannot run."))}, + m_barcodeMap{Acts::TracccPlugin::createBarcodeMap( + m_cfg.detrayStore != nullptr + ? m_cfg.detrayStore->detector + : throw std::invalid_argument( + "Missing detray detector, without which the traccc " + "algorithm cannot run."))}, + m_digitizationConfig{ + Common::Conversion::tracccConfig(m_cfg.digitizationConfigs)}, + clusterizationAlgorithm(m_hostMemoryResource), + spacepointFormationAlgorithm(m_hostMemoryResource), + seedingAlgorithm(m_cfg.seedfinderConfig, m_cfg.spacepointGridConfig, + m_cfg.seedfilterConfig, m_hostMemoryResource), + trackParametersEstimationAlgorithm(m_hostMemoryResource), + findingAlgorithm(m_cfg.findingConfig), + fittingAlgorithm(m_cfg.fittingConfig), + ambiguityResolutionAlgorithm(m_cfg.ambiguityResolutionConfig) { + ACTS_INFO("traccc chain algorithm has a barcode map with " + << m_barcodeMap.size() << " elements"); + + if (m_cfg.digitizationConfigs.empty()) { + throw std::invalid_argument( + "Digitization configuration is empty; cannot run any meaningful " + "reconstruction."); + } + + if (m_cfg.trackingGeometry == nullptr) { + throw std::invalid_argument( + "Missing ACTS tracking geometry, without which the traccc algorithm " + "cannot run."); + } + + if (m_cfg.inputCells.empty()) { + throw std::invalid_argument( + "Cell input was not given, without which the traccc algorithm cannot " + "run."); + } + m_inputCells.initialize(m_cfg.inputCells); + + if (m_cfg.inputMeasurements.empty()) { + throw std::invalid_argument( + "Measurement input was not given, without which the traccc algorithm " + "cannot run (yet)."); + } + m_inputMeasurements.initialize(m_cfg.inputMeasurements); + + if (!m_cfg.inputSpacePoints.empty()) { + if (m_cfg.inputSeeds.empty()) { + throw std::invalid_argument( + "Spacepoint input was given, but seed input was not; this is " + "invalid."); + } + m_inputSpacePoints.initialize(m_cfg.inputSpacePoints); + m_inputSeeds.initialize(m_cfg.inputSeeds); + } + + if (!m_cfg.outputSpacePoints.empty()) { + m_outputSpacePoints.initialize(m_cfg.outputSpacePoints); + } + + if (!m_cfg.outputSeeds.empty()) { + m_outputSeeds.initialize(m_cfg.outputSeeds); + } + + if (!m_cfg.outputTracks.empty()) { + m_outputTracks.initialize(m_cfg.outputTracks); + } +} + +ActsExamples::ProcessCode +ActsExamples::Traccc::Host::TracccChainAlgorithm::execute( + const ActsExamples::AlgorithmContext& ctx) const { + vecmem::host_memory_resource mr; + // Read the cells + const auto cellsMap = m_inputCells(ctx); + + ACTS_INFO("Read " << std::accumulate( + cellsMap.begin(), cellsMap.end(), std::size_t{0}, + [](const std::size_t& acc, const auto& i) { + return acc + i.second.size(); + }) + << " cells from " << cellsMap.size() << " modules"); + + // Convert the cells + auto tcm = Common::Conversion::tracccCellsMap(cellsMap); + auto [cells, modules] = Acts::TracccPlugin::createCellsAndModules( + mr, tcm, m_surfaceTransforms, m_digitizationConfig, m_barcodeMap, + logger().cloneWithSuffix("CreateCellsAndModules")); + + ACTS_INFO("Beginning reconstruction algorithm; have cell map of size " + << tcm.size() << ", cell vector of size " << cells.size() + << ", and module vector of size " << modules.size()); + + auto measurements = clusterizationAlgorithm(vecmem::get_data(cells), + vecmem::get_data(modules)); + ACTS_INFO("Ran the clustering algorithm; produced " << measurements.size() + << " measurements"); + + auto spacepoints = spacepointFormationAlgorithm( + vecmem::get_data(measurements), vecmem::get_data(modules)); + ACTS_INFO("Ran the spacepoint formation algorithm; produced " + << spacepoints.size() << " spacepoints"); + + auto seeds = seedingAlgorithm(spacepoints); + ACTS_INFO("Ran the seeding algorithm; produced " << seeds.size() << " seeds"); + + // Now we have both traccc measurements and acts measurements + // We have run the traccc digitization and we expect that Acts + // digitization has also been run, since otherwise we cannot do compare + // and do truth matching. + + // Read the acts measurements + auto& actsMeasurements = m_inputMeasurements(ctx); + // Determine which traccc measurements are equivalent to which Acts + // measurements. This is needed since we cannot guarantee that the + // measurements have the same ordering. We run the following to obtain a + // mapping between the two measurement collections. Note: if the number of + // measurements don't match during the perhaps mergeCommonCorner or + // doMerge is false in the digitization algorithm configuration. + ACTS_INFO("ACTS measurement container contains " << actsMeasurements.size() + << " measurements"); + + std::map tracccToActsMeasurementIndexMap = + Common::Conversion::makeTracccToActsMeasurementIndexMap( + measurements, actsMeasurements, m_cfg.detrayStore->detector); + + ACTS_INFO("traccc to ACTS measurement index map has " + << tracccToActsMeasurementIndexMap.size() << " keys"); + + if (m_inputSpacePoints.isInitialized() && m_inputSeeds.isInitialized()) { + ACTS_INFO("Using ACTS spacepoints and seeds; discarding traccc results"); + + std::map actsToTracccMeasurementIndexMap = + Common::Conversion::makeActsToTracccMeasurementIndexMap( + actsMeasurements, measurements, m_cfg.detrayStore->detector); + + // Read the exteranlly generated spacepoints and convert them. + ACTS_INFO("Reading and converting ACTS spacepoints to traccc spacepoints"); + auto& actsSpacePoints = m_inputSpacePoints(ctx); + spacepoints.clear(); + + auto [newSpacepoints, actsToTracccSpacepointIndexMap] = ActsExamples:: + Traccc::Common::Conversion::convertActsToTracccSpacePoints( + actsSpacePoints, actsToTracccMeasurementIndexMap, measurements); + + spacepoints = std::move(newSpacepoints); + + ACTS_INFO("Converted " << actsSpacePoints.size() << " ACTS spacepoints to " + << spacepoints.size() << " traccc spacepoints"); + + // Read the exteranlly generated seeds and convert them. + ACTS_INFO("Reading and converting ACTS seeds to traccc seeds"); + auto& actsSeeds = m_inputSeeds(ctx); + + std::vector> + newSeeds = + ActsExamples::Traccc::Common::Conversion::convertActsToTracccSeeds( + actsSeeds, actsSpacePoints, actsToTracccSpacepointIndexMap); + + seeds = std::move(newSeeds); + + ACTS_INFO("Converted " << actsSeeds.size() << " ACTS seeds to " + << seeds.size() << " traccc seeds"); + } else { + ACTS_INFO("Continuing with traccc data (not using converted ACTS results)"); + + if (m_outputSpacePoints.isInitialized() || m_outputSeeds.isInitialized()) { + ACTS_INFO( + "Performing conversions to output traccc spacepoint and seed data"); + MeasurementContainer convertedMeasurements = + Common::Conversion::convertTracccToActsMeasurements( + m_cfg.detrayStore->detector, measurements.cbegin(), + measurements.cend()); + + ACTS_INFO("Converted traccc measurement container contains " + << convertedMeasurements.size() << " measurements"); + + if (actsMeasurements.size() != convertedMeasurements.size()) { + ACTS_WARNING( + "ACTS produced a different number of measurements than traccc!"); + } + + std::map tmpTracccToActsMeasurementIndexMap = + Common::Conversion::makeTracccToActsMeasurementIndexMap( + measurements, convertedMeasurements, m_cfg.detrayStore->detector); + + ACTS_INFO("Converting traccc spacepoints to ACTS spacepoints"); + + auto [convertedSpacePoints, spacepointIndexMapTracccToActs] = + ActsExamples::Traccc::Common::Conversion:: + convertTracccToActsSpacePoints(spacepoints, + tmpTracccToActsMeasurementIndexMap, + convertedMeasurements); + + ACTS_INFO("Converted " << spacepoints.size() << " traccc spacepoints to " + << convertedSpacePoints.size() + << " ACTS spacepoints"); + + if (m_outputSpacePoints.isInitialized()) { + if (m_outputSeeds.isInitialized()) { + m_outputSpacePoints(ctx, + std::vector(convertedSpacePoints)); + } else { + m_outputSpacePoints(ctx, std::move(convertedSpacePoints)); + } + ACTS_INFO( + "Wrote ACTS spacepoints (converted from traccc) to whiteboard"); + } + + if (m_outputSeeds.isInitialized()) { + ACTS_INFO("Converting traccc seeds to ACTS seeds"); + SimSeedContainer convertedSeeds = + ActsExamples::Traccc::Common::Conversion::convertTracccToActsSeeds( + seeds, spacepointIndexMapTracccToActs, convertedSpacePoints); + ACTS_INFO("Converted " << seeds.size() << " traccc seeds to " + << convertedSeeds.size() << " ACTS seeds"); + m_outputSeeds(ctx, std::move(convertedSeeds)); + ACTS_INFO("Wrote ACTS seeds (converted from traccc) to whiteboard"); + } + } + } + + if (m_outputTracks.isInitialized()) { + // We run the reconstruction with traccc. + const field_t::view_t fieldView(m_field); + + // Traccc expects a field vector of a constant field. + auto bv = fieldView.at(0.f, 0.f, 0.f); + + auto params = trackParametersEstimationAlgorithm(spacepoints, seeds, + {bv[0], bv[1], bv[2]}); + ACTS_INFO("Ran the track parameter estimation algorithm; estimated " + << params.size() << " track parameters"); + + auto trackCandidates = + findingAlgorithm(m_cfg.detrayStore->detector, field_t::view_t(m_field), + measurements, params); + ACTS_INFO("Ran the finding algorithm; found " << trackCandidates.size() + << " track candidates"); + + auto tracks = fittingAlgorithm(m_cfg.detrayStore->detector, + field_t::view_t(m_field), trackCandidates); + ACTS_INFO("Ran the fitting algorithm; fitted " << tracks.size() + << " tracks"); + + if (m_cfg.enableAmbiguityResolution) { + tracks = ambiguityResolutionAlgorithm(tracks); + ACTS_INFO("Ran the ambiguity resolution algorithm; kept " << tracks.size() + << " tracks"); + } else { + ACTS_INFO("Skipped the ambiguity resolution algorithm"); + } + + // Now we convert the traccc tracks to acts tracks. + ConstTrackContainer convertedTracks = + Common::Conversion::convertTracccToActsTracks( + tracks, tracccToActsMeasurementIndexMap, actsMeasurements, + *m_cfg.trackingGeometry, m_cfg.detrayStore->detector, + logger().cloneWithSuffix("TracccToActsTracks")); + + m_outputTracks(ctx, std::move(convertedTracks)); + } + + return ActsExamples::ProcessCode::SUCCESS; +} diff --git a/Examples/Python/CMakeLists.txt b/Examples/Python/CMakeLists.txt index ff1e5901f43..25db67dbb1c 100644 --- a/Examples/Python/CMakeLists.txt +++ b/Examples/Python/CMakeLists.txt @@ -101,10 +101,14 @@ if(ACTS_BUILD_PLUGIN_TRACCC) target_sources(ActsPythonBindings PRIVATE src/Covfie.cpp) target_link_libraries(ActsPythonBindings PUBLIC ActsExamplesTraccc) target_sources(ActsPythonBindings PRIVATE src/Traccc.cpp) + target_sources(ActsPythonBindings PRIVATE src/TracccChainHost.cpp) + + list(APPEND py_files examples/traccc.py) else() target_sources(ActsPythonBindings PRIVATE src/DetrayStub.cpp) target_sources(ActsPythonBindings PRIVATE src/CovfieStub.cpp) target_sources(ActsPythonBindings PRIVATE src/TracccStub.cpp) + target_sources(ActsPythonBindings PRIVATE src/TracccChainHostStub.cpp) endif() if(ACTS_BUILD_PLUGIN_ACTSVG) diff --git a/Examples/Python/python/acts/examples/traccc.py b/Examples/Python/python/acts/examples/traccc.py new file mode 100644 index 00000000000..b4ecb8c6b90 --- /dev/null +++ b/Examples/Python/python/acts/examples/traccc.py @@ -0,0 +1,6 @@ +from acts._adapter import _patch_config +from acts import ActsPythonBindings + +_patch_config(ActsPythonBindings._examples.traccc) + +from acts.ActsPythonBindings._examples.traccc import * diff --git a/Examples/Python/src/Traccc.cpp b/Examples/Python/src/Traccc.cpp index 71f6ca29147..e69ec41c4e0 100644 --- a/Examples/Python/src/Traccc.cpp +++ b/Examples/Python/src/Traccc.cpp @@ -12,6 +12,7 @@ #include "ActsExamples/Propagation/PropagatorInterface.hpp" #include "ActsExamples/Traccc/DetrayPropagator.hpp" #include "ActsExamples/Traccc/DetrayStore.hpp" +#include "ActsExamples/Traccc/TracccChainConfig.hpp" #include #include @@ -26,46 +27,180 @@ using namespace ActsExamples; namespace Acts::Python { -void addTraccc(Context& ctx) { - auto [m, mex] = ctx.get("main", "examples"); +void addTracccChainHost(Context &ctx); - auto traccc = mex.def_submodule("traccc"); +void addTraccc(Context &ctx) { + auto mex = ctx.get("examples"); + auto m = mex.def_submodule("traccc"); + ctx.modules["traccc"] = m; /// Define host detray store { py::class_>( - traccc, "DetrayHostStore"); + m, "DetrayHostStore"); /// Convert the detector and create a DetrayHostStore /// /// @param gctx the geometry context /// @param detector the detector to be converted /// @param options the conversion options - traccc.def("convertDetectorHost", [](const GeometryContext& gctx, - const Experimental::Detector& detector, - DetrayConverter::Options options) { + m.def("convertDetectorHost", [](const GeometryContext &gctx, + const Experimental::Detector &detector, + DetrayConverter::Options options) { return DetrayHostStore::create(gctx, detector, options); }); } /// Define the DetrayPropagator { - traccc.def( - "createSlPropagatorHost", - [](std::shared_ptr detrayStore, - bool sterile = false) { - std::shared_ptr detrayProagator = nullptr; - - using DetrayLineStepper = - detray::line_stepper; - - using DetrayPropagator = - DetrayPropagator; - - DetrayPropagator::Config cfg{detrayStore, sterile}; - detrayProagator = std::make_shared(cfg); - return detrayProagator; - }); + m.def("createSlPropagatorHost", + [](std::shared_ptr detrayStore, + bool sterile = false) { + std::shared_ptr detrayPropagator = nullptr; + + using DetrayLineStepper = + detray::line_stepper; + + using DetrayPropagator = + DetrayPropagator; + + DetrayPropagator::Config cfg{detrayStore, sterile}; + detrayPropagator = std::make_shared(cfg); + return detrayPropagator; + }); + } + + { + using Config = traccc::seedfinder_config; + + auto c = py::class_(m, "SeedFinderConfig").def(py::init<>()); + + ACTS_PYTHON_STRUCT_BEGIN(c, Config); + ACTS_PYTHON_MEMBER(zMin); + ACTS_PYTHON_MEMBER(zMax); + ACTS_PYTHON_MEMBER(rMax); + ACTS_PYTHON_MEMBER(rMin); + ACTS_PYTHON_MEMBER(collisionRegionMin); + ACTS_PYTHON_MEMBER(collisionRegionMax); + ACTS_PYTHON_MEMBER(phiMin); + ACTS_PYTHON_MEMBER(phiMax); + ACTS_PYTHON_MEMBER(minPt); + ACTS_PYTHON_MEMBER(cotThetaMax); + ACTS_PYTHON_MEMBER(deltaRMin); + ACTS_PYTHON_MEMBER(deltaRMax); + ACTS_PYTHON_MEMBER(impactMax); + ACTS_PYTHON_MEMBER(sigmaScattering); + ACTS_PYTHON_MEMBER(maxPtScattering); + ACTS_PYTHON_MEMBER(maxSeedsPerSpM); + ACTS_PYTHON_MEMBER(bFieldInZ); + ACTS_PYTHON_MEMBER(beamPos); + ACTS_PYTHON_MEMBER(radLengthPerSeed); + ACTS_PYTHON_MEMBER(zAlign); + ACTS_PYTHON_MEMBER(rAlign); + ACTS_PYTHON_MEMBER(sigmaError); + ACTS_PYTHON_MEMBER(highland); + ACTS_PYTHON_MEMBER(maxScatteringAngle2); + ACTS_PYTHON_MEMBER(pTPerHelixRadius); + ACTS_PYTHON_MEMBER(minHelixDiameter2); + ACTS_PYTHON_MEMBER(pT2perRadius); + ACTS_PYTHON_MEMBER(phiBinDeflectionCoverage); + ACTS_PYTHON_MEMBER(neighbor_scope); + ACTS_PYTHON_STRUCT_END(); + } + + { + using Config = traccc::spacepoint_grid_config; + + auto c = py::class_(m, "SpacePointGridConfig") + .def(py::init()); + + ACTS_PYTHON_STRUCT_BEGIN(c, Config); + ACTS_PYTHON_MEMBER(bFieldInZ); + ACTS_PYTHON_MEMBER(minPt); + ACTS_PYTHON_MEMBER(rMax); + ACTS_PYTHON_MEMBER(zMax); + ACTS_PYTHON_MEMBER(zMin); + ACTS_PYTHON_MEMBER(deltaRMax); + ACTS_PYTHON_MEMBER(cotThetaMax); + ACTS_PYTHON_MEMBER(impactMax); + ACTS_PYTHON_MEMBER(phiMin); + ACTS_PYTHON_MEMBER(phiMax); + ACTS_PYTHON_MEMBER(phiBinDeflectionCoverage); + ACTS_PYTHON_STRUCT_END(); + } + + { + using Config = traccc::seedfilter_config; + + auto c = py::class_(m, "SeedFilterConfig").def(py::init<>()); + + ACTS_PYTHON_STRUCT_BEGIN(c, Config); + ACTS_PYTHON_MEMBER(deltaInvHelixDiameter); + ACTS_PYTHON_MEMBER(impactWeightFactor); + ACTS_PYTHON_MEMBER(compatSeedWeight); + ACTS_PYTHON_MEMBER(deltaRMin); + ACTS_PYTHON_MEMBER(maxSeedsPerSpM); + ACTS_PYTHON_MEMBER(compatSeedLimit); + ACTS_PYTHON_MEMBER(max_triplets_per_spM); + ACTS_PYTHON_MEMBER(good_spB_min_radius); + ACTS_PYTHON_MEMBER(good_spB_weight_increase); + ACTS_PYTHON_MEMBER(good_spT_max_radius); + ACTS_PYTHON_MEMBER(good_spT_weight_increase); + ACTS_PYTHON_MEMBER(good_spB_min_weight); + ACTS_PYTHON_MEMBER(seed_min_weight); + ACTS_PYTHON_MEMBER(spB_min_radius); + ACTS_PYTHON_STRUCT_END(); } + + { + using Config = traccc::finding_config; + + auto c = py::class_(m, "FindingConfig").def(py::init<>()); + + ACTS_PYTHON_STRUCT_BEGIN(c, Config); + ACTS_PYTHON_MEMBER(max_num_branches_per_seed); + ACTS_PYTHON_MEMBER(max_num_branches_per_surface); + ACTS_PYTHON_MEMBER(min_track_candidates_per_track); + ACTS_PYTHON_MEMBER(max_track_candidates_per_track); + ACTS_PYTHON_MEMBER(max_num_skipping_per_cand); + ACTS_PYTHON_MEMBER(min_step_length_for_next_surface); + ACTS_PYTHON_MEMBER(max_step_counts_for_next_surface); + ACTS_PYTHON_MEMBER(chi2_max); + ACTS_PYTHON_MEMBER(propagation); + ACTS_PYTHON_MEMBER(n_measurements_per_thread); + ACTS_PYTHON_STRUCT_END(); + } + + { + using Config = traccc::fitting_config; + + auto c = py::class_(m, "FittingConfig").def(py::init<>()); + + ACTS_PYTHON_STRUCT_BEGIN(c, Config); + ACTS_PYTHON_MEMBER(n_iterations); + ACTS_PYTHON_MEMBER(propagation); + ACTS_PYTHON_STRUCT_END(); + } + + { + using Config = traccc::greedy_ambiguity_resolution_algorithm::config_t; + + auto c = py::class_(m, "GreedyAmbiguityResolutionAlgorithmConfig") + .def(py::init<>()); + + ACTS_PYTHON_STRUCT_BEGIN(c, Config); + ACTS_PYTHON_MEMBER(maximum_shared_hits); + ACTS_PYTHON_MEMBER(maximum_iterations); + ACTS_PYTHON_MEMBER(n_measurements_min); + ACTS_PYTHON_MEMBER(check_obvious_errs); + ACTS_PYTHON_MEMBER(measurement_id_0_warning_threshold); + ACTS_PYTHON_MEMBER(verbose_error); + ACTS_PYTHON_MEMBER(verbose_warning); + ACTS_PYTHON_MEMBER(verbose_info); + ACTS_PYTHON_MEMBER(verbose_debug); + ACTS_PYTHON_STRUCT_END(); + } + + addTracccChainHost(ctx); } } // namespace Acts::Python diff --git a/Examples/Python/src/TracccChainHost.cpp b/Examples/Python/src/TracccChainHost.cpp new file mode 100644 index 00000000000..c20c86054ac --- /dev/null +++ b/Examples/Python/src/TracccChainHost.cpp @@ -0,0 +1,34 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#include "Acts/Plugins/Python/Utilities.hpp" +#include "ActsExamples/EventData/Index.hpp" +#include "ActsExamples/Traccc/Host/TracccChainAlgorithm.hpp" + +#include + +#include +#include + +namespace py = pybind11; + +namespace Acts::Python { + +void addTracccChainHost(Context& ctx) { + auto m = ctx.get("traccc"); + + ACTS_PYTHON_DECLARE_ALGORITHM( + ActsExamples::Traccc::Host::TracccChainAlgorithm, m, + "ReconstructionChainHostAlgorithm", inputCells, inputMeasurements, + inputSpacePoints, inputSeeds, outputSpacePoints, outputSeeds, + outputTracks, enableAmbiguityResolution, detrayStore, trackingGeometry, + field, digitizationConfigs, seedfinderConfig, seedfilterConfig, + findingConfig, fittingConfig, ambiguityResolutionConfig); +} + +} // namespace Acts::Python diff --git a/Examples/Python/src/TracccChainHostStub.cpp b/Examples/Python/src/TracccChainHostStub.cpp new file mode 100644 index 00000000000..8809f096399 --- /dev/null +++ b/Examples/Python/src/TracccChainHostStub.cpp @@ -0,0 +1,17 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#include +#include + +namespace py = pybind11; + +namespace Acts::Python { +void addTracccChainHost(Context &) {} + +} // namespace Acts::Python diff --git a/Examples/Python/tests/test_examples.py b/Examples/Python/tests/test_examples.py index 46044a9513c..98014b1d334 100644 --- a/Examples/Python/tests/test_examples.py +++ b/Examples/Python/tests/test_examples.py @@ -1040,7 +1040,7 @@ def test_digitization_example_input_parsing(digi_config_file): DIGI_SHARE_DIR / "default-smearing-config-generic.json", DIGI_SHARE_DIR / "default-geometric-config-generic.json", ], - ids=["smeared", "geometric"], + ids=["smeared", "geometric", "odd-smeared", "odd-geometric"], ) def test_digitization_example_input( trk_geo, tmp_path, assert_root_hash, digi_config_file diff --git a/Examples/Scripts/Python/traccc_host.py b/Examples/Scripts/Python/traccc_host.py new file mode 100644 index 00000000000..9f99df542b9 --- /dev/null +++ b/Examples/Scripts/Python/traccc_host.py @@ -0,0 +1,263 @@ +#!/usr/bin/env python3 + +import os +import argparse +import pathlib +import math + +import acts +import acts.examples +import acts.examples.traccc +from acts import GeometryContext +from acts.examples.simulation import ( + addParticleGun, + MomentumConfig, + EtaConfig, + PhiConfig, + ParticleConfig, + addFatras, + ParticleSelectorConfig, +) +from acts.examples.dd4hep import ( + DD4hepDetector, + DD4hepDetectorOptions, + DD4hepGeometryService, +) +from acts.examples.odd import getOpenDataDetector, getOpenDataDetectorDirectory + +# def create_gen1_tracking_geometry(): +# return getOpenDataDetector() + +# def create_gen2_tracking_geometry(): + +if __name__ == "__main__": + u = acts.UnitConstants + + parser = argparse.ArgumentParser(description="Full chain with the OpenDataDetector") + parser.add_argument( + "--output", + "-o", + help="Output directory", + type=pathlib.Path, + default=pathlib.Path.cwd() / "odd_output", + ) + parser.add_argument( + "--events", "-n", help="Number of events", type=int, default=100 + ) + parser.add_argument( + "--gun-particles", + help="Multiplicity (no. of particles) of the particle gun", + type=int, + default=4, + ) + parser.add_argument( + "--gun-multiplicity", + help="Multiplicity (no. of vertices) of the particle gun", + type=int, + default=200, + ) + parser.add_argument( + "--gun-eta-range", + nargs=2, + help="Eta range of the particle gun", + type=float, + default=[-3.0, 3.0], + ) + parser.add_argument( + "--gun-pt-range", + nargs=2, + help="Pt range of the particle gun (GeV)", + type=float, + default=[1.0 * u.GeV, 10.0 * u.GeV], + ) + parser.add_argument( + "--digi-config", help="Digitization configuration file", type=pathlib.Path + ) + parser.add_argument( + "--material-config", help="Material map configuration file", type=pathlib.Path + ) + parser.add_argument( + "--ambi-solver", + help="Set which ambiguity solver to use, default is the classical one", + type=str, + choices=["greedy", "scoring", "ML"], + default="greedy", + ) + parser.add_argument( + "--ambi-config", + help="Set the configuration file for the Score Based ambiguity resolution", + type=pathlib.Path, + default=pathlib.Path.cwd() / "ambi_config.json", + ) + + parser.add_argument( + "--MLSeedFilter", + help="Use the Ml seed filter to select seed after the seeding step", + action="store_true", + ) + parser.add_argument( + "--reco", + help="Switch reco on/off", + default=True, + action=argparse.BooleanOptionalAction, + ) + parser.add_argument( + "--output-root", + help="Switch root output on/off", + default=True, + action=argparse.BooleanOptionalAction, + ) + parser.add_argument( + "--output-csv", + help="Switch csv output on/off", + default=True, + action=argparse.BooleanOptionalAction, + ) + + args = parser.parse_args() + + outputDir = args.output + geoDir = getOpenDataDetectorDirectory() + + oddMaterialMap = ( + args.material_config + if args.material_config + else geoDir / "data/odd-material-maps.root" + ) + + oddDigiConfig = ( + args.digi_config + if args.digi_config + else geoDir / "config/odd-digi-geometric-config.json" + ) + + oddMaterialDeco = acts.IMaterialDecorator.fromFile(oddMaterialMap) + + odd_dir = getOpenDataDetectorDirectory() + odd_xml = odd_dir / "xml" / "OpenDataDetector.xml" + + volumeRadiusCutsMap = { + 28: [850.0], # LStrip negative z + 30: [850.0], # LStrip positive z + 23: [400.0, 550.0], # SStrip negative z + 25: [400.0, 550.0], # SStrip positive z + 16: [100.0], # Pixels negative z + 18: [100.0], # Pixels positive z + } + + def geoid_hook(geoid, surface): + gctx = acts.GeometryContext() + if geoid.volume() in volumeRadiusCutsMap: + r = math.sqrt(surface.center(gctx)[0] ** 2 + surface.center(gctx)[1] ** 2) + + geoid.setExtra(1) + for cut in volumeRadiusCutsMap[geoid.volume()]: + if r > cut: + geoid.setExtra(geoid.extra() + 1) + + return geoid + + dd4hepConfig = acts.examples.dd4hep.DD4hepGeometryService.Config( + xmlFileNames=[str(odd_xml)], + logLevel=acts.logging.INFO, + dd4hepLogLevel=acts.logging.INFO, + geometryIdentifierHook=acts.GeometryIdentifierHook(geoid_hook), + ) + detector = acts.examples.dd4hep.DD4hepDetector() + + mdecorator = acts.examples.RootMaterialDecorator( + fileName=str(odd_dir / "data/odd-material-maps.root"), + level=acts.logging.INFO, + ) + + trackingGeometry, decorators = detector.finalize(dd4hepConfig, mdecorator) + + dd4hepIdGeoIdMap = acts.examples.dd4hep.createDD4hepIdGeoIdMap(trackingGeometry) + dd4hepIdGeoIdValueMap = {} + for key, value in dd4hepIdGeoIdMap.items(): + dd4hepIdGeoIdValueMap[key] = value + + geoContext = acts.GeometryContext() + cOptions = DD4hepDetectorOptions(logLevel=acts.logging.INFO, emulateToGraph="") + acts.examples.dd4hep.attachDD4hepGeoIdMapper(cOptions, dd4hepIdGeoIdValueMap) + [final_detector, contextors, store] = detector.finalize(geoContext, cOptions) + + field = acts.ConstantBField(acts.Vector3(0.0, 0.0, 2.0 * u.T)) + rnd = acts.examples.RandomNumbers(seed=42) + + s = acts.examples.Sequencer( + events=args.events, + numThreads=1, + outputDir=str(outputDir), + ) + + addParticleGun( + s, + MomentumConfig( + args.gun_pt_range[0] * u.GeV, + args.gun_pt_range[1] * u.GeV, + transverse=True, + ), + EtaConfig(args.gun_eta_range[0], args.gun_eta_range[1]), + PhiConfig(0.0, 360.0 * u.degree), + ParticleConfig( + args.gun_particles, acts.PdgParticle.eMuon, randomizeCharge=True + ), + vtxGen=acts.examples.GaussianVertexGenerator( + mean=acts.Vector4(0, 0, 0, 0), + stddev=acts.Vector4(0.0125 * u.mm, 0.0125 * u.mm, 55.5 * u.mm, 1.0 * u.ns), + ), + multiplicity=args.gun_multiplicity, + rnd=rnd, + ) + + addFatras( + s, + trackingGeometry, + field, + preSelectParticles=(ParticleSelectorConfig()), + enableInteractions=True, + outputDirRoot=outputDir if args.output_root else None, + outputDirCsv=outputDir if args.output_csv else None, + rnd=rnd, + ) + + digiCfg = acts.examples.DigitizationConfig( + acts.examples.readDigiConfigFromJson( + str(oddDigiConfig), + ), + surfaceByIdentifier=trackingGeometry.geoIdSurfaceMap(), + randomNumbers=acts.examples.RandomNumbers(), + inputSimHits="simhits", + outputMeasurements="measurements", + doMerge=True, + doOutputCells=True, + doClusterization=True, + ) + + digiAlg = acts.examples.DigitizationAlgorithm(digiCfg, acts.logging.VERBOSE) + + s.addAlgorithm(digiAlg) + + detrayStoreOptions = acts.ActsPythonBindings.detray.DetrayConverter.Options() + detrayStoreOptions.convertMaterial = False + detrayStore = acts.examples.traccc.convertDetectorHost( + geoContext, final_detector, detrayStoreOptions + ) + + recoAlg = acts.examples.traccc.ReconstructionChainHostAlgorithm( + level=acts.logging.INFO, + field=field, + detrayStore=detrayStore, + trackingGeometry=trackingGeometry, + inputCells="cells", + inputMeasurements="measurements", + outputTracks="tracks", + digitizationConfigs=acts.examples.readDigiConfigFromJson( + str(oddDigiConfig), + ), + ) + + s.addAlgorithm(recoAlg) + + s.run() diff --git a/Plugins/CMakeLists.txt b/Plugins/CMakeLists.txt index f766f8d1293..83f0dc89aaa 100644 --- a/Plugins/CMakeLists.txt +++ b/Plugins/CMakeLists.txt @@ -12,6 +12,7 @@ add_component_if(Onnx PluginOnnx ACTS_BUILD_PLUGIN_ONNX) add_component_if(ExaTrkX PluginExaTrkX ACTS_BUILD_PLUGIN_EXATRKX) add_component_if(Detray PluginDetray ACTS_BUILD_PLUGIN_TRACCC) add_component_if(Covfie PluginCovfie ACTS_BUILD_PLUGIN_TRACCC) +add_component_if(Traccc PluginTraccc ACTS_BUILD_PLUGIN_TRACCC) add_component_if(Hashing PluginHashing ACTS_BUILD_PLUGIN_HASHING) # dependent plugins. depend either on a independent plugins or on one another diff --git a/Plugins/Traccc/CMakeLists.txt b/Plugins/Traccc/CMakeLists.txt new file mode 100644 index 00000000000..bd7e54ae9be --- /dev/null +++ b/Plugins/Traccc/CMakeLists.txt @@ -0,0 +1,25 @@ +add_library(ActsPluginTraccc SHARED src/CellConversion.cpp) + +target_include_directories( + ActsPluginTraccc + PUBLIC + $ + $ +) +target_link_libraries( + ActsPluginTraccc + PUBLIC + ActsCore + traccc::core + vecmem::core + detray::test_utils + detray::io + ActsPluginCovfie +) + +install( + TARGETS ActsPluginTraccc + EXPORT ActsPluginTracccTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) +install(DIRECTORY include/Acts DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/BarcodeMap.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/BarcodeMap.hpp new file mode 100644 index 00000000000..f6155028750 --- /dev/null +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/BarcodeMap.hpp @@ -0,0 +1,38 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/GeometryIdentifier.hpp" + +#include +#include +#include +#include +#include +#include + +#include "detray/core/detector.hpp" + +namespace Acts::TracccPlugin { + +/// @brief Creates a map from Acts geometry ID (value) to detray barcode. +/// @param detector the detray detector. +/// @return A map (key = geometry ID value, value = detray geometry barcode). +template +inline std::map +createBarcodeMap(const detray::detector& detector) { + // Construct a map from Acts surface identifiers to Detray barcodes. + std::map barcodeMap; + for (const auto& surface : detector.surfaces()) { + barcodeMap[Acts::GeometryIdentifier(surface.source)] = surface.barcode(); + } + return barcodeMap; +} + +} // namespace Acts::TracccPlugin diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/CellConversion.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/CellConversion.hpp new file mode 100644 index 00000000000..226b0031570 --- /dev/null +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/CellConversion.hpp @@ -0,0 +1,50 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/GeometryHierarchyMap.hpp" +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Plugins/Traccc/BarcodeMap.hpp" +#include "Acts/Plugins/Traccc/DigitizationConfig.hpp" +#include "Acts/Utilities/Logger.hpp" + +#include +#include +#include +#include +#include +#include + +#include "detray/core/detector.hpp" +#include "traccc/edm/cell.hpp" +#include "traccc/geometry/geometry.hpp" +#include "traccc/geometry/silicon_detector_description.hpp" + +namespace Acts::TracccPlugin { + +/// @brief Converts a "geometry ID -> traccc cells" map to traccc cells and modules. +/// @param mr The memory resource to use. +/// @param cellsMap A map from Acts geometry ID value to traccc cells. +/// @param geom The traccc geometry. +/// @param dconfig The traccc digitization configuration. +/// @param barcode_map A map from Acts geometry ID value to detray barcode. +/// @return A tuple containing the traccc cells (first item) and traccc modules (second item). +std::tuple +createCellsAndModules( + vecmem::memory_resource& mr, + const std::map>& + cellsMap, + const std::map& geom, + const DigitizationConfig& dconfig, + const std::map& + barcodeMap, + std::unique_ptr logger); + +} // namespace Acts::TracccPlugin diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp new file mode 100644 index 00000000000..5e23759ccaa --- /dev/null +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp @@ -0,0 +1,38 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Definitions/Algebra.hpp" + +#include + +namespace Acts::TracccPlugin::detail { + +/// @brief Creates a new Acts vector from another vector type. +template +inline Acts::ActsVector toActsVector(const dvector_t& dvec) { + Acts::ActsVector res; + for (std::size_t i = 0; i < N; i++) { + res(i) = static_cast(dvec[i]); + } + return res; +} +/// @brief Creates a new Acts square matrix from another square matrix type. +template +inline Acts::ActsSquareMatrix toActsSquareMatrix(const matrixNxN_t& mat) { + Acts::ActsSquareMatrix res; + for (std::size_t x = 0; x < N; x++) { + for (std::size_t y = 0; y < N; y++) { + res(x, y) = static_cast(mat[x][y]); + } + } + return res; +} + +} // namespace Acts::TracccPlugin::detail diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/DigitizationConfig.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/DigitizationConfig.hpp new file mode 100644 index 00000000000..7c156821182 --- /dev/null +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/DigitizationConfig.hpp @@ -0,0 +1,26 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/GeometryHierarchyMap.hpp" +#include "Acts/Utilities/BinUtility.hpp" + +namespace Acts::TracccPlugin { + +/// Type describing the digitization configuration of a detector module +struct ModuleDigitizationConfig { + Acts::BinUtility segmentation; + char dimensions = 2; + float variance_y = 0.f; +}; + +/// Type describing the digitization configuration for the whole detector +using DigitizationConfig = Acts::GeometryHierarchyMap; + +} // namespace Acts::TracccPlugin diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/SurfaceMap.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/SurfaceMap.hpp new file mode 100644 index 00000000000..46f51ba1669 --- /dev/null +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/SurfaceMap.hpp @@ -0,0 +1,40 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Geometry/GeometryIdentifier.hpp" + +#include + +#include "detray/core/detector.hpp" +#include "traccc/definitions/primitives.hpp" + +namespace Acts::TracccPlugin { + +/// @brief Creates a map from Acts geometry ID (value) to detray barcode. +/// @param detector the detray detector. +/// @return A map (key = geometry ID value, value = detray geometry barcode). +template +std::map createSurfaceMap( + const detray::detector& detector) { + std::map maps; + + const typename detray::detector::geometry_context + ctx0{}; + + for (const auto& sf_desc : detector.surfaces()) { + const detray::tracking_surface sf{detector, sf_desc.barcode()}; + + maps.insert({Acts::GeometryIdentifier(sf_desc.source), sf.transform(ctx0)}); + } + + return maps; +} + +} // namespace Acts::TracccPlugin diff --git a/Plugins/Traccc/include/Acts/Plugins/Traccc/TrackConversion.hpp b/Plugins/Traccc/include/Acts/Plugins/Traccc/TrackConversion.hpp new file mode 100644 index 00000000000..137919e8efc --- /dev/null +++ b/Plugins/Traccc/include/Acts/Plugins/Traccc/TrackConversion.hpp @@ -0,0 +1,245 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#pragma once + +#include "Acts/Definitions/Algebra.hpp" +#include "Acts/Definitions/TrackParametrization.hpp" +#include "Acts/EventData/ParticleHypothesis.hpp" +#include "Acts/EventData/SourceLink.hpp" +#include "Acts/EventData/SubspaceHelpers.hpp" +#include "Acts/EventData/TrackContainer.hpp" +#include "Acts/EventData/TrackParameters.hpp" +#include "Acts/EventData/TrackProxy.hpp" +#include "Acts/EventData/detail/ParameterTraits.hpp" +#include "Acts/Geometry/TrackingGeometry.hpp" +#include "Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp" + +#include +#include +#include + +#include + +#include "detray/core/detector.hpp" +#include "detray/tracks/bound_track_parameters.hpp" +#include "traccc/edm/track_state.hpp" + +namespace Acts::TracccPlugin { + +template +inline std::size_t nMeasurements( + const std::vector, allocator_t> + trackStates) { + std::set uniqueMeasurements; + for (const auto& trackState : trackStates) { + uniqueMeasurements.insert(trackState.get_measurement()); + } + return uniqueMeasurements.size(); +} + +/// @brief Creates a new Acts bound track parameters from detray bound track parameters. +/// @param dparams the detray bound track parameters. +/// @param detector the detray detector. +/// @param trackingGeometry the Acts tracking geometry. +/// @return An Acts BoundTrackParameters with data copied from a detray bound_track_parameters. +template +inline auto newParams(const detray::bound_track_parameters& dparams, + const detray::detector& detector, + const Acts::TrackingGeometry& trackingGeometry) { + constexpr std::size_t kFullSize = + Acts::detail::kParametersSize; + Acts::ActsVector parameterVector = + detail::toActsVector(dparams.vector()[0]); + typename Acts::BoundTrackParameters::CovarianceMatrix cov = + detail::toActsSquareMatrix(dparams.covariance()); + Acts::ParticleHypothesis particleHypothesis = + Acts::ParticleHypothesis::pion(); + + auto geoID = + Acts::GeometryIdentifier(detector.surface(dparams.surface_link()).source); + + auto surface = trackingGeometry.findSurface(geoID); + + if (surface == nullptr) { + throw std::runtime_error( + "Mismatch between Acts geometry and detray detector: Acts tracking " + "geometry does not contain geometry ID " + + std::to_string(geoID.value())); + } + + Acts::BoundTrackParameters params(surface->getSharedPtr(), parameterVector, + std::make_optional(std::move(cov)), + particleHypothesis); + + return params; +} + +/// @brief Copies data from a traccc fitting result to an Acts track proxy. +/// @param source the traccc track fitting result to copy from. +/// @param destination the Acts track proxy to copy to. +/// @param detector the detray detector of the traccc track fitting result. +/// @param trackingGeometry the Acts tracking geometry. +template class holder_t, typename metadata_t, + typename container_t> +inline void copyParams( + const detray::bound_track_parameters& dparams, + Acts::TrackProxy& + destination, + const detray::detector& detector, + const Acts::TrackingGeometry& trackingGeometry) { + const auto params = newParams(dparams, detector, trackingGeometry); + destination.parameters() = params.parameters(); + destination.covariance() = params.covariance().value(); + destination.setReferenceSurface(params.referenceSurface().getSharedPtr()); +} + +/// @brief Copies data from a traccc track state to a Acts track state proxy. +/// @param source the traccc track state to copy from. +/// @param destination the Acts track state proxy to copy to. +/// @param detector the detray detector of the traccc track track state. +/// @param trackingGeometry the Acts tracking geometry. +/// @note Sets the uncalibrated source link and calibrated measurement to the traccc measurement. +template +inline void copyTrackState( + const traccc::track_state& source, + Acts::TrackStateProxy& destination, + const detray::detector& detector, + const Acts::TrackingGeometry& trackingGeometry) { + constexpr std::size_t kFullSize = + Acts::detail::kParametersSize; + constexpr std::size_t kSize = 2UL; + + auto geoID = + Acts::GeometryIdentifier(detector.surface(source.surface_link()).source); + auto surface = trackingGeometry.findSurface(geoID)->getSharedPtr(); + destination.setReferenceSurface(surface); + + using Parameters = + typename Acts::TrackStateProxy::Parameters; + using Covariance = + typename Acts::TrackStateProxy::Covariance; + + destination.predicted() = Parameters( + detail::toActsVector(source.predicted().vector()[0]).data()); + destination.predictedCovariance() = Covariance( + detail::toActsSquareMatrix(source.predicted().covariance()) + .data()); + + destination.smoothed() = Parameters( + detail::toActsVector(source.smoothed().vector()[0]).data()); + destination.smoothedCovariance() = Covariance( + detail::toActsSquareMatrix(source.smoothed().covariance()) + .data()); + + destination.filtered() = Parameters( + detail::toActsVector(source.filtered().vector()[0]).data()); + destination.filteredCovariance() = Covariance( + detail::toActsSquareMatrix(source.filtered().covariance()) + .data()); + + destination.jacobian() = Covariance( + detail::toActsSquareMatrix(source.jacobian()).data()); + + destination.chi2() = static_cast(source.smoothed_chi2()); + + auto typeFlags = destination.typeFlags(); + typeFlags.set(TrackStateFlag::ParameterFlag); + if (surface->surfaceMaterial() != nullptr) { + typeFlags.set(TrackStateFlag::MaterialFlag); + } + if (source.is_hole) { + typeFlags.set(TrackStateFlag::HoleFlag); + } + typeFlags.set(TrackStateFlag::MeasurementFlag); + + const traccc::measurement& measurement = source.get_measurement(); + + destination.setUncalibratedSourceLink(Acts::SourceLink{measurement}); + + destination.allocateCalibrated(kSize); + + destination.template calibrated() = + detail::toActsVector(measurement.local); + + auto cov = Eigen::DiagonalMatrix( + detail::toActsVector(measurement.variance)) + .toDenseMatrix(); + destination.template calibratedCovariance() = cov; + + Acts::FixedSubspaceHelper subspace( + measurement.subs.get_indices()); + destination.setBoundSubspaceIndices( + {Acts::BoundIndices::eBoundLoc0, Acts::BoundIndices::eBoundLoc1}); +} + +/// @brief Creates a new track in the Acts track container. +/// This new track will contain data copied from the traccc track container +/// element (track and track state data). +/// @param tracccTrack The traccc container element to copy from. +/// @param trackContainer The Acts track container. The new tracks will be added to this container. +/// @param detector The detray detector. +/// @param trackingGeometry The Acts tracking geometry. +/// @note Sets the uncalibrated source link and calibrated measurement to the traccc measurement. +template class holder_t, typename metadata_t, + typename container_t> +inline auto makeTrack( + const traccc::container_element& + tracccTrack, + Acts::TrackContainer& + trackContainer, + const detray::detector& detector, + const Acts::TrackingGeometry& trackingGeometry) { + auto fittingResult = tracccTrack.header; + auto trackStates = tracccTrack.items; + + auto track = trackContainer.makeTrack(); + copyParams(fittingResult.fit_params, track, detector, trackingGeometry); + track.chi2() = static_cast(fittingResult.chi2); + track.nDoF() = static_cast(fittingResult.ndf); + track.nMeasurements() = static_cast(nMeasurements(trackStates)); + + // Make the track states. + for (const auto& tstate : trackStates) { + auto state = track.appendTrackState(); + copyTrackState(tstate, state, detector, trackingGeometry); + } + + track.linkForward(); + + return track; +} + +/// @brief Creates a new track in the Acts track container for each track in the traccc track container. +/// The new tracks will contain data copied from the traccc track container +/// element (track and track state data). +/// @param tracccTrackContainer The traccc container containing the traccc tracks. +/// @param trackContainer The Acts track container. The new tracks will be added to this container. +/// @param detector The detray detector. +/// @param trackingGeometry The Acts tracking geometry. +/// @note Sets the uncalibrated source link and calibrated measurement to the traccc measurement. +template class holder_t, + typename metadata_t, typename container_t> +inline void makeTracks( + const traccc_track_container_t& tracccTrackContainer, + Acts::TrackContainer& + trackContainer, + const detray::detector& detector, + const Acts::TrackingGeometry& trackingGeometry) { + for (std::size_t i = 0; i < tracccTrackContainer.size(); i++) { + makeTrack(tracccTrackContainer[i], trackContainer, detector, + trackingGeometry); + } +} + +} // namespace Acts::TracccPlugin diff --git a/Plugins/Traccc/src/CellConversion.cpp b/Plugins/Traccc/src/CellConversion.cpp new file mode 100644 index 00000000000..f383ec50072 --- /dev/null +++ b/Plugins/Traccc/src/CellConversion.cpp @@ -0,0 +1,121 @@ +// This file is part of the ACTS project. +// +// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. + +#include "Acts/Geometry/GeometryHierarchyMap.hpp" +#include "Acts/Geometry/GeometryIdentifier.hpp" +#include "Acts/Plugins/Traccc/BarcodeMap.hpp" +#include "Acts/Plugins/Traccc/DigitizationConfig.hpp" +#include "Acts/Utilities/Logger.hpp" + +#include +#include +#include +#include +#include +#include + +#include "detray/core/detector.hpp" +#include "traccc/edm/cell.hpp" +#include "traccc/geometry/geometry.hpp" +#include "traccc/geometry/silicon_detector_description.hpp" +#include "vecmem/memory/memory_resource.hpp" + +namespace Acts::TracccPlugin { + +std::tuple +createCellsAndModules( + vecmem::memory_resource& mr, + const std::map>& + cellsMap, + const std::map& geom, + const DigitizationConfig& dconfig, + const std::map& + barcodeMap, + std::unique_ptr _logger) { + ACTS_LOCAL_LOGGER(std::move(_logger)); + + traccc::cell_collection_types::host cells(&mr); + traccc::silicon_detector_description::host modules(mr); + + modules.resize(cellsMap.size()); + + std::size_t module_idx = 0; + + // Fill the output containers with the ordered cells and modules. + for (const auto& [originalGeometryID, mapCells] : cellsMap) { + // Modify the geometry ID of the module if a barcode map is + // provided. + auto it = barcodeMap.find(originalGeometryID); + + if (it == barcodeMap.cend()) { + ACTS_WARNING("Geometry element " << originalGeometryID + << " was not found in the barcode map."); + continue; + } + + Acts::GeometryIdentifier::Value geometryID = it->second.value(); + + // Add the module and its cells to the output. + modules.geometry_id().at(module_idx) = + detray::geometry::barcode{geometryID}; + modules.acts_geometry_id().at(module_idx) = originalGeometryID.value(); + modules.threshold().at(module_idx) = 0.f; + + const DigitizationConfig::Iterator digi_it = + dconfig.find(originalGeometryID); + + if (digi_it == dconfig.end()) { + std::ostringstream msg; + msg << "Could not find digitization config for geometry ID: " + << originalGeometryID; + throw std::runtime_error(msg.str()); + } + + // Find/set the 3D position of the detector module. + if (!geom.contains(originalGeometryID.value())) { + throw std::runtime_error("Could not find placement for geometry ID " + + std::to_string(originalGeometryID.value())); + } + + // Set the value on the module description. + modules.placement().at(module_idx) = geom.at(originalGeometryID.value()); + + const auto binning_data = digi_it->segmentation.binningData(); + + if (!binning_data.empty()) { + modules.reference_x().at(module_idx) = binning_data.at(0).min; + modules.pitch_x().at(module_idx) = binning_data.at(0).step; + } else { + modules.reference_x().at(module_idx) = 0.f; + modules.pitch_x().at(module_idx) = 1.f; + } + + if (binning_data.size() >= 2) { + modules.reference_y().at(module_idx) = binning_data.at(1).min; + modules.pitch_y().at(module_idx) = binning_data.at(1).step; + } else { + modules.reference_y().at(module_idx) = 0.f; + modules.pitch_y().at(module_idx) = 1.f; + } + + modules.dimensions().at(module_idx) = digi_it->dimensions; + + for (auto& cell : mapCells) { + cells.push_back(cell); + // std::cout << cell.channel0 << ", " << cell.channel1 << " @ " << module_idx << std::endl; + // Set the module link. + cells.back().module_link = module_idx; + } + + module_idx++; + } + return std::make_tuple(std::move(cells), std::move(modules)); +} + +} // namespace Acts::TracccPlugin diff --git a/cmake/ActsConfig.cmake.in b/cmake/ActsConfig.cmake.in index 7ed4b3884a5..6e473214697 100644 --- a/cmake/ActsConfig.cmake.in +++ b/cmake/ActsConfig.cmake.in @@ -84,6 +84,21 @@ if (PluginHashing IN_LIST Acts_COMPONENTS) find_dependency(Annoy @ANNOY_VERSION@ CONFIG EXACT) endif() +if (PluginCovfie IN_LIST Acts_COMPONENTS OR PluginDetray IN_LIST Acts_COMPONENTS OR PluginTraccc IN_LIST Acts_COMPONENTS) + find_dependency(covfie @covfie_VERSION@ CONFIG EXACT) +endif() + +if(PluginDetray IN_LIST Acts_COMPONENTS OR PluginTraccc IN_LIST Acts_COMPONENTS) + find_dependency(vecmem @vecmem_VERSION@ CONFIG EXACT) + find_dependency(algebra-plugins @algebra-plugins_VERSION@ CONFIG EXACT) + find_dependency(actsvg @actsvg_VERSION@ CONFIG EXACT) + find_dependency(detray @detray_VERSION@ CONFIG EXACT) +endif() + +if(PluginTraccc IN_LIST Acts_COMPONENTS) + find_dependency(traccc @traccc_VERSION@ CONFIG EXACT) +endif() + # dependencies that we have built ourselves but cannot be # straightforwardly handed to cmake if(NOT @ACTS_USE_SYSTEM_BOOST@) @@ -99,18 +114,6 @@ if(PluginPodio IN_LIST Acts_COMPONENTS) include(${CMAKE_CURRENT_LIST_DIR}/ActsPodioEdmTargets.cmake) endif() -if(PluginDetray IN_LIST Acts_COMPONENTS) - find_dependency(vecmem @vecmem_VERSION@ CONFIG EXACT) - find_dependency(covfie @cofvie_VERSION@ CONFIG EXACT) - find_dependency(algebra-plugins @algebra-plugins_VERSION@ CONFIG EXACT) - find_dependency(actsvg @actsvg_VERSION@ CONFIG EXACT) - find_dependency(detray @detray_VERSION@ CONFIG EXACT) -endif() - -if (PluginCovfie IN_LIST Acts_COMPONENTS) - find_dependency(covfie @covfie_VERSION@ CONFIG EXACT) -endif() - # load **all** available components. we can not just include the requested # components since there can be interdependencies between them. if(NOT Acts_FIND_QUIETLY) diff --git a/thirdparty/detray/CMakeLists.txt b/thirdparty/detray/CMakeLists.txt index aeae6304a54..4186555cb90 100644 --- a/thirdparty/detray/CMakeLists.txt +++ b/thirdparty/detray/CMakeLists.txt @@ -93,6 +93,7 @@ set(DETRAY_SETUP_DFELIBS "Do not set up Dfelibs as part of Detray" ) set(DETRAY_SVG_DISPLAY OFF CACHE BOOL "No not build the ActSVG display module") +set(DETRAY_BUILD_CUDA OFF CACHE BOOL "Turn off the detray CUDA build") #Now set up its build. FetchContent_MakeAvailable(Detray) diff --git a/thirdparty/traccc/CMakeLists.txt b/thirdparty/traccc/CMakeLists.txt index 94674839a7e..3a0d486caf2 100644 --- a/thirdparty/traccc/CMakeLists.txt +++ b/thirdparty/traccc/CMakeLists.txt @@ -67,6 +67,8 @@ set(TRACCC_BUILD_BENCHMARKS CACHE BOOL "Turn off the build of the Traccc benchmarks" ) +set(TRACCC_BUILD_IO OFF CACHE BOOL "Turn off the build of the Traccc IO code") +set(TRACCC_BUILD_CUDA OFF CACHE BOOL "Turn on/off the traccc CUDA build") # Now set up its build. FetchContent_MakeAvailable(traccc) diff --git a/thirdparty/vecmem/CMakeLists.txt b/thirdparty/vecmem/CMakeLists.txt index e0fbf07b143..729ea44ec31 100644 --- a/thirdparty/vecmem/CMakeLists.txt +++ b/thirdparty/vecmem/CMakeLists.txt @@ -28,6 +28,11 @@ set(VECMEM_BUILD_BENCHMARKING CACHE BOOL "Turn off the build of VecMem benchmarking" ) +set(VECMEM_BUILD_CUDA_LIBRARY + OFF + CACHE BOOL + "Turn on/off the vecmem CUDA build" +) # Now set up its build. FetchContent_MakeAvailable(VecMem)