Skip to content

Commit

Permalink
Merge branch 'main' into fix-rpath
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand authored Mar 19, 2024
2 parents 214e055 + 69f7217 commit 4f044b5
Show file tree
Hide file tree
Showing 56 changed files with 1,344 additions and 911 deletions.
Binary file not shown.
Binary file not shown.
Binary file modified CI/physmon/reference/performance_amvf_orthogonal_hist.root
Binary file not shown.
Binary file modified CI/physmon/reference/performance_amvf_seeded_hist.root
Binary file not shown.
Binary file modified CI/physmon/reference/performance_amvf_truth_estimated_hist.root
Binary file not shown.
Binary file modified CI/physmon/reference/performance_amvf_truth_smeared_hist.root
Binary file not shown.
Binary file modified CI/physmon/reference/performance_amvf_ttbar_hist.root
Binary file not shown.
Binary file modified CI/physmon/reference/performance_ckf_ttbar.root
Binary file not shown.
Binary file modified CI/physmon/reference/performance_ivf_orthogonal_hist.root
Binary file not shown.
Binary file modified CI/physmon/reference/performance_ivf_seeded_hist.root
Binary file not shown.
Binary file modified CI/physmon/reference/performance_ivf_truth_estimated_hist.root
Binary file not shown.
Binary file modified CI/physmon/reference/performance_ivf_truth_smeared_hist.root
Binary file not shown.
Binary file modified CI/physmon/reference/tracksummary_ckf_ttbar_hist.root
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#include "Acts/Digitization/PlanarModuleCluster.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/EventData/GeometryContainers.hpp"
#include "ActsExamples/EventData/Index.hpp"
#include "ActsExamples/EventData/SimParticle.hpp"
#include "ActsExamples/EventData/SimHit.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
#include "ActsExamples/Framework/IAlgorithm.hpp"
#include "ActsExamples/Framework/ProcessCode.hpp"
Expand All @@ -35,7 +34,6 @@ struct AlgorithmContext;
class HitsPrinter : public IAlgorithm {
public:
using Clusters = ActsExamples::GeometryIdMultimap<Acts::PlanarModuleCluster>;
using HitParticlesMap = ActsExamples::IndexMultimap<ActsFatras::Barcode>;
using HitIds = std::vector<std::size_t>;

struct Config {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ using TrackHitList = std::map<const double, const Index>;

class SurfaceSortingAlgorithm final : public IAlgorithm {
public:
using HitSimHitsMap = IndexMultimap<Index>;

struct Config {
/// Input proto track collection
std::string inputProtoTracks;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// 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/.

#include "ActsExamples/TruthTracking/ProtoTrackTruthMatcher.hpp"

#include "Acts/Utilities/Enumerate.hpp"
#include "ActsExamples/EventData/SimParticle.hpp"
#include "ActsExamples/Validation/TrackClassification.hpp"

#include <map>
#include <optional>
#include <stdexcept>
#include <vector>

namespace ActsExamples {

ProtoTrackTruthMatcher::ProtoTrackTruthMatcher(const Config& config,
Acts::Logging::Level level)
: IAlgorithm("ProtoTrackTruthMatcher", level), m_cfg(config) {
if (m_cfg.inputProtoTracks.empty()) {
throw std::invalid_argument("Missing input proto tracks");
}
if (m_cfg.inputParticles.empty()) {
throw std::invalid_argument("Missing input particles");
}
if (m_cfg.inputMeasurementParticlesMap.empty()) {
throw std::invalid_argument("Missing input measurement particles map");
}
if (m_cfg.outputProtoTrackParticleMatching.empty()) {
throw std::invalid_argument(
"Missing output proto track particles matching");
}
if (m_cfg.outputParticleProtoTrackMatching.empty()) {
throw std::invalid_argument("Missing output particle proto track matching");
}

m_inputProtoTracks.initialize(m_cfg.inputProtoTracks);
m_inputParticles.initialize(m_cfg.inputParticles);
m_inputMeasurementParticlesMap.initialize(m_cfg.inputMeasurementParticlesMap);
m_outputProtoTrackParticleMatching.initialize(
m_cfg.outputProtoTrackParticleMatching);
m_outputParticleProtoTrackMatching.initialize(
m_cfg.outputParticleProtoTrackMatching);
}

ActsExamples::ProcessCode ProtoTrackTruthMatcher::execute(
const ActsExamples::AlgorithmContext& ctx) const {
// Read input proto tracks
const auto& protoTracks = m_inputProtoTracks(ctx);

// Read truth input collections
const auto& particles = m_inputParticles(ctx);
const auto& hitParticlesMap = m_inputMeasurementParticlesMap(ctx);

ProtoTrackParticleMatching protoTrackParticleMatching;
ParticleProtoTrackMatching particleProtoTrackMatching;

// TODO this may be computed in a separate algorithm
// TODO can we wire this through?
std::map<SimBarcode, std::size_t> particleTruthHitCount;
for (const auto& [_, pid] : hitParticlesMap) {
particleTruthHitCount[pid]++;
}

// For each particle within a track, how many hits did it contribute
std::vector<ParticleHitCount> particleHitCounts;

for (const auto& [index, protoTrack] : Acts::enumerate(protoTracks)) {
// Get the majority truth particle to this track
identifyContributingParticles(hitParticlesMap, protoTrack,
particleHitCounts);
if (particleHitCounts.empty()) {
ACTS_DEBUG("No truth particle associated with this proto track "
<< index);
continue;
}

// Get the majority particleId and majority particle counts
// Note that the majority particle might not be in the truth seeds
// collection
ActsFatras::Barcode majorityParticleId =
particleHitCounts.front().particleId;
std::size_t nMajorityHits = particleHitCounts.front().hitCount;

if (particles.find(majorityParticleId) == particles.end()) {
ACTS_DEBUG(
"The majority particle is not in the input particle collection, "
"majorityParticleId = "
<< majorityParticleId);
continue;
}

// Check if the trajectory is matched with truth.
// If not, it will be classified as 'fake'
const bool recoMatched =
static_cast<double>(nMajorityHits) / protoTrack.size() >=
m_cfg.matchingRatio;
const bool truthMatched =
static_cast<double>(nMajorityHits) /
particleTruthHitCount.at(majorityParticleId) >=
m_cfg.matchingRatio;

if ((!m_cfg.doubleMatching && recoMatched) ||
(m_cfg.doubleMatching && recoMatched && truthMatched)) {
auto& trackParticleMatch = protoTrackParticleMatching[index] = {
TrackMatchClassification::Matched, majorityParticleId,
particleHitCounts};

auto& particleTrackMatch = particleProtoTrackMatching[majorityParticleId];
if (!particleTrackMatch.track) {
particleTrackMatch.track = index;
} else {
// we already have a track associated with this particle and have to
// resolve the ambiguity.
// we will use the track with more hits and smaller chi2
const auto& otherProtoTrack =
protoTracks.at(particleTrackMatch.track.value());
if (otherProtoTrack.size() < protoTrack.size()) {
protoTrackParticleMatching[particleTrackMatch.track.value()]
.classification = TrackMatchClassification::Duplicate;
particleTrackMatch.track = index;
} else {
trackParticleMatch.classification =
TrackMatchClassification::Duplicate;
}

++particleTrackMatch.duplicates;
}
} else {
protoTrackParticleMatching[index] = {TrackMatchClassification::Fake,
std::nullopt, particleHitCounts};

auto& particleTrackMatch = particleProtoTrackMatching[majorityParticleId];
++particleTrackMatch.fakes;
}
}

m_outputProtoTrackParticleMatching(ctx,
std::move(protoTrackParticleMatching));
m_outputParticleProtoTrackMatching(ctx,
std::move(particleProtoTrackMatching));

return ProcessCode::SUCCESS;
}

} // namespace ActsExamples
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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/Utilities/Logger.hpp"
#include "ActsExamples/EventData/ProtoTrack.hpp"
#include "ActsExamples/EventData/SimHit.hpp"
#include "ActsExamples/EventData/SimParticle.hpp"
#include "ActsExamples/EventData/TruthMatching.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
#include "ActsExamples/Framework/IAlgorithm.hpp"
#include "ActsExamples/Framework/ProcessCode.hpp"

#include <string>

namespace ActsExamples {

struct AlgorithmContext;

/// Matches proto track to truth particles and vice versa
class ProtoTrackTruthMatcher final : public IAlgorithm {
public:
struct Config {
/// Input proto tracks collection
std::string inputProtoTracks;
/// Input particles collection.
std::string inputParticles;
/// Input hit-particles map collection.
std::string inputMeasurementParticlesMap;
/// Output proto track-particle matching.
std::string outputProtoTrackParticleMatching;
/// Output particle-proto track matching.
std::string outputParticleProtoTrackMatching;

/// Matching ratio for track to particle matching
double matchingRatio = 0.5;
/// Whether to use double matching (track to particle and particle to track)
bool doubleMatching = false;
};

ProtoTrackTruthMatcher(const Config& config, Acts::Logging::Level level);

ProcessCode execute(const AlgorithmContext& ctx) const final;

/// Get readonly access to the config parameters
const Config& config() const { return m_cfg; }

private:
Config m_cfg;

ReadDataHandle<ProtoTrackContainer> m_inputProtoTracks{this,
"InputProtoTracks"};
ReadDataHandle<SimParticleContainer> m_inputParticles{this, "InputParticles"};
ReadDataHandle<HitParticlesMap> m_inputMeasurementParticlesMap{
this, "InputMeasurementParticlesMap"};
WriteDataHandle<TrackParticleMatching> m_outputProtoTrackParticleMatching{
this, "OutputProtoTrackParticleMatching"};
WriteDataHandle<ParticleTrackMatching> m_outputParticleProtoTrackMatching{
this, "OutputParticleProtoTrackMatching"};
};

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,14 @@
#include "ActsExamples/TruthTracking/TrackModifier.hpp"

#include "Acts/Definitions/TrackParametrization.hpp"
#include "Acts/EventData/MultiTrajectory.hpp"
#include "Acts/EventData/TrackParameters.hpp"
#include "ActsExamples/EventData/Track.hpp"
#include "ActsExamples/EventData/Trajectories.hpp"

#include <algorithm>
#include <cstdint>
#include <stdexcept>
#include <utility>
#include <vector>

namespace ActsExamples {
struct AlgorithmContext;
} // namespace ActsExamples

ActsExamples::TrackModifier::TrackModifier(const Config& config,
Acts::Logging::Level level)
TrackModifier::TrackModifier(const Config& config, Acts::Logging::Level level)
: IAlgorithm("TrackModifier", level), m_cfg(config) {
if (m_cfg.inputTracks.empty()) {
throw std::invalid_argument("Missing input tracks");
Expand All @@ -38,7 +29,7 @@ ActsExamples::TrackModifier::TrackModifier(const Config& config,
m_outputTracks.initialize(m_cfg.outputTracks);
}

ActsExamples::ProcessCode ActsExamples::TrackModifier::execute(
ProcessCode TrackModifier::execute(
const ActsExamples::AlgorithmContext& ctx) const {
auto modifyTrack = [this](auto& trk) {
{
Expand Down Expand Up @@ -90,3 +81,5 @@ ActsExamples::ProcessCode ActsExamples::TrackModifier::execute(

return ProcessCode::SUCCESS;
}

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@

#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/EventData/Track.hpp"
#include "ActsExamples/EventData/Trajectories.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
#include "ActsExamples/Framework/IAlgorithm.hpp"
#include "ActsExamples/Framework/ProcessCode.hpp"

#include <limits>
#include <string>

namespace ActsExamples {
struct AlgorithmContext;

/// Select tracks by applying some selection cuts.
/// Modify tracks based on configuration.
class TrackModifier final : public IAlgorithm {
public:
struct Config {
Expand Down Expand Up @@ -49,7 +47,6 @@ class TrackModifier final : public IAlgorithm {
Config m_cfg;

ReadDataHandle<ConstTrackContainer> m_inputTracks{this, "InputTracks"};

WriteDataHandle<ConstTrackContainer> m_outputTracks{this, "OutputTracks"};
};

Expand Down
Loading

0 comments on commit 4f044b5

Please sign in to comment.