Skip to content

Commit

Permalink
Merge branch 'main' into ex-refactor-detectors
Browse files Browse the repository at this point in the history
  • Loading branch information
andiwand authored Dec 7, 2024
2 parents ed4678b + 5e8efd6 commit 1755a30
Show file tree
Hide file tree
Showing 27 changed files with 78 additions and 220 deletions.
2 changes: 1 addition & 1 deletion CI/physmon/workflows/physmon_trackfinding_1muon.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def run_ckf_tracking(label, seeding):
rnd=rnd,
postSelectParticles=ParticleSelectorConfig(
pt=(0.9 * u.GeV, None),
measurements=(9, None),
hits=(9, None),
removeNeutral=True,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
rnd=rnd,
postSelectParticles=ParticleSelectorConfig(
pt=(0.9 * u.GeV, None),
measurements=(9, None),
hits=(9, None),
removeNeutral=True,
),
)
Expand Down
2 changes: 1 addition & 1 deletion CI/physmon/workflows/physmon_trackfinding_ttbar_pu200.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
),
postSelectParticles=ParticleSelectorConfig(
pt=(0.5 * u.GeV, None),
measurements=(9, None),
hits=(9, None),
removeNeutral=True,
),
)
Expand Down
1 change: 0 additions & 1 deletion Examples/Algorithms/TrackFitting/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ add_library(
ActsExamplesTrackFitting
SHARED
src/RefittingCalibrator.cpp
src/SurfaceSortingAlgorithm.cpp
src/TrackFittingAlgorithm.cpp
src/KalmanFitterFunction.cpp
src/RefittingAlgorithm.cpp
Expand Down

This file was deleted.

84 changes: 0 additions & 84 deletions Examples/Algorithms/TrackFitting/src/SurfaceSortingAlgorithm.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@

#include "ActsExamples/TruthTracking/ParticleSelector.hpp"

#include "Acts/Definitions/Common.hpp"
#include "Acts/Utilities/VectorHelpers.hpp"
#include "ActsExamples/EventData/Index.hpp"
#include "ActsExamples/EventData/SimParticle.hpp"
#include "ActsExamples/Framework/AlgorithmContext.hpp"

#include <ostream>
#include <stdexcept>
#include <utility>

ActsExamples::ParticleSelector::ParticleSelector(const Config& config,
Acts::Logging::Level level)
namespace ActsExamples {

ParticleSelector::ParticleSelector(const Config& config,
Acts::Logging::Level level)
: IAlgorithm("ParticleSelector", level), m_cfg(config) {
if (m_cfg.inputParticles.empty()) {
throw std::invalid_argument("Missing input particles collection");
Expand All @@ -28,8 +30,17 @@ ActsExamples::ParticleSelector::ParticleSelector(const Config& config,
}

m_inputParticles.initialize(m_cfg.inputParticles);
m_inputParticleMeasurementsMap.maybeInitialize(
m_cfg.inputParticleMeasurementsMap);
m_outputParticles.initialize(m_cfg.outputParticles);

if (!m_inputParticleMeasurementsMap.isInitialized() &&
(m_cfg.measurementsMin > 0 ||
m_cfg.measurementsMax < std::numeric_limits<std::size_t>::max())) {
throw std::invalid_argument(
"Measurement-based cuts require the inputMeasurementParticlesMap");
}

ACTS_DEBUG("selection particle rho [" << m_cfg.rhoMin << "," << m_cfg.rhoMax
<< ")");
ACTS_DEBUG("selection particle |z| [" << m_cfg.absZMin << "," << m_cfg.absZMax
Expand All @@ -46,6 +57,8 @@ ActsExamples::ParticleSelector::ParticleSelector(const Config& config,
<< ")");
ACTS_DEBUG("selection particle m [" << m_cfg.mMin << "," << m_cfg.mMax
<< ")");
ACTS_DEBUG("selection particle hits [" << m_cfg.hitsMin << ","
<< m_cfg.hitsMax << ")");
ACTS_DEBUG("selection particle measurements ["
<< m_cfg.measurementsMin << "," << m_cfg.measurementsMax << ")");
ACTS_DEBUG("remove charged particles " << m_cfg.removeCharged);
Expand All @@ -59,12 +72,18 @@ ActsExamples::ParticleSelector::ParticleSelector(const Config& config,
<< m_cfg.maxPrimaryVertexId << ")");
}

ActsExamples::ProcessCode ActsExamples::ParticleSelector::execute(
const AlgorithmContext& ctx) const {
ProcessCode ParticleSelector::execute(const AlgorithmContext& ctx) const {
// prepare input/ output types
const SimParticleContainer& inputParticles = m_inputParticles(ctx);

const static InverseMultimap<SimBarcode> emptyMeasurementParticlesMap;
const InverseMultimap<SimBarcode>& inputMeasurementParticlesMap =
m_inputParticleMeasurementsMap.isInitialized()
? m_inputParticleMeasurementsMap(ctx)
: emptyMeasurementParticlesMap;

std::size_t nInvalidCharge = 0;
std::size_t nInvalidHitCount = 0;
std::size_t nInvalidMeasurementCount = 0;

// helper functions to select tracks
Expand All @@ -87,9 +106,14 @@ ActsExamples::ProcessCode ActsExamples::ParticleSelector::execute(

nInvalidCharge += static_cast<std::size_t>(!validCharge);

bool validMeasurementCount =
within(p.numberOfHits(), m_cfg.measurementsMin, m_cfg.measurementsMax);
const bool validHitCount =
within(p.numberOfHits(), m_cfg.hitsMin, m_cfg.hitsMax);
nInvalidHitCount += static_cast<std::size_t>(!validHitCount);

const std::size_t measurementCount =
inputMeasurementParticlesMap.count(p.particleId());
const bool validMeasurementCount =
within(measurementCount, m_cfg.measurementsMin, m_cfg.measurementsMax);
nInvalidMeasurementCount +=
static_cast<std::size_t>(!validMeasurementCount);

Expand All @@ -103,7 +127,7 @@ ActsExamples::ProcessCode ActsExamples::ParticleSelector::execute(
}

return validPdg && validCharge && validSecondary && validPrimaryVertexId &&
validMeasurementCount &&
validHitCount && validMeasurementCount &&
within(p.transverseMomentum(), m_cfg.ptMin, m_cfg.ptMax) &&
within(std::abs(eta), m_cfg.absEtaMin, m_cfg.absEtaMax) &&
within(eta, m_cfg.etaMin, m_cfg.etaMax) &&
Expand Down Expand Up @@ -132,10 +156,13 @@ ActsExamples::ProcessCode ActsExamples::ParticleSelector::execute(
<< outputParticles.size() << " from "
<< inputParticles.size() << " particles");
ACTS_DEBUG("filtered out because of charge: " << nInvalidCharge);
ACTS_DEBUG("filtered out because of hit count: " << nInvalidHitCount);
ACTS_DEBUG("filtered out because of measurement count: "
<< nInvalidMeasurementCount);

m_outputParticles(ctx, std::move(outputParticles));

return ProcessCode::SUCCESS;
}

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/EventData/Index.hpp"
#include "ActsExamples/EventData/SimParticle.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
#include "ActsExamples/Framework/IAlgorithm.hpp"
Expand All @@ -26,6 +27,9 @@ class ParticleSelector final : public IAlgorithm {
struct Config {
/// The input particles collection.
std::string inputParticles;
/// (Optionally) The input particle measurements map. Only required for
/// measurement-based cuts.
std::string inputParticleMeasurementsMap;
/// The output particles collection.
std::string outputParticles;

Expand All @@ -51,7 +55,10 @@ class ParticleSelector final : public IAlgorithm {
// Rest mass cuts
double mMin = 0;
double mMax = std::numeric_limits<double>::infinity();
/// Measurement number cuts
// Hit count cuts
std::size_t hitsMin = 0;
std::size_t hitsMax = std::numeric_limits<std::size_t>::max();
// Measurement number cuts
std::size_t measurementsMin = 0;
std::size_t measurementsMax = std::numeric_limits<std::size_t>::max();
/// Remove charged particles.
Expand Down Expand Up @@ -81,6 +88,8 @@ class ParticleSelector final : public IAlgorithm {
Config m_cfg;

ReadDataHandle<SimParticleContainer> m_inputParticles{this, "InputParticles"};
ReadDataHandle<InverseMultimap<SimBarcode>> m_inputParticleMeasurementsMap{
this, "InputParticleMeasurementsMap"};

WriteDataHandle<SimParticleContainer> m_outputParticles{this,
"OutputParticles"};
Expand Down
12 changes: 0 additions & 12 deletions Examples/Python/python/acts/examples/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,6 @@ def addKalmanTracks(
s: acts.examples.Sequencer,
trackingGeometry: acts.TrackingGeometry,
field: acts.MagneticFieldProvider,
directNavigation: bool = False,
reverseFilteringMomThreshold: float = 0 * u.GeV,
inputProtoTracks: str = "truth_particle_tracks",
multipleScattering: bool = True,
Expand All @@ -1299,17 +1298,6 @@ def addKalmanTracks(
) -> None:
customLogLevel = acts.examples.defaultLogging(s, logLevel)

if directNavigation:
srfSortAlg = acts.examples.SurfaceSortingAlgorithm(
level=customLogLevel(),
inputProtoTracks=inputProtoTracks,
inputSimHits="simhits",
inputMeasurementSimHitsMap="measurement_simhits_map",
outputProtoTracks="sorted_truth_particle_tracks",
)
s.addAlgorithm(srfSortAlg)
inputProtoTracks = srfSortAlg.config.outputProtoTracks

kalmanOptions = {
"multipleScattering": multipleScattering,
"energyLoss": energyLoss,
Expand Down
5 changes: 4 additions & 1 deletion Examples/Python/python/acts/examples/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@
"absEta", # (min,max)
"pt", # (min,max)
"m", # (min,max)
"hits", # (min,max)
"measurements", # (min,max)
"removeCharged", # bool
"removeNeutral", # bool
"removeSecondaries", # bool
],
defaults=[(None, None)] * 9 + [None] * 3,
defaults=[(None, None)] * 10 + [None] * 3,
)


Expand Down Expand Up @@ -393,6 +394,8 @@ def addParticleSelection(
ptMax=config.pt[1],
mMin=config.m[0],
mMax=config.m[1],
hitsMin=config.hits[0],
hitsMax=config.hits[1],
measurementsMin=config.measurements[0],
measurementsMax=config.measurements[1],
removeCharged=config.removeCharged,
Expand Down
Loading

0 comments on commit 1755a30

Please sign in to comment.