-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Conversion and chain code in traccc
This PR adds conversion code as well as the code to run simple host-side chain algorithms using traccc. Co-authored-by: Stephen Nicholas Swatman <[email protected]>
- Loading branch information
1 parent
e3b33cc
commit 53d156e
Showing
43 changed files
with
2,515 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
) | ||
|
||
target_link_libraries( | ||
ActsExamplesTracccCommon | ||
PUBLIC ActsPluginDetray ActsPluginTraccc ActsExamplesFramework ActsExamplesDigitization | ||
) | ||
|
||
install( | ||
TARGETS ActsExamplesTracccCommon | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
) |
29 changes: 29 additions & 0 deletions
29
...les/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/CellMapConversion.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2024 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "Acts/Geometry/GeometryIdentifier.hpp" | ||
#include "ActsExamples/EventData/Cluster.hpp" | ||
|
||
#include <cstdint> | ||
#include <cstdlib> | ||
#include <map> | ||
#include <vector> | ||
|
||
#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<Acts::GeometryIdentifier, std::vector<traccc::cell>> tracccCellsMap( | ||
const std::map<Acts::GeometryIdentifier, std::vector<Cluster::Cell>>& map); | ||
|
||
} // namespace ActsExamples::Traccc::Common::Conversion |
29 changes: 29 additions & 0 deletions
29
...lgorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/DigitizationConversion.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2023 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
// Acts include(s) | ||
#include "Acts/Geometry/GeometryHierarchyMap.hpp" | ||
|
||
// Acts plugin include(s) | ||
#include "Acts/Plugins/Traccc/DigitizationConfig.hpp" | ||
|
||
// Acts Examples include(s) | ||
#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<DigiComponentsConfig>& config); | ||
|
||
} // namespace ActsExamples::Traccc::Common::Conversion |
87 changes: 87 additions & 0 deletions
87
...Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/MeasurementConversion.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2023 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
// Plugin include(s) | ||
#include "Acts/Plugins/Traccc/Detail/AlgebraConversion.hpp" | ||
|
||
// Acts include(s) | ||
#include "Acts/Definitions/Algebra.hpp" | ||
#include "Acts/Definitions/TrackParametrization.hpp" | ||
#include "Acts/EventData/SourceLink.hpp" | ||
#include "Acts/Geometry/GeometryIdentifier.hpp" | ||
#include "ActsExamples/EventData/Measurement.hpp" | ||
|
||
// Acts Examples include(s) | ||
#include "ActsExamples/EventData/IndexSourceLink.hpp" | ||
|
||
// Detray include(s) | ||
#include "detray/core/detector.hpp" | ||
#include "detray/tracks/bound_track_parameters.hpp" | ||
|
||
// Traccc include(s) | ||
#include "traccc/definitions/qualifiers.hpp" | ||
#include "traccc/definitions/track_parametrization.hpp" | ||
#include "traccc/edm/measurement.hpp" | ||
#include "traccc/edm/track_state.hpp" | ||
|
||
// System include(s) | ||
#include <cstdint> | ||
#include <cstdlib> | ||
#include <iterator> | ||
#include <memory> | ||
#include <tuple> | ||
#include <variant> | ||
#include <vector> | ||
|
||
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 <typename detector_t, std::forward_iterator iterator_t> | ||
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<Index>(measurementContainer.size()); | ||
IndexSourceLink idxSourceLink{moduleGeoId, measurementIdx}; | ||
|
||
Eigen::Matrix<MeasurementContainer::VariableProxy::SubspaceIndex, | ||
Eigen::Dynamic, 1> | ||
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::ActsScalar, 2>( | ||
Acts::TracccPlugin::detail::toActsVector<2>((*i).variance)) | ||
.toDenseMatrix()); | ||
} | ||
|
||
return measurementContainer; | ||
} | ||
|
||
} // namespace ActsExamples::Traccc::Common::Conversion |
133 changes: 133 additions & 0 deletions
133
Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/MeasurementMap.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2024 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "Acts/Geometry/GeometryIdentifier.hpp" | ||
#include "ActsExamples/EventData/Cluster.hpp" | ||
#include "ActsExamples/EventData/IndexSourceLink.hpp" | ||
#include "ActsExamples/EventData/Measurement.hpp" | ||
|
||
#include <cstdint> | ||
#include <cstdlib> | ||
#include <map> | ||
#include <vector> | ||
|
||
#include "traccc/edm/cell.hpp" | ||
#include "traccc/edm/measurement.hpp" | ||
|
||
namespace ActsExamples::Traccc::Common::Conversion { | ||
|
||
namespace { | ||
template <typename C1, typename C2, typename M1GeoIdProj, typename M2GeoIdProj, | ||
typename M1LocalProj, typename M2LocalProj> | ||
std::map<std::size_t, std::size_t> makeGenericMeasurementIndexMap( | ||
const C1& fromMeasurements, const C2& toMeasurements, | ||
M1GeoIdProj&& fromMeasurementGeoIdProjector, | ||
M2GeoIdProj&& toMeasurementGeoIdProjector, | ||
M1LocalProj&& fromMeasurementLocalProjector, | ||
M2LocalProj&& toMeasurementLocalProjector, Acts::ActsScalar tol = 0.001) { | ||
std::map<std::size_t, std::size_t> outputMap; | ||
|
||
std::map<std::size_t, std::vector<std::size_t>> 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<std::size_t>& 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 <typename detector_t> | ||
std::map<std::size_t, std::size_t> makeTracccToActsMeasurementIndexMap( | ||
const std::pmr::vector<traccc::measurement>& 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<ActsExamples::IndexSourceLink>() | ||
.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 <typename detector_t> | ||
std::map<std::size_t, std::size_t> makeActsToTracccMeasurementIndexMap( | ||
const ActsExamples::MeasurementContainer& actsMeasurements, | ||
const std::pmr::vector<traccc::measurement>& tracccMeasurements, | ||
const detector_t& detector) { | ||
return makeGenericMeasurementIndexMap( | ||
actsMeasurements, tracccMeasurements, | ||
[](const ActsExamples::MeasurementContainer::ConstVariableProxy& i) { | ||
return i.sourceLink() | ||
.template get<ActsExamples::IndexSourceLink>() | ||
.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 |
47 changes: 47 additions & 0 deletions
47
Examples/Algorithms/Traccc/Common/include/ActsExamples/Traccc/Conversion/SeedConversion.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2023 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "Acts/EventData/Seed.hpp" | ||
#include "ActsExamples/EventData/SimSeed.hpp" | ||
#include "ActsExamples/EventData/SimSpacePoint.hpp" | ||
|
||
#include <cstdint> | ||
#include <cstdlib> | ||
#include <memory_resource> | ||
|
||
#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<traccc::seed, std::pmr::polymorphic_allocator<traccc::seed>>& | ||
seeds, | ||
const std::map<std::size_t, std::size_t>& tracccToActsSpacepointIndexMap, | ||
const std::vector<SimSpacePoint>& 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<traccc::seed, std::pmr::polymorphic_allocator<traccc::seed>> | ||
convertActsToTracccSeeds( | ||
const SimSeedContainer& seeds, | ||
const SimSpacePointContainer& actsSpacepoints, | ||
const std::map<std::size_t, std::size_t>& actsToTracccSpacepointIndexMap); | ||
|
||
} // namespace ActsExamples::Traccc::Common::Conversion |
Oops, something went wrong.