GDML
This example reads geometries from GDML files, the geometry exchange format of Geant4 and ROOT: test geometries of the shapes and the CMS detector (2018). It draws them and makes X-ray images of the muon barrel of CMS.
You can also download this example as a Jupyter notebook and a plain Julia source file.
Table of contents
Loading the modules
using Geom4hep
using CairoMakie: CairoMakie, Figure, LScene, Axis, heatmap!, DataAspectThe GDML files are in the examples directory of the package
gdmldir = joinpath(pkgdir(Geom4hep), "examples");Reading a GDML file
read_gdml returns the world volume of the file, with the floating point type given as second argument (Float64 by default). Lengths are converted to mm and angles to radians.
world = read_gdml(joinpath(gdmldir, "polyhedra.gdml"))
[(d.volume.label, d.volume.shape) for d in world.daughters]3-element Vector{Tuple{String, Geom4hep.Polyhedra{Float64, VS} where VS<:AbstractVector{Geom4hep.PolyhedraSection{Float64}}}}:
("HRCF", Polyhedra{Float64}(nsides = 18, nsections = 5, z = [-1158.0, -695.4000000000001, -649.7800000000002, 60.789999999999964, 91.27000000000044, 1141.0], ϕ₀ = 6.1086523819801535, Δϕ = 6.283185307179586))
("STEP", Polyhedra{Float64}(nsides = 8, nsections = 2, z = [-300.0, 0.0, 300.0], ϕ₀ = 0.0, Δϕ = 6.283185307179586))
("OPEN", Polyhedra{Float64}(nsides = 6, nsections = 2, z = [-200.0, 0.0, 200.0], ϕ₀ = 0.7853981633974483, Δϕ = 4.71238898038469))The volumes can be drawn as any other hierarchy of volumes. By default they are colored by the dominant element of their material, and the volumes of gases and vacuum are not drawn. The volumes of polycones.gdml (the envelopes of the CMS electromagnetic calorimeter) are all of air, so they are colored by their level in the hierarchy instead (colorby=:level).
fig = Figure(size=(1000, 400))
draw!(LScene(fig[1, 1], show_axis=false), world)
draw!(LScene(fig[1, 2], show_axis=false), read_gdml(joinpath(gdmldir, "torus.gdml")))
draw!(LScene(fig[1, 3], show_axis=false), read_gdml(joinpath(gdmldir, "polycones.gdml")); colorby=:level)
figThe CMS detector
The GDML file of CMS (2018) has about 20 000 placements of 3 800 volumes. It is read in a few seconds. Here in single precision, as needed on GPUs.
cms = read_gdml(joinpath(gdmldir, "cms2018.gdml"), Float32)
[d.volume.label for d in cms[1].daughters][1:8]8-element Vector{String}:
"CMStoZDC0x7f4a9a83fd80"
"CMStoZDC0x7f4a9a83fd80"
"ZDCtoFP4200x7f4a9a83fe00"
"ZDCtoFP4200x7f4a9a83fe00"
"Tracker0x7f4a9a83fe80"
"CALO0x7f4a9a83ff00"
"MUON0x7f4a9a758080"
"BEAM0x7f4a9a83ff80"The muon system is the 7th daughter of the CMS envelope, and the muon barrel the first daughter of the muon system. world_volume puts it into a world box of its own. The volumes are colored by the dominant element of their material: the iron of the return yoke in red, and the copper of the cables in blue. The volumes of air (the wheels and the chambers, which contain the yoke) are not drawn. With clip=:xy the quadrant x > 0, y > 0 is cut away (as in Geant4.jl), to see the inside: each volume that crosses the quadrant is drawn as its subtraction with a large box.
barrel = cms[1, 7, 1]
world = world_volume(barrel)
fig = Figure(size=(1200, 600))
draw!(LScene(fig[1, 1], show_axis=false), world; maxlevel=4)
draw!(LScene(fig[1, 2], show_axis=false), world; maxlevel=4, clip=:xy)
figThe GDML Rendering example renders the CMS and LHCb detectors with GLMakie.
X-ray images
The X-ray images integrate the density along rays parallel to the axes, through the navigator of the closed geometry model.
model = close_geometry(world)GeometryModel{Float32}(volumes=701, placements=6885, materials=17, shape kinds=4, shapes=438, bvh nodes=2287, csg components=87)fig = Figure(size=(1000, 500))
for axis in (3, 1)
u, v, image, nsteps = xray(model, axis, 300)
heatmap!(Axis(fig[1, axis == 3 ? 1 : 2], title="rays along $("xyz"[axis])", aspect=DataAspect()),
u, v, image, colormap=:grayC)
end
figThe whole detector (world_volume(cms) instead of the barrel) can be processed in the same way. It is much faster on a GPU: see examples/XRay.jl in the repository.
This page was generated using Literate.jl.