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: Split particle selection in Examples #3969

Draft
wants to merge 7 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
13 changes: 4 additions & 9 deletions CI/physmon/workflows/physmon_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from acts.examples.simulation import (
addFatras,
addGeant4,
ParticleSelectorConfig,
addPythia8,
)

Expand Down Expand Up @@ -58,7 +57,7 @@
acts.PdgParticle.eElectron,
]
],
outputParticles="particles_input",
outputParticles="particles_generated",
outputVertices="vertices_input",
randomNumbers=rnd,
)
Expand All @@ -67,7 +66,7 @@
s.addWriter(
acts.examples.RootParticleWriter(
level=acts.logging.INFO,
inputParticles="particles_input",
inputParticles="particles_generated",
filePath=tp / "particles.root",
)
)
Expand All @@ -78,9 +77,7 @@
setup.field,
rnd,
enableInteractions=True,
preSelectParticles=None,
postSelectParticles=ParticleSelectorConfig(removeSecondaries=True),
inputParticles="particles_input",
inputParticles="particles_generated",
outputParticles="particles_fatras",
outputSimHits="simhits_fatras",
outputDirRoot=tp / "fatras",
Expand All @@ -92,12 +89,10 @@
setup.trackingGeometry,
setup.field,
rnd,
preSelectParticles=None,
postSelectParticles=ParticleSelectorConfig(removeSecondaries=True),
killVolume=setup.trackingGeometry.highestTrackingVolume,
killAfterTime=25 * u.ns,
killSecondaries=True,
inputParticles="particles_input",
inputParticles="particles_generated",
outputParticles="particles_geant4",
outputSimHits="simhits_geant4",
outputDirRoot=tp / "geant4",
Expand Down
17 changes: 11 additions & 6 deletions CI/physmon/workflows/physmon_trackfinding_1muon.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
EtaConfig,
PhiConfig,
ParticleConfig,
ParticleSelectorConfig,
addFatras,
addDigitization,
ParticleSelectorConfig,
addDigiParticleSelection,
)

from acts.examples.reconstruction import (
Expand Down Expand Up @@ -72,11 +73,6 @@ def run_ckf_tracking(label, seeding):
setup.field,
enableInteractions=True,
rnd=rnd,
postSelectParticles=ParticleSelectorConfig(
pt=(0.9 * u.GeV, None),
hits=(9, None),
removeNeutral=True,
),
)

addDigitization(
Expand All @@ -87,6 +83,15 @@ def run_ckf_tracking(label, seeding):
rnd=rnd,
)

addDigiParticleSelection(
s,
ParticleSelectorConfig(
pt=(0.9 * u.GeV, None),
measurements=(9, None),
removeNeutral=True,
),
)

addSeeding(
s,
setup.trackingGeometry,
Expand Down
17 changes: 11 additions & 6 deletions CI/physmon/workflows/physmon_trackfinding_4muon_50vertices.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
EtaConfig,
PhiConfig,
ParticleConfig,
ParticleSelectorConfig,
addFatras,
addDigitization,
ParticleSelectorConfig,
addDigiParticleSelection,
)
from acts.examples.reconstruction import (
addSeeding,
Expand Down Expand Up @@ -69,11 +70,6 @@
setup.trackingGeometry,
setup.field,
rnd=rnd,
postSelectParticles=ParticleSelectorConfig(
pt=(0.9 * u.GeV, None),
hits=(9, None),
removeNeutral=True,
),
)

addDigitization(
Expand All @@ -84,6 +80,15 @@
rnd=rnd,
)

addDigiParticleSelection(
s,
ParticleSelectorConfig(
pt=(0.9 * u.GeV, None),
measurements=(9, None),
removeNeutral=True,
),
)

