Skip to content

Commit 2276aa6

Browse files
committed
Implement python generators for detector metadata
1 parent 6e249bf commit 2276aa6

16 files changed

+1089
-155
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/** Detray library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2022-2024 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
#pragma once
9+
10+
// Project include(s)
11+
#include "detray/core/detail/multi_store.hpp"
12+
#include "detray/core/detail/single_store.hpp"
13+
#include "detray/definitions/algebra.hpp"
14+
#include "detray/definitions/containers.hpp"
15+
#include "detray/definitions/indexing.hpp"
16+
#include "detray/geometry/detail/surface_descriptor.hpp"
17+
#include "detray/geometry/mask.hpp"
18+
#include "detray/geometry/shapes/concentric_cylinder2D.hpp"
19+
#include "detray/geometry/shapes/rectangle2D.hpp"
20+
#include "detray/geometry/shapes/ring2D.hpp"
21+
#include "detray/geometry/shapes/trapezoid2D.hpp"
22+
#include "detray/materials/material_map.hpp"
23+
#include "detray/materials/material_slab.hpp"
24+
#include "detray/navigation/accelerators/brute_force_finder.hpp"
25+
#include "detray/navigation/accelerators/surface_grid.hpp"
26+
27+
namespace detray {
28+
29+
/// Defines the data types needed for the toy detector
30+
template <concepts::algebra algebra_t>
31+
struct odd_metadata {
32+
33+
/// Define the algebra type for the geometry and navigation
34+
using algebra_type = algebra_t;
35+
using scalar_t = dscalar<algebra_type>;
36+
37+
/// Mask to (next) volume link: next volume(s)
38+
using nav_link = std::uint_least16_t;
39+
40+
/// Mask types
41+
using rectangle = mask<rectangle2D, algebra_type, nav_link>;
42+
using trapezoid = mask<trapezoid2D, algebra_type, nav_link>;
43+
// using cylinder = mask<cylinder2D, algebra_type, nav_link>; // beampipe
44+
using cylinder_portal = mask<concentric_cylinder2D, algebra_type, nav_link>;
45+
using disc_portal = mask<ring2D, algebra_type, nav_link>;
46+
47+
/// Material types
48+
using slab = material_slab<scalar_t>;
49+
50+
// Cylindrical material grid
51+
template <typename container_t>
52+
using cylinder_map_t =
53+
material_map<algebra_type, concentric_cylinder2D, container_t>;
54+
55+
// Disc material grid
56+
template <typename container_t>
57+
using disc_map_t = material_map<algebra_type, ring2D, container_t>;
58+
59+
// Rectangular material grid
60+
template <typename container_t>
61+
using rectangular_map_t =
62+
material_map<algebra_type, rectangle2D, container_t>;
63+
64+
/// Surface grid types (regular, open binning)
65+
/// @{
66+
67+
// Surface grid definition: bin-content: darray<sf_descriptor, 1>
68+
template <typename axes_t, typename bin_entry_t, typename container_t>
69+
using surface_grid_t =
70+
grid<algebra_type, axes_t, bins::static_array<bin_entry_t, 1>,
71+
simple_serializer, container_t, false>;
72+
73+
// cylindrical grid for the barrel layers
74+
template <typename bin_entry_t, typename container_t>
75+
using cylinder_sf_grid =
76+
surface_grid_t<axes<concentric_cylinder2D>, bin_entry_t, container_t>;
77+
78+
// disc grid for the endcap layers
79+
template <typename bin_entry_t, typename container_t>
80+
using disc_sf_grid = surface_grid_t<axes<ring2D>, bin_entry_t, container_t>;
81+
82+
/// @}
83+
84+
/// How to store coordinate transform matrices
85+
template <template <typename...> class vector_t = dvector>
86+
using transform_store =
87+
single_store<dtransform3D<algebra_type>, vector_t, geometry_context>;
88+
89+
/// Mask type ids
90+
enum class mask_ids : std::uint_least8_t {
91+
e_rectangle2 = 0,
92+
e_trapezoid2 = 1,
93+
e_portal_cylinder2 = 2,
94+
e_portal_ring2 = 3,
95+
e_cylinder2 = 2,
96+
};
97+
98+
/// How to store masks
99+
template <template <typename...> class vector_t = dvector>
100+
using mask_store =
101+
regular_multi_store<mask_ids, empty_context, dtuple, vector_t,
102+
rectangle, trapezoid, cylinder_portal, disc_portal>;
103+
104+
/// Material type ids
105+
enum class material_ids : std::uint_least8_t {
106+
e_disc2_map = 0u,
107+
e_concentric_cylinder2_map = 1u,
108+
e_rectangle2_map = 2u,
109+
e_slab = 3u,
110+
e_none = 4u,
111+
};
112+
113+
/// How to store materials
114+
template <typename container_t = host_container_types>
115+
using material_store =
116+
multi_store<material_ids, empty_context, dtuple,
117+
grid_collection<disc_map_t<container_t>>,
118+
grid_collection<cylinder_map_t<container_t>>,
119+
grid_collection<rectangular_map_t<container_t>>,
120+
typename container_t::template vector_type<slab>>;
121+
122+
/// How to link to the entries in the data stores
123+
using transform_link = typename transform_store<>::link_type;
124+
using mask_link = typename mask_store<>::single_link;
125+
using material_link = typename material_store<>::single_link;
126+
/// Surface type used for sensitives, passives and portals
127+
using surface_type =
128+
surface_descriptor<mask_link, material_link, transform_link, nav_link>;
129+
130+
/// Portals and passives in the brute froce search, sensitives in the grids
131+
enum geo_objects : std::uint_least8_t {
132+
e_portal = 0,
133+
e_passive = 0,
134+
e_sensitive = 1,
135+
e_size = 2,
136+
e_all = e_size,
137+
};
138+
139+
/// Acceleration data structures
140+
enum class accel_ids : std::uint_least8_t {
141+
e_brute_force = 0, // test all surfaces in a volume (brute force)
142+
e_disc_grid = 1, // endcap
143+
e_cylinder2_grid = 2, // barrel
144+
e_default = e_brute_force,
145+
};
146+
147+
/// One link for portals/passives and one sensitive surfaces
148+
using object_link_type =
149+
dmulti_index<dtyped_index<accel_ids, dindex>, geo_objects::e_size>;
150+
151+
/// How to store the acceleration data structures
152+
template <typename container_t = host_container_types>
153+
using accelerator_store = multi_store<
154+
accel_ids, empty_context, dtuple,
155+
brute_force_collection<surface_type, container_t>,
156+
grid_collection<disc_sf_grid<surface_type, container_t>>,
157+
grid_collection<cylinder_sf_grid<surface_type, container_t>>>;
158+
159+
/// Volume search grid
160+
template <typename container_t = host_container_types>
161+
using volume_finder =
162+
grid<algebra_type,
163+
axes<cylinder3D, axis::bounds::e_open, axis::irregular,
164+
axis::regular, axis::irregular>,
165+
bins::single<dindex>, simple_serializer, container_t>;
166+
};
167+
168+
} // namespace detray
Lines changed: 4 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,19 @@
11
/** Detray library, part of the ACTS project (R&D line)
22
*
3-
* (c) 2022-2024 CERN for the benefit of the ACTS project
3+
* (c) 2022-2025 CERN for the benefit of the ACTS project
44
*
55
* Mozilla Public License Version 2.0
66
*/
77

