Skip to content

Commit 00e79ae

Browse files
authored
feat: projected grid filling in Gen2 (acts-project#4811)
This is some attempt to optimize the grid filling in Gen2 which we can then shift into Gen3. Having it merged in will allow us to test it in an Athena deployment. --- END COMMIT MESSAGE --- **Try all navigation: 10 000 tracks - Gen2** | Algorithm | Total Time (ms) | Time/Event (ms) | Fraction | |:--------------------------------------|----------------:|----------------:|---------:| | Algorithm:PropagationAlgorithm | 7577.90 | 75.78 | 99.8% | | Reader:EventGenerator | 9.07 | 0.09 | 0.1% | | Algorithm:HepMC3InputConverter | 2.07 | 0.02 | 0.0% | | Algorithm:ParticleTrackParamExtractor | 1.22 | 0.01 | 0.0% | | TOTAL | 7590.27 | 75.90 | 100.0% | **(over-optimized) Grid navigation: 10 000 tracks - Gen2** | Algorithm | Total Time (ms) | Time/Event (ms) | Fraction | |:--------------------------------------|----------------:|----------------:|---------:| | Algorithm:PropagationAlgorithm | 142.16 | 1.42 | 93.6% | | Reader:EventGenerator | 7.94 | 0.08 | 5.2% | | Algorithm:HepMC3InputConverter | 1.04 | 0.01 | 0.7% | | Algorithm:ParticleTrackParamExtractor | 0.69 | 0.01 | 0.5% | | TOTAL | 151.83 | 1.52 | 100.0% | **Conservative grid:** | Algorithm | Total Time (ms) | Time/Event (ms) | Fraction | |:--------------------------------------|----------------:|----------------:|---------:| | Algorithm:PropagationAlgorithm | 1453.06 | 14.53 | 91.3% | | Reader:EventGenerator | 125.08 | 1.25 | 7.9% | | Algorithm:ParticleTrackParamExtractor | 7.08 | 0.07 | 0.4% | | Algorithm:HepMC3InputConverter | 5.98 | 0.06 | 0.4% | | TOTAL | 1591.20 | 15.91 | 100.0% | Any further description goes here, @-mentions are ok here! - Use a *conventional commits* prefix: [quick summary](https://www.conventionalcommits.org/en/v1.0.0/#summary) - We mostly use `feat`, `fix`, `refactor`, `docs`, `chore` and `build` types. - A milestone will be assigned by one of the maintainers
1 parent cc2d0bd commit 00e79ae

17 files changed

Lines changed: 383 additions & 93 deletions

File tree

Core/include/Acts/Detector/KdtSurfacesProvider.hpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ namespace Acts::Experimental {
2929
/// KDTree lookup positions
3030
///
3131
template <std::size_t kDIM = 2u, std::size_t bSize = 100u,
32-
typename reference_generator =
33-
detail::PolyhedronReferenceGenerator<1u, false>>
32+
typename reference_generator = detail::PolyhedronReferenceGenerator>
3433
class KdtSurfaces {
3534
public:
3635
/// Broadcast the surface KDT type
@@ -49,11 +48,11 @@ class KdtSurfaces {
4948
/// @param surfaces the surfaces to be filled into the tree
5049
/// @param casts the cast list from global position into kdtree local
5150
/// @param rgen the reference point generator
52-
KdtSurfaces(const GeometryContext& gctx,
53-
const std::vector<std::shared_ptr<Surface>>& surfaces,
54-
const std::array<AxisDirection, kDIM>& casts,
55-
const reference_generator& rgen =
56-
detail::PolyhedronReferenceGenerator<1u, false>{})
51+
KdtSurfaces(
52+
const GeometryContext& gctx,
53+
const std::vector<std::shared_ptr<Surface>>& surfaces,
54+
const std::array<AxisDirection, kDIM>& casts,
55+
const reference_generator& rgen = detail::PolyhedronReferenceGenerator{})
5756
: m_kdt(nullptr), m_casts(casts), m_rGenerator(rgen) {
5857
// Simple check if the dimension is correct
5958
if (kDIM == 0u) {
@@ -161,8 +160,7 @@ class KdtSurfaces {
161160
/// This allows to create small region based callable structs at
162161
/// configuration level that are then connected to an InternalStructureBuilder
163162
template <std::size_t kDIM = 2u, std::size_t bSize = 100u,
164-
typename reference_generator =
165-
detail::PolyhedronReferenceGenerator<1u, false>>
163+
typename reference_generator = detail::PolyhedronReferenceGenerator>
166164
class KdtSurfacesProvider : public ISurfacesProvider {
167165
public:
168166
/// The prefilled surfaces in a KD tree structure, it is generally shared

Core/include/Acts/Detector/LayerStructureBuilder.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Acts/Definitions/Algebra.hpp"
1212
#include "Acts/Detector/DetectorComponents.hpp"
1313
#include "Acts/Detector/ProtoSupport.hpp"
14+
#include "Acts/Detector/detail/ReferenceGenerators.hpp"
1415
#include "Acts/Detector/interface/IInternalStructureBuilder.hpp"
1516
#include "Acts/Detector/interface/ISurfacesProvider.hpp"
1617
#include "Acts/Geometry/GeometryContext.hpp"
@@ -85,6 +86,16 @@ class LayerStructureBuilder : public IInternalStructureBuilder {
8586
std::vector<ProtoSupport> supports = {};
8687
/// Definition of Binnings
8788
std::vector<std::tuple<DirectedProtoAxis, std::size_t>> binnings = {};
89+
/// Expansion value for the reference generation
90+
double expansionValue = 0.0;
91+
/// Sampling the luminous region for projected reference generation
92+
std::vector<Vector3> luminousRegion = {Vector3(0., 0., -200.),
93+
Vector3(0., 0., 200.)};
94+
/// Reference generator to be used
95+
detail::ReferenceGeneratorType referenceGeneratorType =
96+
detail::ReferenceGeneratorType::Polyhedron;
97+
/// Projection surface for projected reference generator
98+
std::shared_ptr<Surface> projectionReferenceSurface = nullptr;
8899
/// Optional extent (if already parsed), will trigger binning autorange
89100
/// check
90101
std::optional<Extent> extent = std::nullopt;

Core/include/Acts/Detector/detail/ReferenceGenerators.hpp

Lines changed: 84 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,49 @@
1919

2020
namespace Acts::Experimental::detail {
2121

22+
enum class ReferenceGeneratorType {
23+
Center,
24+
AxisDirection,
25+
Polyhedron,
26+
Projected
27+
};
28+
29+
struct IReferenceGenerator {
30+
virtual ~IReferenceGenerator() = default;
31+
32+
/// Helper to access reference positions for filling the grid
33+
///
34+
/// @param gctx the geometry context of this operation
35+
/// @param surface the surface for which the reference points are to be accessed
36+
///
37+
/// @return a vector of reference points for filling
38+
virtual const std::vector<Vector3> references(
39+
const GeometryContext& gctx, const Surface& surface) const = 0;
40+
41+
/// Access the type of the reference generator
42+
virtual ReferenceGeneratorType type() const = 0;
43+
};
44+
2245
/// A struct to access the center position
2346
///
2447
/// This generator will provide only one filling point and hence
2548
/// only a single bin in the indexed grid.
26-
struct CenterReferenceGenerator {
49+
struct CenterReferenceGenerator : public IReferenceGenerator {
2750
/// Helper to access the Center point of for filling the grid
2851
///
2952
/// @param gctx the geometry context of this operation
3053
/// @param surface the surface for which the reference point is to be accessed
3154
///
3255
/// @return a vector of reference points for filling
3356
const std::vector<Vector3> references(const GeometryContext& gctx,
34-
const Surface& surface) const {
57+
const Surface& surface) const override {
3558
return {surface.center(gctx)};
3659
}
60+
61+
/// Access the type of the reference generator
62+
ReferenceGeneratorType type() const override {
63+
return ReferenceGeneratorType::Center;
64+
}
3765
};
3866

3967
/// A struct to access reference positions based on bin values
@@ -43,52 +71,85 @@ struct CenterReferenceGenerator {
4371
/// This generator will provide only one filling point and hence
4472
/// only a single bin in the indexed grid.
4573
template <AxisDirection bVAL>
46-
struct AxisDirectionReferenceGenerator {
74+
struct AxisDirectionReferenceGenerator : public IReferenceGenerator {
4775
/// Helper to access a reference position based on binning value
4876
///
4977
/// @param gctx the geometry context of this operation
5078
/// @param surface the surface for which the reference point is to be accessed
5179
///
5280
/// @return a vector of reference points for filling
5381
const std::vector<Vector3> references(const GeometryContext& gctx,
54-
const Surface& surface) const {
82+
const Surface& surface) const override {
5583
return {surface.referencePosition(gctx, bVAL)};
5684
}
85+
86+
/// Access the type of the reference generator
87+
ReferenceGeneratorType type() const override {
88+
return ReferenceGeneratorType::AxisDirection;
89+
}
5790
};
5891

5992
/// A struct to access generated vertices from surface polyhedrons
6093
/// These vertices are then used to find the bin boundary box for the
6194
/// indexed grid.
6295
///
63-
/// @tparam nSEGS the number of segments to be used for the polyhedron
64-
/// approximation of arcs between vertices
65-
/// @tparam aBARY if true, the barycenter of the polyhedron is added
6696
///
6797
/// The grid filling then completes the empty bins in between and
6898
/// expands if necessary.
69-
template <std::size_t nSEGS = 1u, bool aBARY = true>
70-
struct PolyhedronReferenceGenerator {
99+
struct PolyhedronReferenceGenerator : public IReferenceGenerator {
100+
/// This is for the barycenter addition
101+
bool addBarycenter = false;
102+
103+
/// @brief The number of segments for the polyhedron approximation
104+
int nSegements = 1;
105+
106+
/// Absolute expansion value for the reference points
107+
double expansionValue = 0.0;
108+
71109
/// Helper to access the Center point of for filling the grid
72110
///
73111
/// @param gctx the geometry context of this operation
74112
/// @param surface the surface for which the reference point is to be accessed
75113
///
76114
/// @return a vector of reference points for filling
77115
const std::vector<Vector3> references(const GeometryContext& gctx,
78-
const Surface& surface) const {
79-
// Create the return vector
80-
std::vector<Vector3> rPositions;
81-
auto pHedron = surface.polyhedronRepresentation(gctx, nSEGS);
82-
rPositions.insert(rPositions.end(), pHedron.vertices.begin(),
83-
pHedron.vertices.end());
84-
// Add the barycenter if configured
85-
if constexpr (aBARY) {
86-
Vector3 bc(0., 0., 0.);
87-
std::ranges::for_each(rPositions, [&](const auto& p) { bc += p; });
88-
bc *= 1. / rPositions.size();
89-
rPositions.push_back(bc);
90-
}
91-
return rPositions;
116+
const Surface& surface) const override;
117+
118+
/// Access the type of the reference generator
119+
ReferenceGeneratorType type() const override {
120+
return ReferenceGeneratorType::Polyhedron;
121+
}
122+
};
123+
124+
/// A Projected reference generator which projects the polyhedron vertices onto
125+
/// a given reference surface.
126+
///
127+
struct ProjectedReferenceGenerator : public IReferenceGenerator {
128+
/// The reference surface onto which to project
129+
std::shared_ptr<Surface> referenceSurface = nullptr;
130+
131+
/// @brief The number of segments for the polyhedron approximation
132+
int nSegements = 1;
133+
134+
/// Absolute expansion value for the reference points
135+
double expansionValue = 0.0;
136+
137+
/// Luminous region sampling points for the projection - beam spot
138+
std::vector<Vector3> luminousRegion = {Vector3(0., 0., -200.),
139+
Vector3(0., 0., 200.0)};
140+
141+
/// Helper to access the Center point of for filling the grid
142+
///
143+
/// @param gctx the geometry context of this operation
144+
/// @param surface the surface for which the reference point is to be accessed
145+
///
146+
/// @return a vector of reference points for filling
147+
const std::vector<Vector3> references(const GeometryContext& gctx,
148+
const Surface& surface) const override;
149+
150+
/// Access the type of the reference generator
151+
ReferenceGeneratorType type() const override {
152+
return ReferenceGeneratorType::Projected;
92153
}
93154
};
94155

Core/src/Detector/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ target_sources(
88
detail/DetectorVolumeConsistency.cpp
99
detail/PortalHelper.cpp
1010
detail/ProtoMaterialHelper.cpp
11+
detail/ReferenceGenerators.cpp
1112
detail/SupportSurfacesHelper.cpp
1213
detail/IndexedGridFiller.cpp
1314
CylindricalContainerBuilder.cpp

Core/src/Detector/LayerStructureBuilder.cpp

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,45 @@ void adaptBinningRange(
6363
}
6464
}
6565

66+
template <typename reference_generator>
67+
Acts::Experimental::InternalNavigationDelegate createInternalNavigationDelegate(
68+
const Acts::GeometryContext& gctx,
69+
const std::vector<std::shared_ptr<Acts::Surface>>& internalSurfaces,
70+
std::vector<std::tuple<Acts::DirectedProtoAxis, std::size_t>>& binnings,
71+
const reference_generator& rGenerator,
72+
const std::vector<std::size_t>& assignToAll) {
73+
// shorthand it
74+
using namespace Acts;
75+
using namespace Acts::Experimental;
76+
77+
// Retrieve the layer surfaces
78+
InternalNavigationDelegate internalCandidatesUpdater =
79+
tryAllPortalsAndSurfaces();
80+
81+
// 1D surface binning
82+
if (binnings.size() == 1) {
83+
const auto& [protoAxis, fillExpansion] = binnings.at(0);
84+
internalCandidatesUpdater =
85+
Acts::detail::IndexedSurfacesGenerator::createInternalNavigation<
86+
Acts::Experimental::IndexedSurfacesNavigation>(
87+
gctx, internalSurfaces, rGenerator, protoAxis, fillExpansion,
88+
assignToAll);
89+
} else if (binnings.size() == 2u) {
90+
const auto& [protoAxisA, fillExpansionA] = binnings.at(0);
91+
const auto& [protoAxisB, fillExpansionB] = binnings.at(1);
92+
internalCandidatesUpdater =
93+
Acts::detail::IndexedSurfacesGenerator::createInternalNavigation<
94+
Experimental::IndexedSurfacesNavigation>(
95+
gctx, internalSurfaces, rGenerator, protoAxisA, fillExpansionA,
96+
protoAxisB, fillExpansionB, assignToAll);
97+
} else {
98+
throw std::runtime_error(
99+
"LayerStructureBuilder: only 1D or 2D surface binning "
100+
"supported.");
101+
}
102+
return internalCandidatesUpdater;
103+
}
104+
66105
} // namespace
67106

68107
Acts::Experimental::LayerStructureBuilder::LayerStructureBuilder(
@@ -209,31 +248,37 @@ Acts::Experimental::LayerStructureBuilder::construct(
209248
adaptBinningRange(binnings, m_cfg.extent.value());
210249
}
211250

251+
ACTS_VERBOSE("Creating internal layer structure with "
252+
<< binnings.size() << " surface binning from "
253+
<< internalSurfaces.size() << " surfaces.");
212254
// Provide a reference generator
213-
Acts::Experimental::detail::PolyhedronReferenceGenerator rGenerator;
255+
if (m_cfg.referenceGeneratorType ==
256+
detail::ReferenceGeneratorType::Projected) {
257+
Acts::Experimental::detail::ProjectedReferenceGenerator rGenerator;
258+
rGenerator.expansionValue = m_cfg.expansionValue;
259+
rGenerator.referenceSurface = m_cfg.projectionReferenceSurface;
260+
rGenerator.luminousRegion = m_cfg.luminousRegion;
261+
262+
internalCandidatesUpdater = createInternalNavigationDelegate(
263+
gctx, internalSurfaces, binnings, rGenerator, assignToAll);
264+
265+
} else if (m_cfg.referenceGeneratorType ==
266+
detail::ReferenceGeneratorType::Center) {
267+
Acts::Experimental::detail::CenterReferenceGenerator rGenerator;
268+
269+
internalCandidatesUpdater = createInternalNavigationDelegate(
270+
gctx, internalSurfaces, binnings, rGenerator, assignToAll);
271+
} else if (m_cfg.referenceGeneratorType ==
272+
detail::ReferenceGeneratorType::Polyhedron) {
273+
Acts::Experimental::detail::PolyhedronReferenceGenerator rGenerator;
274+
rGenerator.expansionValue = m_cfg.expansionValue;
275+
276+
internalCandidatesUpdater = createInternalNavigationDelegate(
277+
gctx, internalSurfaces, binnings, rGenerator, assignToAll);
214278

215-
// 1D surface binning
216-
if (binnings.size() == 1) {
217-
ACTS_DEBUG("- creating a 1D internal binning and portal navigation");
218-
const auto& [protoAxis, fillExpansion] = binnings.at(0);
219-
internalCandidatesUpdater =
220-
Acts::detail::IndexedSurfacesGenerator::createInternalNavigation<
221-
Experimental::IndexedSurfacesNavigation>(
222-
gctx, internalSurfaces, rGenerator, protoAxis, fillExpansion,
223-
assignToAll);
224-
} else if (binnings.size() == 2u) {
225-
ACTS_DEBUG("- creating a 2D internal binning and portal navigation");
226-
const auto& [protoAxisA, fillExpansionA] = binnings.at(0);
227-
const auto& [protoAxisB, fillExpansionB] = binnings.at(1);
228-
internalCandidatesUpdater =
229-
Acts::detail::IndexedSurfacesGenerator::createInternalNavigation<
230-
Experimental::IndexedSurfacesNavigation>(
231-
gctx, internalSurfaces, rGenerator, protoAxisA, fillExpansionA,
232-
protoAxisB, fillExpansionB, assignToAll);
233279
} else {
234-
throw std::runtime_error(
235-
"LayerStructureBuilder: only 1D or 2D surface binning "
236-
"supported.");
280+
throw std::invalid_argument(
281+
"LayerStructureBuilder: unknown reference generator type.");
237282
}
238283
}
239284
} else {

0 commit comments

Comments
 (0)