Skip to content

Commit

Permalink
refactor: Integrate source link container into measurements container…
Browse files Browse the repository at this point in the history
… in Examples (acts-project#3732)

The source link container seems not to carry any additional information compared to the measurement container. The only important difference between them is that the source link container is sorted by geometry. I integrated a sorted container into the measurement container, even though this might not be strictly necessary it plays nicer with the existing functionality of accessing such a sorted container.
  • Loading branch information
andiwand authored and Rosie-Hasan committed Nov 13, 2024
1 parent b2890fd commit 2dc1f8b
Show file tree
Hide file tree
Showing 48 changed files with 215 additions and 346 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "Acts/Geometry/GeometryHierarchyMap.hpp"
#include "Acts/TrackFitting/KalmanFitter.hpp"
#include "ActsAlignment/Kernel/Alignment.hpp"
#include "ActsExamples/EventData/IndexSourceLink.hpp"
#include "ActsExamples/EventData/Measurement.hpp"
#include "ActsExamples/EventData/ProtoTrack.hpp"
#include "ActsExamples/EventData/Track.hpp"
Expand Down Expand Up @@ -88,8 +87,6 @@ class AlignmentAlgorithm final : public IAlgorithm {
struct Config {
/// Input measurements collection.
std::string inputMeasurements;
/// Input source links collection.
std::string inputSourceLinks;
/// Input proto tracks collection, i.e. groups of hit indices.
std::string inputProtoTracks;
/// Input initial track parameter estimates for for each proto track.
Expand Down Expand Up @@ -133,8 +130,6 @@ class AlignmentAlgorithm final : public IAlgorithm {

ReadDataHandle<MeasurementContainer> m_inputMeasurements{this,
"InputMeasurements"};
ReadDataHandle<IndexSourceLinkContainer> m_inputSourceLinks{
this, "InputSourceLinks"};
ReadDataHandle<TrackParametersContainer> m_inputInitialTrackParameters{
this, "InputInitialTrackParameters"};
ReadDataHandle<ProtoTrackContainer> m_inputProtoTracks{this,
Expand Down
19 changes: 6 additions & 13 deletions Examples/Algorithms/Alignment/src/AlignmentAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Acts/Surfaces/PerigeeSurface.hpp"
#include "Acts/TrackFitting/GainMatrixSmoother.hpp"
#include "Acts/TrackFitting/GainMatrixUpdater.hpp"
#include "ActsExamples/EventData/IndexSourceLink.hpp"
#include "ActsExamples/EventData/MeasurementCalibration.hpp"
#include "ActsExamples/EventData/ProtoTrack.hpp"
#include "ActsExamples/EventData/Trajectories.hpp"
Expand All @@ -23,9 +24,6 @@ ActsExamples::AlignmentAlgorithm::AlignmentAlgorithm(Config cfg,
if (m_cfg.inputMeasurements.empty()) {
throw std::invalid_argument("Missing input measurement collection");
}
if (m_cfg.inputSourceLinks.empty()) {
throw std::invalid_argument("Missing input source links collection");
}
if (m_cfg.inputProtoTracks.empty()) {
throw std::invalid_argument("Missing input proto tracks collection");
}
Expand All @@ -39,7 +37,6 @@ ActsExamples::AlignmentAlgorithm::AlignmentAlgorithm(Config cfg,
}

m_inputMeasurements.initialize(m_cfg.inputMeasurements);
m_inputSourceLinks.initialize(m_cfg.inputSourceLinks);
m_inputProtoTracks.initialize(m_cfg.inputProtoTracks);
m_inputInitialTrackParameters.initialize(m_cfg.inputInitialTrackParameters);
m_outputAlignmentParameters.initialize(m_cfg.outputAlignmentParameters);
Expand All @@ -49,7 +46,6 @@ ActsExamples::ProcessCode ActsExamples::AlignmentAlgorithm::execute(
const ActsExamples::AlgorithmContext& ctx) const {
// Read input data
const auto& measurements = m_inputMeasurements(ctx);
const auto& sourceLinks = m_inputSourceLinks(ctx);
const auto& protoTracks = m_inputProtoTracks(ctx);
const auto& initialParameters = m_inputInitialTrackParameters(ctx);

Expand Down Expand Up @@ -79,14 +75,11 @@ ActsExamples::ProcessCode ActsExamples::AlignmentAlgorithm::execute(
trackSourceLinks.reserve(protoTrack.size());

// Fill the source links via their indices from the container
for (auto hitIndex : protoTrack) {
auto sourceLink = sourceLinks.nth(hitIndex);
if (sourceLink == sourceLinks.end()) {
ACTS_FATAL("Proto track " << itrack << " contains invalid hit index"
<< hitIndex);
return ProcessCode::ABORT;
}
trackSourceLinks.push_back(*sourceLink);
for (auto measIndex : protoTrack) {
const ConstVariableBoundMeasurementProxy measurement =
measurements.getMeasurement(measIndex);
IndexSourceLink sourceLink(measurement.geometryId(), measIndex);
trackSourceLinks.push_back(sourceLink);
}
sourceLinkTrackContainer.push_back(trackSourceLinks);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "ActsExamples/Digitization/SmearingConfig.hpp"
#include "ActsExamples/EventData/Cluster.hpp"
#include "ActsExamples/EventData/Index.hpp"
#include "ActsExamples/EventData/IndexSourceLink.hpp"
#include "ActsExamples/EventData/Measurement.hpp"
#include "ActsExamples/EventData/SimHit.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
Expand Down Expand Up @@ -102,8 +101,6 @@ class DigitizationAlgorithm final : public IAlgorithm {
ReadDataHandle<SimHitContainer> m_simContainerReadHandle{this,
"SimHitContainer"};

WriteDataHandle<IndexSourceLinkContainer> m_sourceLinkWriteHandle{
this, "SourceLinks"};
WriteDataHandle<MeasurementContainer> m_measurementWriteHandle{
this, "Measurements"};
WriteDataHandle<CellsMap> m_cellsWriteHandle{this, "Cells"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ class DigitizationConfig {

/// Input collection of simulated hits.
std::string inputSimHits = "simhits";
/// Output source links collection.
std::string outputSourceLinks = "sourcelinks";
/// Output measurements collection.
std::string outputMeasurements = "measurements";
/// Output cells map (geoID -> collection of cells).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "ActsExamples/EventData/Cluster.hpp"
#include "ActsExamples/EventData/IndexSourceLink.hpp"
#include "ActsExamples/EventData/Measurement.hpp"

#include <array>
Expand All @@ -20,7 +20,6 @@
#include <vector>

namespace ActsExamples {
class IndexSourceLink;

/// Struct to identify digitized parameters
///
Expand All @@ -35,15 +34,16 @@ struct DigitizedParameters {

/// Helper method for created a measurement from digitized parameters
///
/// @param container The measurement container to insert into
/// @param geometryId The geometry ID of the measurement surface
/// @param dParams The digitized parameters of variable size
/// @param isl The indexed source link for the measurement
///
/// To be used also by the e I/O system
///
/// @return the measurement proxy
ActsExamples::VariableBoundMeasurementProxy createMeasurement(
MeasurementContainer& container, const DigitizedParameters& dParams,
const IndexSourceLink& isl) noexcept(false);
MeasurementContainer& container, Acts::GeometryIdentifier geometryId,
const DigitizedParameters& dParams) noexcept(false);

/// Construct the constituents of a measurement.
///
Expand Down
17 changes: 1 addition & 16 deletions Examples/Algorithms/Digitization/src/DigitizationAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "ActsExamples/Digitization/ModuleClusters.hpp"
#include "ActsExamples/EventData/GeometryContainers.hpp"
#include "ActsExamples/EventData/Index.hpp"
#include "ActsExamples/EventData/IndexSourceLink.hpp"
#include "ActsExamples/EventData/SimHit.hpp"
#include "ActsExamples/Framework/AlgorithmContext.hpp"
#include "ActsExamples/Utilities/GroupBy.hpp"
Expand Down Expand Up @@ -55,9 +54,6 @@ ActsExamples::DigitizationAlgorithm::DigitizationAlgorithm(
}

if (m_cfg.doClusterization) {
if (m_cfg.outputSourceLinks.empty()) {
throw std::invalid_argument("Missing source links output collection");
}
if (m_cfg.outputMeasurements.empty()) {
throw std::invalid_argument("Missing measurements output collection");
}
Expand All @@ -73,7 +69,6 @@ ActsExamples::DigitizationAlgorithm::DigitizationAlgorithm(
"Missing hit-to-simulated-hits map output collection");
}

m_sourceLinkWriteHandle.initialize(m_cfg.outputSourceLinks);
m_measurementWriteHandle.initialize(m_cfg.outputMeasurements);
m_clusterWriteHandle.initialize(m_cfg.outputClusters);
m_measurementParticlesMapWriteHandle.initialize(
Expand Down Expand Up @@ -152,12 +147,10 @@ ActsExamples::ProcessCode ActsExamples::DigitizationAlgorithm::execute(

// Prepare output containers
// need list here for stable addresses
IndexSourceLinkContainer sourceLinks;
MeasurementContainer measurements;
ClusterContainer clusters;
IndexMultimap<ActsFatras::Barcode> measurementParticlesMap;
IndexMultimap<Index> measurementSimHitsMap;
sourceLinks.reserve(simHits.size());
measurements.reserve(simHits.size());
measurementParticlesMap.reserve(simHits.size());
measurementSimHitsMap.reserve(simHits.size());
Expand Down Expand Up @@ -292,15 +285,8 @@ ActsExamples::ProcessCode ActsExamples::DigitizationAlgorithm::execute(
// The measurement container is unordered and the index under
// which the measurement will be stored is known before adding it.
Index measurementIdx = measurements.size();
IndexSourceLink sourceLink{moduleGeoId, measurementIdx};

// Add to output containers:
// index map and source link container are geometry-ordered.
// since the input is also geometry-ordered, new items can
// be added at the end.
sourceLinks.insert(sourceLinks.end(), sourceLink);

createMeasurement(measurements, dParameters, sourceLink);
createMeasurement(measurements, moduleGeoId, dParameters);
clusters.emplace_back(std::move(dParameters.cluster));
// this digitization does hit merging so there can be more than
// one mapping entry for each digitized hit.
Expand Down Expand Up @@ -328,7 +314,6 @@ ActsExamples::ProcessCode ActsExamples::DigitizationAlgorithm::execute(
}

if (m_cfg.doClusterization) {
m_sourceLinkWriteHandle(ctx, std::move(sourceLinks));
m_measurementWriteHandle(ctx, std::move(measurements));
m_clusterWriteHandle(ctx, std::move(clusters));
m_measurementParticlesMapWriteHandle(ctx,
Expand Down
9 changes: 4 additions & 5 deletions Examples/Algorithms/Digitization/src/MeasurementCreation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

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

Expand All @@ -18,10 +19,8 @@
#include <utility>

ActsExamples::VariableBoundMeasurementProxy ActsExamples::createMeasurement(
MeasurementContainer& container, const DigitizedParameters& dParams,
const IndexSourceLink& isl) {
Acts::SourceLink sl{isl};

MeasurementContainer& container, Acts::GeometryIdentifier geometryId,
const DigitizedParameters& dParams) {
if (dParams.indices.size() > 4u) {
std::string errorMsg = "Invalid/mismatching measurement dimension: " +
std::to_string(dParams.indices.size());
Expand All @@ -31,6 +30,6 @@ ActsExamples::VariableBoundMeasurementProxy ActsExamples::createMeasurement(
return Acts::visit_measurement(
dParams.indices.size(), [&](auto dim) -> VariableBoundMeasurementProxy {
auto [indices, par, cov] = measurementConstituents<dim>(dParams);
return container.emplaceMeasurement<dim>(sl, indices, par, cov);
return container.emplaceMeasurement<dim>(geometryId, indices, par, cov);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class GbtsSeedingAlgorithm final : public IAlgorithm {

std::vector<Acts::GeometryIdentifier> geometrySelection;

std::string inputSourceLinks;

std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry;

std::map<std::pair<int, int>, std::pair<int, int>> ActsGbtsMap;
Expand Down Expand Up @@ -88,9 +86,6 @@ class GbtsSeedingAlgorithm final : public IAlgorithm {

WriteDataHandle<SimSeedContainer> m_outputSeeds{this, "OutputSeeds"};

ReadDataHandle<IndexSourceLinkContainer> m_inputSourceLinks{
this, "InputSourceLinks"};

ReadDataHandle<ClusterContainer> m_inputClusters{this, "InputClusters"};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
#include "Acts/Utilities/Logger.hpp"
#include "Acts/Utilities/Result.hpp"
#include "ActsExamples/EventData/Index.hpp"
#include "ActsExamples/EventData/IndexSourceLink.hpp"
#include "ActsExamples/EventData/Measurement.hpp"
#include "ActsExamples/EventData/ProtoTrack.hpp"
#include "ActsExamples/EventData/SimSpacePoint.hpp"
Expand Down Expand Up @@ -168,8 +167,6 @@ class HoughTransformSeeder final : public IAlgorithm {
std::string outputSeeds;
/// Output hough track collection.
std::string outputProtoTracks;
/// Input source links collection.
std::string inputSourceLinks;
/// Tracking geometry required to access global-to-local transforms.
std::shared_ptr<const Acts::TrackingGeometry> trackingGeometry;
/// For which part of the detector geometry should space points be created.
Expand Down Expand Up @@ -281,9 +278,6 @@ class HoughTransformSeeder final : public IAlgorithm {
ReadDataHandle<MeasurementContainer> m_inputMeasurements{this,
"InputMeasurements"};

ReadDataHandle<IndexSourceLinkContainer> m_inputSourceLinks{
this, "InputSourceLinks"};

////////////////////////////////////////////////////////////////////////
/// Convenience

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "Acts/Geometry/GeometryIdentifier.hpp"
#include "Acts/SpacePointFormation/SpacePointBuilder.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/EventData/IndexSourceLink.hpp"
#include "ActsExamples/EventData/Measurement.hpp"
#include "ActsExamples/EventData/SimSpacePoint.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
Expand Down Expand Up @@ -46,8 +45,6 @@ struct AlgorithmContext;
class SpacePointMaker final : public IAlgorithm {
public:
struct Config {
/// Input source links collection.
std::string inputSourceLinks;
/// Input measurements collection.
std::string inputMeasurements;
/// Output space points collection.
Expand Down Expand Up @@ -86,9 +83,6 @@ class SpacePointMaker final : public IAlgorithm {

Acts::SpacePointBuilder<SimSpacePoint> m_spacePointBuilder;

ReadDataHandle<IndexSourceLinkContainer> m_inputSourceLinks{
this, "InputSourceLinks"};

ReadDataHandle<MeasurementContainer> m_inputMeasurements{this,
"InputMeasurements"};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ class TrackFindingAlgorithm final : public IAlgorithm {
struct Config {
/// Input measurements collection.
std::string inputMeasurements;
/// Input source links collection.
std::string inputSourceLinks;
/// Input initial track parameter estimates for for each proto track.
std::string inputInitialTrackParameters;
/// Input seeds. These are optional and allow for seed deduplication.
Expand Down Expand Up @@ -156,9 +154,8 @@ class TrackFindingAlgorithm final : public IAlgorithm {
const Config& config() const { return m_cfg; }

private:
template <typename source_link_accessor_container_t>
void computeSharedHits(const source_link_accessor_container_t& sourceLinks,
TrackContainer& tracks) const;
void computeSharedHits(TrackContainer& tracks,
const MeasurementContainer& measurements) const;

ActsExamples::ProcessCode finalize() override;

Expand All @@ -168,8 +165,6 @@ class TrackFindingAlgorithm final : public IAlgorithm {

ReadDataHandle<MeasurementContainer> m_inputMeasurements{this,
"InputMeasurements"};
ReadDataHandle<IndexSourceLinkContainer> m_inputSourceLinks{
this, "InputSourceLinks"};
ReadDataHandle<TrackParametersContainer> m_inputInitialTrackParameters{
this, "InputInitialTrackParameters"};
ReadDataHandle<SimSeedContainer> m_inputSeeds{this, "InputSeeds"};
Expand All @@ -192,56 +187,4 @@ class TrackFindingAlgorithm final : public IAlgorithm {
}};
};

// TODO this is somewhat duplicated in AmbiguityResolutionAlgorithm.cpp
// TODO we should make a common implementation in the core at some point
template <typename source_link_accessor_container_t>
void TrackFindingAlgorithm::computeSharedHits(
const source_link_accessor_container_t& sourceLinks,
TrackContainer& tracks) const {
// Compute shared hits from all the reconstructed tracks
// Compute nSharedhits and Update ckf results
// hit index -> list of multi traj indexes [traj, meas]

std::vector<std::size_t> firstTrackOnTheHit(
sourceLinks.size(), std::numeric_limits<std::size_t>::max());
std::vector<std::size_t> firstStateOnTheHit(
sourceLinks.size(), std::numeric_limits<std::size_t>::max());

for (auto track : tracks) {
for (auto state : track.trackStatesReversed()) {
if (!state.typeFlags().test(Acts::TrackStateFlag::MeasurementFlag)) {
continue;
}

std::size_t hitIndex = state.getUncalibratedSourceLink()
.template get<IndexSourceLink>()
.index();

// Check if hit not already used
if (firstTrackOnTheHit.at(hitIndex) ==
std::numeric_limits<std::size_t>::max()) {
firstTrackOnTheHit.at(hitIndex) = track.index();
firstStateOnTheHit.at(hitIndex) = state.index();
continue;
}

// if already used, control if first track state has been marked
// as shared
int indexFirstTrack = firstTrackOnTheHit.at(hitIndex);
int indexFirstState = firstStateOnTheHit.at(hitIndex);

auto firstState = tracks.getTrack(indexFirstTrack)
.container()
.trackStateContainer()
.getTrackState(indexFirstState);
if (!firstState.typeFlags().test(Acts::TrackStateFlag::SharedHitFlag)) {
firstState.typeFlags().set(Acts::TrackStateFlag::SharedHitFlag);
}

// Decorate this track state
state.typeFlags().set(Acts::TrackStateFlag::SharedHitFlag);
}
}
}

} // namespace ActsExamples
Loading

0 comments on commit 2dc1f8b

Please sign in to comment.