88
#pragma once
99

1010
// Project include(s)
11-
#include "detray/core/detail/multi_store.hpp"
12-
#include "detray/core/detail/single_store.hpp"
13-
#include "detray/definitions/algebra.hpp"
14-
#include "detray/definitions/containers.hpp"
15-
#include "detray/definitions/indexing.hpp"
16-
#include "detray/geometry/detail/surface_descriptor.hpp"
17-
#include "detray/geometry/mask.hpp"
18-
#include "detray/geometry/shapes/concentric_cylinder2D.hpp"
19-
#include "detray/geometry/shapes/rectangle2D.hpp"
20-
#include "detray/geometry/shapes/ring2D.hpp"
21-
#include "detray/geometry/shapes/trapezoid2D.hpp"
22-
#include "detray/materials/material_map.hpp"
23-
#include "detray/materials/material_slab.hpp"
24-
#include "detray/navigation/accelerators/brute_force_finder.hpp"
25-
#include "detray/navigation/accelerators/surface_grid.hpp"
11+
#include "detray/detectors/odd_metadata.hpp"
2612

2713
namespace detray {
2814

29-
/// Defines the data types needed for the toy detector
15+
/// Defines the data types needed for the toy detector (same as ODD)
3016
template <concepts::algebra algebra_t>
31-
struct toy_metadata {
32-
33-
/// Define the algebra type for the geometry and navigation
34-
using algebra_type = algebra_t;
35-
using scalar_t = dscalar<algebra_type>;
36-
37-
/// Mask to (next) volume link: next volume(s)
38-
using nav_link = std::uint_least16_t;
39-
40-
/// Mask types
41-
using rectangle = mask<rectangle2D, algebra_type, nav_link>;
42-
using trapezoid = mask<trapezoid2D, algebra_type, nav_link>;
43-
// using cylinder = mask<cylinder2D, algebra_type, nav_link>; // beampipe
44-
using cylinder_portal = mask<concentric_cylinder2D, algebra_type, nav_link>;
45-
using disc_portal = mask<ring2D, algebra_type, nav_link>;
46-
47-
/// Material types
48-
using slab = material_slab<scalar_t>;
49-
50-
// Cylindrical material grid
51-
template <typename container_t>
52-
using cylinder_map_t =
53-
material_map<algebra_type, concentric_cylinder2D, container_t>;
54-
55-
// Disc material grid
56-
template <typename container_t>
57-
using disc_map_t = material_map<algebra_type, ring2D, container_t>;
58-
59-
// Rectangular material grid
60-
template <typename container_t>
61-
using rectangular_map_t =
62-
material_map<algebra_type, rectangle2D, container_t>;
63-
64-
/// Surface grid types (regular, open binning)
65-
/// @{
66-
67-
// Surface grid definition: bin-content: darray<sf_descriptor, 1>
68-
template <typename axes_t, typename bin_entry_t, typename container_t>
69-
using surface_grid_t =
70-
grid<algebra_type, axes_t, bins::static_array<bin_entry_t, 1>,
71-
simple_serializer, container_t, false>;
72-
73-
// cylindrical grid for the barrel layers
74-
template <typename bin_entry_t, typename container_t>
75-
using cylinder_sf_grid =
76-
surface_grid_t<axes<concentric_cylinder2D>, bin_entry_t, container_t>;
77-
78-
// disc grid for the endcap layers
79-
template <typename bin_entry_t, typename container_t>
80-
using disc_sf_grid = surface_grid_t<axes<ring2D>, bin_entry_t, container_t>;
81-
82-
/// @}
83-
84-
/// How to store coordinate transform matrices
85-
template <template <typename...> class vector_t = dvector>
86-
using transform_store =
87-
single_store<dtransform3D<algebra_type>, vector_t, geometry_context>;
88-
89-
/// Mask type ids
90-
enum class mask_ids : std::uint_least8_t {
91-
e_rectangle2 = 0,
92-
e_trapezoid2 = 1,
93-
e_portal_cylinder2 = 2,
94-
e_portal_ring2 = 3,
95-
e_cylinder2 = 2,
96-
};
97-
98-
/// How to store masks
99-
template <template <typename...> class vector_t = dvector>
100-
using mask_store =
101-
regular_multi_store<mask_ids, empty_context, dtuple, vector_t,
102-
rectangle, trapezoid, cylinder_portal, disc_portal>;
103-
104-
/// Material type ids
105-
enum class material_ids : std::uint_least8_t {
106-
e_disc2_map = 0u,
107-
e_concentric_cylinder2_map = 1u,
108-
e_rectangle2_map = 2u,
109-
e_slab = 3u,
110-
e_none = 4u,
111-
};
112-
113-
/// How to store materials
114-
template <typename container_t = host_container_types>
115-
using material_store =
116-
multi_store<material_ids, empty_context, dtuple,
117-
grid_collection<disc_map_t<container_t>>,
118-
grid_collection<cylinder_map_t<container_t>>,
119-
grid_collection<rectangular_map_t<container_t>>,
120-
typename container_t::template vector_type<slab>>;
121-
122-
/// How to link to the entries in the data stores
123-
using transform_link = typename transform_store<>::link_type;
124-
using mask_link = typename mask_store<>::single_link;
125-
using material_link = typename material_store<>::single_link;
126-
/// Surface type used for sensitives, passives and portals
127-
using surface_type =
128-
surface_descriptor<mask_link, material_link, transform_link, nav_link>;
129-
130-
/// Portals and passives in the brute froce search, sensitives in the grids
131-
enum geo_objects : std::uint_least8_t {
132-
e_portal = 0,
133-
e_passive = 0,
134-
e_sensitive = 1,
135-
e_size = 2,
136-
e_all = e_size,
137-
};
138-
139-
/// Acceleration data structures
140-
enum class accel_ids : std::uint_least8_t {
141-
e_brute_force = 0, // test all surfaces in a volume (brute force)
142-
e_disc_grid = 1, // endcap
143-
e_cylinder2_grid = 2, // barrel
144-
e_default = e_brute_force,
145-
};
146-
147-
/// One link for portals/passives and one sensitive surfaces
148-
using object_link_type =
149-
dmulti_index<dtyped_index<accel_ids, dindex>, geo_objects::e_size>;
150-
151-
/// How to store the acceleration data structures
152-
template <typename container_t = host_container_types>
153-
using accelerator_store = multi_store<
154-
accel_ids, empty_context, dtuple,
155-
brute_force_collection<surface_type, container_t>,
156-
grid_collection<disc_sf_grid<surface_type, container_t>>,
157-
grid_collection<cylinder_sf_grid<surface_type, container_t>>>;
158-
159-
/// Volume search grid
160-
template <typename container_t = host_container_types>
161-
using volume_finder =
162-
grid<algebra_type,
163-
axes<cylinder3D, axis::bounds::e_open, axis::irregular,
164-
axis::regular, axis::irregular>,
165-
bins::single<dindex>, simple_serializer, container_t>;
166-
};
17+
using toy_metadata = odd_metadata<algebra_t>;
16718

16819
} // namespace detray

0 commit comments

Comments
 (0)