Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add prototracks-to-seeds algorithm (#2219)
This allows to transform a prototracks collection into a seeds collection. Useful for the Exa.TrkX workflow.
- Loading branch information
1 parent
9d56444
commit c37d881
Showing
7 changed files
with
173 additions
and
10 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
54 changes: 54 additions & 0 deletions
54
Examples/Algorithms/Utilities/include/ActsExamples/Utilities/PrototracksToSeeds.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,54 @@ | ||
// 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/EventData/ProtoTrack.hpp" | ||
#include "ActsExamples/EventData/SimSeed.hpp" | ||
#include "ActsExamples/Framework/DataHandle.hpp" | ||
#include "ActsExamples/Framework/IAlgorithm.hpp" | ||
|
||
namespace ActsExamples { | ||
|
||
class PrototracksToSeeds final : public IAlgorithm { | ||
public: | ||
struct Config { | ||
std::string inputProtoTracks; | ||
std::string inputSpacePoints; | ||
std::string outputSeeds = "seeds-from-prototracks"; | ||
std::string outputProtoTracks = "remaining-prototracks"; | ||
}; | ||
|
||
/// Construct the algorithm. | ||
/// | ||
/// @param cfg is the algorithm configuration | ||
/// @param lvl is the logging level | ||
PrototracksToSeeds(Config cfg, Acts::Logging::Level lvl); | ||
|
||
/// Run the algorithm. | ||
/// | ||
/// @param ctx is the algorithm context with event information | ||
/// @return a process code indication success or failure | ||
ProcessCode execute(const AlgorithmContext& ctx) const final; | ||
|
||
/// Const access to the config | ||
const Config& config() const { return m_cfg; } | ||
|
||
private: | ||
Config m_cfg; | ||
|
||
WriteDataHandle<SimSeedContainer> m_outputSeeds{this, "OutputSeeds"}; | ||
WriteDataHandle<ProtoTrackContainer> m_outputProtoTracks{this, | ||
"OutputProtoTracks"}; | ||
ReadDataHandle<SimSpacePointContainer> m_inputSpacePoints{this, | ||
"InputSpacePoints"}; | ||
ReadDataHandle<ProtoTrackContainer> m_inputProtoTracks{this, | ||
"InputProtoTracks"}; | ||
}; | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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/Utilities/PrototracksToSeeds.hpp" | ||
|
||
#include "ActsExamples/EventData/IndexSourceLink.hpp" | ||
#include "ActsExamples/EventData/ProtoTrack.hpp" | ||
#include "ActsExamples/EventData/SimSeed.hpp" | ||
#include "ActsExamples/Framework/WhiteBoard.hpp" | ||
#include "ActsExamples/Utilities/EventDataTransforms.hpp" | ||
|
||
#include <algorithm> | ||
|
||
namespace ActsExamples { | ||
|
||
PrototracksToSeeds::PrototracksToSeeds(Config cfg, Acts::Logging::Level lvl) | ||
: IAlgorithm("PrototracksToSeeds", lvl), m_cfg(std::move(cfg)) { | ||
m_outputSeeds.initialize(m_cfg.outputSeeds); | ||
m_outputProtoTracks.initialize(m_cfg.outputProtoTracks); | ||
m_inputProtoTracks.initialize(m_cfg.inputProtoTracks); | ||
m_inputSpacePoints.initialize(m_cfg.inputSpacePoints); | ||
} | ||
|
||
ProcessCode PrototracksToSeeds::execute(const AlgorithmContext& ctx) const { | ||
auto prototracks = m_inputProtoTracks(ctx); | ||
|
||
const auto nBefore = prototracks.size(); | ||
prototracks.erase(std::remove_if(prototracks.begin(), prototracks.end(), | ||
[](const auto& t) { return t.size() < 3; }), | ||
prototracks.end()); | ||
ACTS_DEBUG("Discarded " << prototracks.size() - nBefore | ||
<< " prototracks with less then 3 hits"); | ||
|
||
SimSeedContainer seeds; | ||
seeds.reserve(prototracks.size()); | ||
|
||
const auto& sps = m_inputSpacePoints(ctx); | ||
std::transform(prototracks.begin(), prototracks.end(), | ||
std::back_inserter(seeds), | ||
[&](const auto& pt) { return prototrackToSeed(pt, sps); }); | ||
|
||
m_outputSeeds(ctx, std::move(seeds)); | ||
m_outputProtoTracks(ctx, std::move(prototracks)); | ||
|
||
return ProcessCode::SUCCESS; | ||
} | ||
|
||
} // 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
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