-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: TrackSelector operates on TrackContainer (#1874)
Also adds a separate `TrackParameterSelector` which retains the functionality to select from track parameters. `TrackSelector` only operates on `TrackContainer`. There's no mechanism to select `Trajectory` objects anymore. Blocked by: - #1872 - #1870
- Loading branch information
1 parent
bd9839a
commit 24b4c7a
Showing
15 changed files
with
303 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
Examples/Algorithms/TruthTracking/ActsExamples/TruthTracking/TrackParameterSelector.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 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/TruthTracking/TrackParameterSelector.hpp" | ||
|
||
#include "Acts/Utilities/ThrowAssert.hpp" | ||
#include "ActsExamples/EventData/Track.hpp" | ||
#include "ActsExamples/EventData/Trajectories.hpp" | ||
#include "ActsExamples/Framework/WhiteBoard.hpp" | ||
|
||
#include <cmath> | ||
#include <cstdint> | ||
#include <stdexcept> | ||
#include <vector> | ||
|
||
ActsExamples::TrackParameterSelector::TrackParameterSelector( | ||
const Config& config, Acts::Logging::Level level) | ||
: BareAlgorithm("TrackParameterSelector", level), m_cfg(config) { | ||
if (m_cfg.inputTrackParameters.empty()) { | ||
throw std::invalid_argument("Missing input track parameters"); | ||
} | ||
if (m_cfg.outputTrackParameters.empty()) { | ||
throw std::invalid_argument("Missing output track parameters"); | ||
} | ||
} | ||
|
||
ActsExamples::ProcessCode ActsExamples::TrackParameterSelector::execute( | ||
const ActsExamples::AlgorithmContext& ctx) const { | ||
// helper functions to select tracks | ||
auto within = [](double x, double min, double max) { | ||
return (min <= x) and (x < max); | ||
}; | ||
auto isValidTrack = [&](const auto& trk) { | ||
const auto theta = trk.template get<Acts::eBoundTheta>(); | ||
const auto eta = -std::log(std::tan(theta / 2)); | ||
// define charge selection | ||
return within(trk.transverseMomentum(), m_cfg.ptMin, m_cfg.ptMax) and | ||
within(std::abs(eta), m_cfg.absEtaMin, m_cfg.absEtaMax) and | ||
within(eta, m_cfg.etaMin, m_cfg.etaMax) and | ||
within(trk.template get<Acts::eBoundPhi>(), m_cfg.phiMin, | ||
m_cfg.phiMax) and | ||
within(trk.template get<Acts::eBoundLoc0>(), m_cfg.loc0Min, | ||
m_cfg.loc0Max) and | ||
within(trk.template get<Acts::eBoundLoc1>(), m_cfg.loc1Min, | ||
m_cfg.loc1Max) and | ||
within(trk.template get<Acts::eBoundTime>(), m_cfg.timeMin, | ||
m_cfg.timeMax); | ||
}; | ||
|
||
const auto& inputTrackParameters = | ||
ctx.eventStore.get<TrackParametersContainer>(m_cfg.inputTrackParameters); | ||
TrackParametersContainer outputTrackParameters; | ||
outputTrackParameters.reserve(inputTrackParameters.size()); | ||
|
||
// copy selected tracks and record initial track index | ||
for (uint32_t i = 0; i < inputTrackParameters.size(); ++i) { | ||
const auto& trk = inputTrackParameters[i]; | ||
if (isValidTrack(trk)) { | ||
outputTrackParameters.push_back(trk); | ||
} | ||
} | ||
outputTrackParameters.shrink_to_fit(); | ||
|
||
ACTS_DEBUG("event " << ctx.eventNumber << " selected " | ||
<< outputTrackParameters.size() << " from " | ||
<< inputTrackParameters.size() | ||
<< " tracks in track parameters"); | ||
|
||
ctx.eventStore.add(m_cfg.outputTrackParameters, | ||
std::move(outputTrackParameters)); | ||
|
||
return ProcessCode::SUCCESS; | ||
} |
58 changes: 58 additions & 0 deletions
58
Examples/Algorithms/TruthTracking/ActsExamples/TruthTracking/TrackParameterSelector.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 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 "ActsExamples/Framework/BareAlgorithm.hpp" | ||
|
||
#include <limits> | ||
#include <string> | ||
|
||
namespace ActsExamples { | ||
|
||
/// Select tracks by applying some selection cuts. | ||
class TrackParameterSelector final : public BareAlgorithm { | ||
public: | ||
struct Config { | ||
/// Input track parameters collection | ||
std::string inputTrackParameters; | ||
/// Output track parameters collection. | ||
std::string outputTrackParameters; | ||
|
||
// Minimum/maximum local positions. | ||
double loc0Min = -std::numeric_limits<double>::infinity(); | ||
double loc0Max = std::numeric_limits<double>::infinity(); | ||
double loc1Min = -std::numeric_limits<double>::infinity(); | ||
double loc1Max = std::numeric_limits<double>::infinity(); | ||
// Minimum/maximum track time. | ||
double timeMin = -std::numeric_limits<double>::infinity(); | ||
double timeMax = std::numeric_limits<double>::infinity(); | ||
// Direction cuts. | ||
double phiMin = -std::numeric_limits<double>::infinity(); | ||
double phiMax = std::numeric_limits<double>::infinity(); | ||
double etaMin = -std::numeric_limits<double>::infinity(); | ||
double etaMax = std::numeric_limits<double>::infinity(); | ||
double absEtaMin = 0.0; | ||
double absEtaMax = std::numeric_limits<double>::infinity(); | ||
// Momentum cuts. | ||
double ptMin = 0.0; | ||
double ptMax = std::numeric_limits<double>::infinity(); | ||
}; | ||
|
||
TrackParameterSelector(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; | ||
}; | ||
|
||
} // namespace ActsExamples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.