Skip to content

Commit 736fbb8

Browse files
committed
Implement pyhon generators for metadata
1 parent ce40d8c commit 736fbb8

14 files changed

+1140
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Detray library, part of the ACTS project (R&D line)
2+
#
3+
# (c) 2025 CERN for the benefit of the ACTS project
4+
#
5+
# Mozilla Public License Version 2.0
6+
7+
from impl import metadata, metadata_generator
8+
from impl import Shape, Material, Accelerator
9+
from utils import (
10+
add_calorimeter_defaults,
11+
add_silicon_tracker_defaults,
12+
add_telescope_detector_defaults,
13+
add_wire_chamber_defaults,
14+
)
15+
16+
from itk_metadata import add_itk_types
17+
from odd_metadata import add_odd_types
18+
19+
# --------------------------------------------------------------------------
20+
# Generate the default metadata type (can represent all detectors)
21+
# --------------------------------------------------------------------------
22+
23+
24+
def __main__():
25+
# Collect the types required for a detector that can hold all detector types
26+
md = metadata("default_new")
27+
28+
# Make sure all of the defaults are added
29+
add_silicon_tracker_defaults(md, use_mat_maps=True, use_homogeneous_mat=True)
30+
add_calorimeter_defaults(md, use_mat_maps=True, use_homogeneous_mat=True)
31+
add_telescope_detector_defaults(md, use_mat_maps=True, use_homogeneous_mat=True)
32+
add_wire_chamber_defaults(md, use_mat_maps=True, use_homogeneous_mat=True)
33+
34+
# Make sure all detectors can be represented by this metadata
35+
add_odd_types(md)
36+
add_itk_types(md)
37+
38+
#
39+
# Add some special types (e.g. for detector R&D)
40+
#
41+
42+
# Special surface types
43+
# md.add_sensitive(Shape.UNBOUNDED) # Always hit the surface
44+
# md.add_sensitive(Shape.UNMASKED)
45+
46+
# Add more material types
47+
# Material maps on non-concentric cylinders
48+
# md.add_material(Material.CYLINDER_MAP2D)
49+
50+
# Add surface acceleration structures
51+
# md.add_accel_struct(Accelerator.CYLINDER_GRID3D)
52+
# md.add_accel_struct(Accelerator.CUBOID_GRID3D)
53+
54+
# Dump the metadata to header file
55+
metadata_generator(md)
56+
57+
58+
if __name__ == "__main__":
59+
__main__()

