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

feat: HitSelector algorithm #2731

Merged
merged 4 commits into from
Nov 27, 2023
Merged
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
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