Skip to content

Commit

Permalink
feat: HitSelector algorithm (#2731)
Browse files Browse the repository at this point in the history
Needed for the GNN+CKF workflow
  • Loading branch information
benjaminhuth authored Nov 27, 2023
1 parent 243850f commit 7e9c2f0
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions Examples/Algorithms/Utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_library(
src/TrajectoriesToPrototracks.cpp
src/TrackSelectorAlgorithm.cpp
src/TracksToTrajectories.cpp
src/HitSelector.cpp
src/TracksToParameters.cpp)
target_include_directories(
ActsExamplesUtilities
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This file is part of the Acts project.
//
// Copyright (C) 2019-2023 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/TrackFinding/TrackSelector.hpp"
#include "Acts/Utilities/Logger.hpp"
#include "ActsExamples/EventData/SimHit.hpp"
#include "ActsExamples/Framework/DataHandle.hpp"
#include "ActsExamples/Framework/IAlgorithm.hpp"

#include <cstddef>
#include <limits>
#include <string>

namespace ActsExamples {

/// Select tracks by applying some selection cuts.
class HitSelector final : public IAlgorithm {
public:
struct Config {
/// Input track collection.
std::string inputHits;
/// Output track collection
std::string outputHits;

/// Time cut
double maxTime = std::numeric_limits<double>::max();
};

HitSelector(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<SimHitContainer> m_inputHits{this, "InputHits"};
WriteDataHandle<SimHitContainer> m_outputHits{this, "OutputHits"};
};

} // namespace ActsExamples
33 changes: 33 additions & 0 deletions Examples/Algorithms/Utilities/src/HitSelector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This file is part of the Acts project.
//
// Copyright (C) 2019-2023 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/Utilities/HitSelector.hpp"

ActsExamples::HitSelector::HitSelector(const Config& config,
Acts::Logging::Level level)
: IAlgorithm("HitSelector", level), m_cfg(config) {
m_inputHits.initialize(m_cfg.inputHits);
m_outputHits.initialize(m_cfg.outputHits);
}

ActsExamples::ProcessCode ActsExamples::HitSelector::execute(
const ActsExamples::AlgorithmContext& ctx) const {
const auto& hits = m_inputHits(ctx);
SimHitContainer selectedHits;

std::copy_if(hits.begin(), hits.end(),
std::inserter(selectedHits, selectedHits.begin()),
[&](const auto& hit) { return hit.time() < m_cfg.maxTime; });

ACTS_DEBUG("selected " << selectedHits.size() << " from " << hits.size()
<< " hits");

m_outputHits(ctx, std::move(selectedHits));

return {};
}
4 changes: 4 additions & 0 deletions Examples/Python/src/TruthTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ActsExamples/TruthTracking/TruthSeedingAlgorithm.hpp"
#include "ActsExamples/TruthTracking/TruthTrackFinder.hpp"
#include "ActsExamples/TruthTracking/TruthVertexFinder.hpp"
#include "ActsExamples/Utilities/HitSelector.hpp"
#include "ActsExamples/Utilities/Range.hpp"

#include <array>
Expand Down Expand Up @@ -195,6 +196,9 @@ void addTruthTracking(Context& ctx) {
ActsExamples::TruthSeedingAlgorithm, mex, "TruthSeedingAlgorithm",
inputParticles, inputMeasurementParticlesMap, inputSpacePoints,
outputParticles, outputSeeds, outputProtoTracks, deltaRMin, deltaRMax);

ACTS_PYTHON_DECLARE_ALGORITHM(ActsExamples::HitSelector, mex, "HitSelector",
inputHits, outputHits, maxTime);
}

} // namespace Acts::Python

0 comments on commit 7e9c2f0

Please sign in to comment.