addSeeding(
s,
setup.trackingGeometry,
Expand Down
30 changes: 20 additions & 10 deletions CI/physmon/workflows/physmon_trackfinding_ttbar_pu200.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import acts
from acts.examples.simulation import (
addPythia8,
ParticleSelectorConfig,
addGenParticleSelection,
addFatras,
addDigitization,
ParticleSelectorConfig,
addDigiParticleSelection,
)
from acts.examples.reconstruction import (
addSeeding,
Expand Down Expand Up @@ -61,20 +63,19 @@
outputDirRoot=tp,
)

addGenParticleSelection(
s,
ParticleSelectorConfig(
rho=(0.0, 24 * u.mm),
absZ=(0.0, 1.0 * u.m),
),
)

addFatras(
s,
setup.trackingGeometry,
setup.field,
rnd=rnd,
preSelectParticles=ParticleSelectorConfig(
rho=(0.0, 24 * u.mm),
absZ=(0.0, 1.0 * u.m),
),
postSelectParticles=ParticleSelectorConfig(
pt=(0.5 * u.GeV, None),
hits=(9, None),
removeNeutral=True,
),
)

addDigitization(
Expand All @@ -85,6 +86,15 @@
rnd=rnd,
)

addDigiParticleSelection(
s,
ParticleSelectorConfig(
pt=(0.5 * u.GeV, None),
measurements=(9, None),
removeNeutral=True,
),
)

addSeeding(
s,
setup.trackingGeometry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class Sequencer {
std::vector<SequenceElementWithFpeResult> m_sequenceElements;
std::unique_ptr<const Acts::Logger> m_logger;

std::unordered_map<std::string, std::string> m_whiteboardObjectAliases;
std::unordered_multimap<std::string, std::string> m_whiteboardObjectAliases;

std::unordered_map<std::string, const DataHandleBase *> m_whiteBoardState;

Expand Down
18 changes: 11 additions & 7 deletions Examples/Framework/include/ActsExamples/Framework/WhiteBoard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <stdexcept>
#include <string>
#include <string_view>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <utility>
Expand All @@ -34,9 +33,10 @@ namespace ActsExamples {
/// Its lifetime is bound to the lifetime of the white board.
class WhiteBoard {
public:
WhiteBoard(std::unique_ptr<const Acts::Logger> logger =
Acts::getDefaultLogger("WhiteBoard", Acts::Logging::INFO),
std::unordered_map<std::string, std::string> objectAliases = {});
WhiteBoard(
std::unique_ptr<const Acts::Logger> logger =
Acts::getDefaultLogger("WhiteBoard", Acts::Logging::INFO),
std::unordered_multimap<std::string, std::string> objectAliases = {});

// A WhiteBoard holds unique elements and can not be copied
WhiteBoard(const WhiteBoard& other) = delete;
Expand Down Expand Up @@ -82,7 +82,7 @@ class WhiteBoard {

std::unique_ptr<const Acts::Logger> m_logger;
std::unordered_map<std::string, std::shared_ptr<IHolder>> m_store;
std::unordered_map<std::string, std::string> m_objectAliases;
std::unordered_multimap<std::string, std::string> m_objectAliases;

const Acts::Logger& logger() const { return *m_logger; }

Expand All @@ -100,7 +100,7 @@ class WhiteBoard {

inline ActsExamples::WhiteBoard::WhiteBoard(
std::unique_ptr<const Acts::Logger> logger,
std::unordered_map<std::string, std::string> objectAliases)
std::unordered_multimap<std::string, std::string> objectAliases)
: m_logger(std::move(logger)), m_objectAliases(std::move(objectAliases)) {}

template <typename T>
Expand All @@ -111,10 +111,14 @@ inline void ActsExamples::WhiteBoard::add(const std::string& name, T&& object) {
if (m_store.contains(name)) {
throw std::invalid_argument("Object '" + name + "' already exists");
}

auto holder = std::make_shared<HolderT<T>>(std::forward<T>(object));
m_store.emplace(name, holder);
ACTS_VERBOSE("Added object '" << name << "' of type " << typeid(T).name());
if (auto it = m_objectAliases.find(name); it != m_objectAliases.end()) {

// deal with aliases
auto range = m_objectAliases.equal_range(name);
for (auto it = range.first; it != range.second; ++it) {
m_store[it->second] = holder;
ACTS_VERBOSE("Added alias object '" << it->second << "'");
}
Expand Down
29 changes: 16 additions & 13 deletions Examples/Framework/src/Framework/Sequencer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "ActsExamples/Framework/Sequencer.hpp"

#include "Acts/Plugins/FpeMonitoring/FpeMonitor.hpp"
#include "Acts/Utilities/Helpers.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/Framework/AlgorithmContext.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
Expand All @@ -26,9 +25,7 @@
#include <atomic>
#include <cctype>
#include <chrono>
#include <cstdint>
#include <cstdlib>
#include <exception>
#include <fstream>
#include <functional>
#include <iterator>
Expand Down Expand Up @@ -256,20 +253,26 @@ void Sequencer::addElement(const std::shared_ptr<SequenceElement>& element) {

void Sequencer::addWhiteboardAlias(const std::string& aliasName,
const std::string& objectName) {
auto [it, success] =
m_whiteboardObjectAliases.insert({objectName, aliasName});
if (!success) {
ACTS_INFO("Key '" << objectName << "' aliased to '" << aliasName
<< "' already set");
return;
const auto range = m_whiteboardObjectAliases.equal_range(objectName);
for (auto it = range.first; it != range.second; ++it) {
const auto& [key, value] = *it;
if (value == aliasName) {
ACTS_INFO("Key '" << objectName << "' aliased to '" << aliasName
<< "' already set");
return;
}
}

ACTS_INFO("Key '" << objectName << "' aliased to '" << aliasName << "'");
m_whiteboardObjectAliases.insert({objectName, aliasName});

if (auto oit = m_whiteBoardState.find(objectName);
oit != m_whiteBoardState.end()) {
m_whiteBoardState[aliasName] = oit->second;
auto oit = m_whiteBoardState.find(objectName);
if (oit == m_whiteBoardState.end()) {
ACTS_ERROR("Key '" << objectName << "' does not exist");
return;
}

ACTS_INFO("Key '" << objectName << "' aliased to '" << aliasName << "'");
m_whiteBoardState[aliasName] = oit->second;
}

std::vector<std::string> Sequencer::listAlgorithmNames() const {
Expand Down
6 changes: 3 additions & 3 deletions Examples/Python/python/acts/examples/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2149,9 +2149,9 @@ def addVertexFitting(
trackParameters = converter.config.outputTrackParameters

tracks = tracks if tracks is not None else ""
inputParticles = "particles_input"
inputParticles = "particles"
selectedParticles = "particles_selected"
inputTruthVertices = "vertices_input"
inputTruthVertices = "vertices_truth"

if vertexFinder == VertexFinder.Truth:
findVertices = TruthVertexFinder(
Expand Down Expand Up @@ -2245,7 +2245,7 @@ def addSingleSeedVertexFinding(
)
s.addAlgorithm(findSingleSeedVertex)

inputParticles = "particles_input"
inputParticles = "particles"
selectedParticles = "particles_selected"

if outputDirRoot is not None:
Expand Down
Loading
Loading