detectors/python/impl/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .metadata_generator import (
2+
metadata,
3+
metadata_generator,
4+
)
5+
from .definitions import Algebra, Shape, Material, Accelerator
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Detray library, part of the ACTS project (R&D line)
2+
#
3+
# (c) 2025 CERN for the benefit of the ACTS project
4+
#
5+
# Mozilla Public License Version 2.0
6+
7+
# Project includes
8+
from .type_helpers import cpp_class
9+
10+
# python includes
11+
from enum import Enum
12+
13+
14+
""" Fundamental types """
15+
16+
17+
class Type(Enum):
18+
SINGLE = "float"
19+
DOUBLE = "double"
20+
UINT_8 = "std::uint8_t"
21+
UINT_16 = "std::uint16_t"
22+
UINT_32 = "std::uint32_t"
23+
UINT_64 = "std::uint64_t"
24+
UINT_128 = "std::uint128_t"
25+
UINT_LEAST_8 = "std::uint_least8_t"
26+
UINT_LEAST_16 = "std::uint_least16_t"
27+
UINT_LEAST_32 = "std::uint_least32_t"
28+
UINT_LEAST_64 = "std::uint_least64_t"
29+
UINT_LEAST_128 = "std::uint_least128_t"
30+
31+
def __str__(self) -> str:
32+
return self.value
33+
34+
35+
""" Available linear algebra bachends """
36+
37+
38+
class Algebra(Enum):
39+
ANY = "concepts::algebra algebra_t"
40+
ARRAY = "detray::array"
41+
EIGEN = "detray::eigen"
42+
FASTOR = "detray::fastor"
43+
SMATRIX = "detray::smatrix"
44+
VC_AOS = "detray::vc_aos"
45+
VC_SOA = "detray::vc_soa"
46+
47+
def __str__(self) -> str:
48+
return self.value
49+
50+
51+
""" Available geometric shape types """
52+
53+
54+
class Shape:
55+
# ITk stereo annulus (r, phi)
56+
ANNULUS = cpp_class(specifier="detray::annulus2D")
57+
# 2D cylinder, at the origin, no rotation, single inters. sol. (r*phi, z)
58+
CONCENTRIC_CYLINDER = cpp_class(specifier="detray::concentric_cylinder2D")
59+
# 3D cubiod (x, y, z)
60+
CUBOID = cpp_class(specifier="detray::cuboid3D")
61+
# 2D cylinder (r*phi, z)
62+
CYLINDER2D = cpp_class(specifier="detray::cylinder2D")
63+
# 3D cylinder (r, phi, z)
64+
CYLINDER3D = cpp_class(specifier="detray::cylinder3D")
65+
# line, square cross sec, (+-r, z)
66+
DRIFT_CELL = cpp_class(specifier="detray::line_square")
67+
# line, circular cross sec, (+-r, z)
68+
STRAW_TUBE = cpp_class(specifier="detray::line_circular")
69+
# 2D rectangle (x, y)
70+
RECTANGLE = cpp_class(specifier="detray::rectangle2D")
71+
# 2D ring / disc (r, phi)
72+
RING = cpp_class(specifier="detray::ring2D")
73+
# 2D trapezoid (x, y)
74+
TRAPEZOID = cpp_class(specifier="detray::trapezoid2D")
75+
# Mask of any shape (to be added as 'param'), always 'inside'= true
76+
UNBOUNDED = cpp_class(specifier="detray::unbounded")
77+
# No shape
78+
UNMASKED = cpp_class(specifier="detray::unmasked")
79+
80+
81+
""" Available material types """
82+
83+
84+
class Material:
85+
# Slab of material of given thickness
86+
SLAB = cpp_class(specifier="detray::material_slab")
87+
# Material with round cross sec, of given r
88+
ROD = cpp_class(specifier="detray::material_rod")
89+
# Raw material type, used e.g. for homogeneous volume material
90+
RAW = cpp_class(specifier="detray::material")
91+
# Surface material map, annulus shape 2D
92+
ANNULUS_MAP2D = cpp_class(
93+
specifier="detray::material_map", param={"shape": Shape.ANNULUS}
94+
)
95+
# Surface material map, concentric cyl.
96+
CONCENTIRC_CYLINDER_MAP2D = cpp_class(
97+
specifier="detray::material_map", param={"shape": Shape.CONCENTRIC_CYLINDER}
98+
)
99+
# Surface material map, cylindrical 2D
100+
CYLINDER_MAP2D = cpp_class(
101+
specifier="detray::material_map", param={"shape": Shape.CYLINDER2D}
102+
)
103+
# Volume material map, cylindrical 3D
104+
CYLINDER_MAP3D = cpp_class(
105+
specifier="detray::material_map", param={"shape": Shape.CYLINDER3D}
106+
)
107+
# Volume material map, cuboid 3D
108+
CUBOID_MAP3D = cpp_class(
109+
specifier="detray::material_map", param={"shape": Shape.CUBOID}
110+
)
111+
# Surface material map, rectangular 2D
112+
RECTANGLE_MAP2D = cpp_class(
113+
specifier="detray::material_map", param={"shape": Shape.RECTANGLE}
114+
)
115+
# Surface material map, disc 2D
116+
DISC_MAP2D = cpp_class(
117+
specifier="detray::material_map", param={"shape": Shape.RING}
118+
)
119+
# Surface material map, trapezoidal 2D
120+
TRAPEZOID_MAP2D = cpp_class(
121+
specifier="detray::material_map", param={"shape": Shape.TRAPEZOID}
122+
)
123+
124+
125+
""" Available surface/volume acceleration structure types """
126+
127+
128+
class Accelerator:
129+
# Test all registered surfaces
130+
BRUTE_FORCE = cpp_class(specifier="detray::brute_force")
131+
# Surface grid, cylindrical 2D (barrel)
132+
CONCENTRIC_CYLINDER_GRID2D = cpp_class(
133+
specifier="detray::spatial_grid", param={"shape": Shape.CONCENTRIC_CYLINDER}
134+
)
135+
# Surface grid, cylindrical 2D (barrel)
136+
CYLINDER_GRID2D = cpp_class(
137+
specifier="detray::spatial_grid", param={"shape": Shape.CYLINDER2D}
138+
)
139+
# Surface grid, cylindrical 3D (barrel)
140+
CYLINDER_GRID3D = cpp_class(
141+
specifier="detray::spatial_grid", param={"shape": Shape.CYLINDER3D}
142+
)
143+
# Surface grid, disc (endcap)
144+
DISC_GRID2D = cpp_class(
145+
specifier="detray::spatial_grid", param={"shape": Shape.RING}
146+
)
147+
# Surface grid, reactangular (telescope)
148+
RECTANGLE_GRID2D = cpp_class(
149+
specifier="detray::spatial_grid", param={"shape": Shape.RECTANGLE}
150+
)
151+
# Surface grid, cuboid 3D (telescope)
152+
CUBOID_GRID3D = cpp_class(
153+
specifier="detray::spatial_grid", param={"shape": Shape.CUBOID}
154+
)

0 commit comments

Comments
 (0)