-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Conversion and chain code in traccc #3656
Open
stephenswat
wants to merge
2
commits into
acts-project:main
Choose a base branch
from
stephenswat:feat/traccc_host
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 $<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) 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 <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 |
24 changes: 24 additions & 0 deletions
24
...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,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<DigiComponentsConfig>& config); | ||
|
||
} // namespace ActsExamples::Traccc::Common::Conversion |
78 changes: 78 additions & 0 deletions
78
...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,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 <cstdint> | ||
#include <cstdlib> | ||
#include <iterator> | ||
#include <memory> | ||
#include <tuple> | ||
#include <variant> | ||
#include <vector> | ||
|
||
#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 <typename detector_t, std::forward_iterator iterator_t> | ||
inline MeasurementContainer convertTracccToActsMeasurements( | ||
const detector_t& detector, iterator_t measurements_begin, | ||
iterator_t measurements_end) { | ||
Comment on lines
+46
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: could be a range instead of |
||
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) 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 <cstdint> | ||
#include <cstdlib> | ||
#include <map> | ||
#include <vector> | ||
|
||
#include "traccc/edm/cell.hpp" | ||
#include "traccc/edm/measurement.hpp" | ||
|
||
namespace ActsExamples::Traccc::Common::Conversion { | ||
|
||
namespace { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it intentional that everything lives in an anonymous namespace here? |
||
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) 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 <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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks quite deeply nested. I think we usually try to keep things flap. But nothing critical.