-
Notifications
You must be signed in to change notification settings - Fork 171
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
refactor: Reworked HitSelector
in Examples
#3836
Draft
andiwand
wants to merge
3
commits into
acts-project:main
Choose a base branch
from
andiwand:feat-hit-and-meas-selector
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+221
−97
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
Examples/Algorithms/TruthTracking/ActsExamples/TruthTracking/HitSelector.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,84 @@ | ||
// This file is part of the ACTS project. | ||
// | ||
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. | ||
|
||
#include "ActsExamples/TruthTracking/HitSelector.hpp" | ||
|
||
#include "Acts/Utilities/MathHelpers.hpp" | ||
#include "ActsExamples/EventData/SimHit.hpp" | ||
#include "ActsExamples/EventData/SimParticle.hpp" | ||
|
||
ActsExamples::HitSelector::HitSelector(const Config& config, | ||
Acts::Logging::Level level) | ||
: IAlgorithm("HitSelector", level), m_cfg(config) { | ||
m_inputHits.initialize(m_cfg.inputHits); | ||
m_inputParticlesSelected.maybeInitialize(m_cfg.inputParticlesSelected); | ||
m_outputHits.initialize(m_cfg.outputHits); | ||
|
||
ACTS_DEBUG("selection particles " << m_cfg.inputParticlesSelected); | ||
ACTS_DEBUG("selection hit x [" << m_cfg.minX << "," << m_cfg.maxX << ")"); | ||
ACTS_DEBUG("selection hit y [" << m_cfg.minY << "," << m_cfg.maxY << ")"); | ||
ACTS_DEBUG("selection hit z [" << m_cfg.minZ << "," << m_cfg.maxZ << ")"); | ||
ACTS_DEBUG("selection hit r [" << m_cfg.minR << "," << m_cfg.maxR << ")"); | ||
ACTS_DEBUG("selection hit time [" << m_cfg.minTime << "," << m_cfg.maxTime | ||
<< ")"); | ||
ACTS_DEBUG("selection hit energy loss [" << m_cfg.minEnergyLoss << "," | ||
<< m_cfg.maxEnergyLoss << ")"); | ||
ACTS_DEBUG("selection primary vertex ID [" << m_cfg.minPrimaryVertexId << "," | ||
<< m_cfg.maxPrimaryVertexId | ||
<< ")"); | ||
} | ||
|
||
ActsExamples::ProcessCode ActsExamples::HitSelector::execute( | ||
const ActsExamples::AlgorithmContext& ctx) const { | ||
const SimHitContainer& hits = m_inputHits(ctx); | ||
const SimParticleContainer* particlesSelected = | ||
m_inputParticlesSelected.isInitialized() ? &m_inputParticlesSelected(ctx) | ||
: nullptr; | ||
|
||
std::vector<SimHit> unorderedHits; | ||
unorderedHits.reserve(hits.size()); | ||
|
||
for (const auto& hit : hits) { | ||
const double r = Acts::fastHypot(hit.position().x(), hit.position().y()); | ||
const std::uint64_t primaryVertexId = hit.particleId().vertexPrimary(); | ||
|
||
const bool validParticle = (particlesSelected == nullptr) || | ||
particlesSelected->contains(hit.particleId()); | ||
const bool validX = | ||
(m_cfg.minX <= hit.position().x()) && (hit.position().x() < m_cfg.maxX); | ||
const bool validY = | ||
(m_cfg.minY <= hit.position().y()) && (hit.position().y() < m_cfg.maxY); | ||
const bool validZ = | ||
(m_cfg.minZ <= hit.position().z()) && (hit.position().z() < m_cfg.maxZ); | ||
const bool validR = (m_cfg.minR <= r) && (r < m_cfg.maxR); | ||
const bool validTime = | ||
(m_cfg.minTime <= hit.time()) && (hit.time() < m_cfg.maxTime); | ||
const bool validEnergyLoss = | ||
(m_cfg.minEnergyLoss <= hit.depositedEnergy()) && | ||
(hit.depositedEnergy() < m_cfg.maxEnergyLoss); | ||
const bool validPrimaryVertexId = | ||
(m_cfg.minPrimaryVertexId <= primaryVertexId) && | ||
(primaryVertexId < m_cfg.maxPrimaryVertexId); | ||
|
||
const bool validHit = validParticle && validX && validY && validZ && | ||
validR && validTime && validEnergyLoss && | ||
validPrimaryVertexId; | ||
if (validHit) { | ||
unorderedHits.push_back(hit); | ||
} | ||
} | ||
|
||
SimHitContainer selectedHits(unorderedHits.begin(), unorderedHits.end()); | ||
|
||
ACTS_DEBUG("selected " << selectedHits.size() << " from " << hits.size() | ||
<< " hits"); | ||
|
||
m_outputHits(ctx, std::move(selectedHits)); | ||
|
||
return ProcessCode::SUCCESS; | ||
} |
86 changes: 86 additions & 0 deletions
86
Examples/Algorithms/TruthTracking/ActsExamples/TruthTracking/HitSelector.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,86 @@ | ||
// This file is part of the ACTS project. | ||
// | ||
// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "Acts/Utilities/Logger.hpp" | ||
#include "ActsExamples/EventData/SimHit.hpp" | ||
#include "ActsExamples/EventData/SimParticle.hpp" | ||
#include "ActsExamples/Framework/DataHandle.hpp" | ||
#include "ActsExamples/Framework/IAlgorithm.hpp" | ||
|
||
#include <limits> | ||
#include <string> | ||
|
||
namespace ActsExamples { | ||
|
||
/// Select hits by applying some selection cuts. | ||
class HitSelector final : public IAlgorithm { | ||
public: | ||
struct Config { | ||
/// Input hit collection. | ||
std::string inputHits; | ||
/// Optional input particle collection. | ||
std::string inputParticlesSelected; | ||
/// Output hit collection | ||
std::string outputHits; | ||
|
||
/// Min x cut | ||
double minX = -std::numeric_limits<double>::max(); | ||
/// Max x cut | ||
double maxX = std::numeric_limits<double>::max(); | ||
|
||
/// Min y cut | ||
double minY = -std::numeric_limits<double>::max(); | ||
/// Max y cut | ||
double maxY = std::numeric_limits<double>::max(); | ||
|
||
/// Min z cut | ||
double minZ = -std::numeric_limits<double>::max(); | ||
/// Max z cut | ||
double maxZ = std::numeric_limits<double>::max(); | ||
|
||
/// Min r cut | ||
double minR = -std::numeric_limits<double>::max(); | ||
/// Max r cut | ||
double maxR = std::numeric_limits<double>::max(); | ||
|
||
/// Min time cut | ||
double minTime = -std::numeric_limits<double>::max(); | ||
/// Max time cut | ||
double maxTime = std::numeric_limits<double>::max(); | ||
|
||
/// Min energy loss cut | ||
double minEnergyLoss = 0; | ||
/// Max energy loss cut | ||
double maxEnergyLoss = std::numeric_limits<double>::max(); | ||
|
||
/// Min primary vertex ID cut | ||
std::uint64_t minPrimaryVertexId = 0; | ||
/// Max primary vertex ID cut | ||
std::uint64_t maxPrimaryVertexId = | ||
std::numeric_limits<std::uint64_t>::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"}; | ||
ReadDataHandle<SimParticleContainer> m_inputParticlesSelected{ | ||
this, "InputParticlesSelected"}; | ||
WriteDataHandle<SimHitContainer> m_outputHits{this, "OutputHits"}; | ||
}; | ||
|
||
} // 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
50 changes: 0 additions & 50 deletions
50
Examples/Algorithms/Utilities/include/ActsExamples/Utilities/HitSelector.hpp
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -10,25 +10,16 @@ | |
|
||
#include "Acts/Definitions/Algebra.hpp" | ||
#include "Acts/Definitions/TrackParametrization.hpp" | ||
#include "Acts/EventData/MeasurementHelpers.hpp" | ||
#include "Acts/EventData/SubspaceHelpers.hpp" | ||
#include "Acts/EventData/Types.hpp" | ||
#include "Acts/EventData/detail/ParameterTraits.hpp" | ||
#include "Acts/EventData/detail/PrintParameters.hpp" | ||
#include "Acts/Geometry/GeometryIdentifier.hpp" | ||
#include "Acts/Utilities/Iterator.hpp" | ||
#include "ActsExamples/EventData/GeometryContainers.hpp" | ||
#include "ActsExamples/EventData/IndexSourceLink.hpp" | ||
#include "ActsExamples/EventData/MeasurementConcept.hpp" | ||
|
||
#include <array> | ||
#include <compare> | ||
#include <concepts> | ||
#include <cstddef> | ||
#include <iosfwd> | ||
#include <iterator> | ||
#include <type_traits> | ||
#include <variant> | ||
#include <vector> | ||
|
||
#include <boost/container/static_vector.hpp> | ||
|
@@ -138,6 +129,11 @@ class MeasurementContainer { | |
return getMeasurement<Size>(addMeasurement(Size, geometryId)); | ||
} | ||
|
||
template <MeasurementConcept OtherDerived> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems unrelated? |
||
VariableProxy copyMeasurement(const OtherDerived& other); | ||
template <MeasurementConcept OtherDerived, std::size_t Size> | ||
FixedProxy<Size> copyMeasurement(const OtherDerived& other); | ||
|
||
template <typename... Args> | ||
VariableProxy emplaceMeasurement(std::uint8_t size, | ||
Acts::GeometryIdentifier geometryId, | ||
|
@@ -494,6 +490,22 @@ class VariableMeasurementProxy | |
} | ||
}; | ||
|
||
template <MeasurementConcept OtherDerived> | ||
MeasurementContainer::VariableProxy MeasurementContainer::copyMeasurement( | ||
const OtherDerived& other) { | ||
VariableProxy meas = makeMeasurement(other.size(), other.geometryId()); | ||
meas.copyFrom(other); | ||
return meas; | ||
} | ||
|
||
template <MeasurementConcept OtherDerived, std::size_t Size> | ||
MeasurementContainer::FixedProxy<Size> MeasurementContainer::copyMeasurement( | ||
const OtherDerived& other) { | ||
FixedProxy<Size> meas = makeMeasurement<Size>(other.geometryId()); | ||
meas.copyFrom(other); | ||
return meas; | ||
} | ||
|
||
template <typename... Args> | ||
MeasurementContainer::VariableProxy MeasurementContainer::emplaceMeasurement( | ||
std::uint8_t size, Acts::GeometryIdentifier geometryId, Args&&... args) { | ||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle one could optimize the construction by sorting the vector and provide this
boost::container::sorted_range_t
tag (or similar), might be benefitial in for very high pile-up situations with a lot of hits...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I think we can reserve the space in the
SimHitContainer
, right?