Skip to content
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

refactor: Replace ParticleSmearing with TrackParameterSmearing in Examples #3784

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions CI/physmon/workflows/physmon_trackfinding_1muon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from acts.examples.reconstruction import (
addSeeding,
ParticleSmearingSigmas,
TrackSmearingSigmas,
SeedFinderConfigArg,
SeedFinderOptionsArg,
SeedingAlgorithm,
Expand Down Expand Up @@ -91,15 +91,15 @@ def run_ckf_tracking(label, seeding):
s,
setup.trackingGeometry,
setup.field,
ParticleSmearingSigmas( # only used by SeedingAlgorithm.TruthSmeared
TrackSmearingSigmas( # only used by SeedingAlgorithm.TruthSmeared
# zero eveything so the CKF has a chance to find the measurements
d0=0,
d0PtA=0,
d0PtB=0,
z0=0,
z0PtA=0,
z0PtB=0,
t0=0,
loc0=0,
loc0PtA=0,
loc0PtB=0,
loc1=0,
loc1PtA=0,
loc1PtB=0,
time=0,
phi=0,
theta=0,
ptRel=0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@

#include "ActsExamples/Generators/EventGenerator.hpp"

#include "Acts/Surfaces/PerigeeSurface.hpp"
#include "ActsExamples/EventData/SimVertex.hpp"
#include "ActsExamples/EventData/Track.hpp"
#include "ActsExamples/Framework/AlgorithmContext.hpp"
#include "ActsFatras/EventData/Barcode.hpp"
#include "ActsFatras/EventData/Particle.hpp"

#include <limits>
#include <memory>
#include <optional>
#include <ostream>
#include <stdexcept>
#include <unordered_map>

ActsExamples::EventGenerator::EventGenerator(const Config& cfg,
Acts::Logging::Level lvl)
namespace ActsExamples {

EventGenerator::EventGenerator(const Config& cfg, Acts::Logging::Level lvl)
: m_cfg(cfg), m_logger(Acts::getDefaultLogger("EventGenerator", lvl)) {
if (m_cfg.outputParticles.empty()) {
throw std::invalid_argument("Missing output particles collection");
Expand All @@ -37,17 +43,15 @@ ActsExamples::EventGenerator::EventGenerator(const Config& cfg,
m_outputVertices.initialize(m_cfg.outputVertices);
}

std::string ActsExamples::EventGenerator::name() const {
std::string EventGenerator::name() const {
return "EventGenerator";
}

std::pair<std::size_t, std::size_t>
ActsExamples::EventGenerator::availableEvents() const {
std::pair<std::size_t, std::size_t> EventGenerator::availableEvents() const {
return {0u, std::numeric_limits<std::size_t>::max()};
}

ActsExamples::ProcessCode ActsExamples::EventGenerator::read(
const AlgorithmContext& ctx) {
ProcessCode EventGenerator::read(const AlgorithmContext& ctx) {
SimParticleContainer particles;
SimVertexContainer vertices;

Expand Down Expand Up @@ -120,5 +124,8 @@ ActsExamples::ProcessCode ActsExamples::EventGenerator::read(
// move generated event to the store
m_outputParticles(ctx, std::move(particles));
m_outputVertices(ctx, std::move(vertices));

return ProcessCode::SUCCESS;
}

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "ActsExamples/Framework/RandomNumbers.hpp"

#include <cstddef>
#include <functional>
#include <memory>
#include <string>
#include <utility>
Expand Down Expand Up @@ -93,8 +92,9 @@ class EventGenerator final : public ActsExamples::IReader {
struct Config {
/// Name of the output particles collection.
std::string outputParticles;
/// Name of the vertex collection.
/// Name of the output vertex collection.
std::string outputVertices;

/// List of generators that should be used to generate the event.
std::vector<Generator> generators;
/// The random number service.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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/TruthTracking/ParticleTrackParamExtractor.hpp"

#include "Acts/Surfaces/PerigeeSurface.hpp"
#include "ActsExamples/EventData/SimParticle.hpp"
#include "ActsExamples/Framework/AlgorithmContext.hpp"

#include <stdexcept>
#include <utility>

namespace ActsExamples {

ParticleTrackParamExtractor::ParticleTrackParamExtractor(
const Config& config, Acts::Logging::Level level)
: IAlgorithm("ParticleTrackParamExtractor", level), m_cfg(config) {
if (m_cfg.inputParticles.empty()) {
throw std::invalid_argument("Missing input particles collection");
}
if (m_cfg.outputTrackParameters.empty()) {
throw std::invalid_argument("Missing output track parameters collection");
}

m_inputParticles.initialize(m_cfg.inputParticles);
m_outputTrackParameters.initialize(m_cfg.outputTrackParameters);
}

ActsExamples::ProcessCode ParticleTrackParamExtractor::execute(
const AlgorithmContext& ctx) const {
const SimParticleContainer& particles = m_inputParticles(ctx);

std::unordered_map<SimBarcode, std::shared_ptr<Acts::PerigeeSurface>>
perigeeSurfaces;

for (auto&& [vtxId, vtxParticles] : groupBySecondaryVertex(particles)) {
// a group contains at least one particle by construction. assume that all
// particles within the group originate from the same position and use it
// to as the reference position for the perigee frame.
auto perigee = Acts::Surface::makeShared<Acts::PerigeeSurface>(
vtxParticles.begin()->position());
perigeeSurfaces[vtxId] = perigee;
}

// create track parameters from the particles
TrackParametersContainer trackParameters;

for (const auto& particle : particles) {
const auto vtxId = particle.particleId().vertexId();
const auto particleHypothesis = particle.hypothesis();
const auto phi = Acts::VectorHelpers::phi(particle.direction());
const auto theta = Acts::VectorHelpers::theta(particle.direction());
const auto qOverP = particle.qOverP();
const auto time = particle.time();

trackParameters.emplace_back(
perigeeSurfaces.at(vtxId),
Acts::BoundVector{0, 0, phi, theta, qOverP, time}, std::nullopt,
particleHypothesis);
}

m_outputTrackParameters(ctx, std::move(trackParameters));

return ProcessCode::SUCCESS;
}

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

#include <string>

namespace ActsExamples {
struct AlgorithmContext;

/// Extract track parameters from particles.
class ParticleTrackParamExtractor final : public IAlgorithm {
public:
struct Config {
/// The input particles collection.
std::string inputParticles;
/// The output track parameters collection.
std::string outputTrackParameters;
};

ParticleTrackParamExtractor(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<SimParticleContainer> m_inputParticles{this, "InputParticles"};
WriteDataHandle<TrackParametersContainer> m_outputTrackParameters{
this, "OutputTrackParameters"};
};

} // namespace ActsExamples
Loading
Loading