Public API
Documentation of the public interface of Geom4hep.jl.
Index
Geom4hep.UnitsGeom4hep.AbstractMaterialGeom4hep.AbstractShapeGeom4hep.AssemblyGeom4hep.BooleanIntersectionGeom4hep.BooleanSubtractionGeom4hep.BooleanUnionGeom4hep.BoxGeom4hep.ConeGeom4hep.CutTubeGeom4hep.ElementGeom4hep.EllipsoidGeom4hep.EllipticalTubeGeom4hep.ExtrudedSolidGeom4hep.GenericTrapGeom4hep.GeometryModelGeom4hep.IsotopeGeom4hep.MaterialGeom4hep.MultiUnionGeom4hep.NavStateGeom4hep.NoShapeGeom4hep.ParaGeom4hep.PlacedVolumeGeom4hep.Point2Geom4hep.Point3Geom4hep.PolyconeGeom4hep.PolyhedraGeom4hep.ShapeBenchmarkGeom4hep.ShapeRefGeom4hep.SphereGeom4hep.TessFacetGeom4hep.TessellatedGeom4hep.TetGeom4hep.TorusGeom4hep.Transformation3DGeom4hep.TrapGeom4hep.TrdGeom4hep.TubeGeom4hep.Vector3Geom4hep.VolumeGeom4hep.add_component!Geom4hep.atoms_per_volumeGeom4hep.benchmark_shapeGeom4hep.capacityGeom4hep.close_geometryGeom4hep.compute_stepGeom4hep.csg_meshGeom4hep.distance_to_inGeom4hep.distance_to_outGeom4hep.drawGeom4hep.draw!Geom4hep.draw_distance_to_inGeom4hep.draw_distance_to_outGeom4hep.electron_densityGeom4hep.estimate_capacityGeom4hep.estimate_surfaceGeom4hep.extentGeom4hep.in_worldGeom4hep.insideGeom4hep.locateGeom4hep.mass_fractionsGeom4hep.material_indexGeom4hep.mean_excitation_energyGeom4hep.nist_elementGeom4hep.nist_materialGeom4hep.nist_material_namesGeom4hep.normalGeom4hep.nuclear_interaction_lengthGeom4hep.place_daughter!Geom4hep.push_toleranceGeom4hep.radiation_lengthGeom4hep.read_gdmlGeom4hep.safety_to_inGeom4hep.safety_to_outGeom4hep.shape_callGeom4hep.shape_to_meshGeom4hep.surfaceGeom4hep.toleranceGeom4hep.vecgeom_suiteGeom4hep.world_volumeGeom4hep.xrayGeometryBasics.mesh
Points, vectors and transformations
Geom4hep.Point3 — Type
Point3{T}(x, y, z)A position in 3D space. Point3 - Point3 gives a Vector3, Point3 ± Vector3 a Point3.
Geom4hep.Vector3 — Type
Vector3{T}(x, y, z)A displacement or direction in 3D space. Transformations rotate but do not translate vectors.
Geom4hep.Point2 — Type
Point2{T}(x, y)A position in 2D space (used for computations in the transverse plane).
Geom4hep.Transformation3D — Type
Transformation3D{T}(dx, dy, dz)
Transformation3D{T}(dx, dy, dz, rotation::Rotation{3})
Transformation3D{T}(dx, dy, dz, rotx, roty, rotz)
Transformation3D{T}(rotation::RotMatrix3, translation::Vector3)
one(Transformation3D{T})Placement of a daughter volume (or of a boolean operand) in the frame of its mother. Applied to a point of the mother, it gives the point in the frame of the daughter: t * p == R * (p - t) for a translation t = (dx, dy, dz) and rotation R, so Transformation3D{T}(dx, dy, dz) places the daughter at (dx, dy, dz). Rotations come from Rotations.jl (RotXYZ, RotZXZ, ...); the angles rotx, roty, rotz build a RotXYZ. p * t applies the inverse transformation, and t1 * t2 composes them.
Shapes
Geom4hep.AbstractShape — Type
AbstractShape{T<:AbstractFloat}Supertype of all the shapes (solids). T is the floating point type of the shape parameters and of the points and directions it works with (Float64 or Float32). A shape is defined in its own frame; it is positioned in a mother volume by the transformation of its placement.
Every shape implements inside, distance_to_in, distance_to_out, safety_to_in, safety_to_out, normal, extent, capacity and surface, and the mesh functions used for drawing (coordinates, faces, mesh).
Geom4hep.Box — Type
Box{T}(x, y, z)Box (as G4Box) centred at the origin, with half lengths x, y and z along the axes. box[i] gives the half length along axis i.
Geom4hep.Trd — Type
Trd{T}(x1, x2, y1, y2, z)Trapezoid (as G4Trd) with half length z along the z axis and rectangular faces at -z and +z with half lengths (x1, y1) and (x2, y2).
Geom4hep.Trap — Type
Trap{T}(z, θ, ϕ, y1, x1, x2, α1, y2, x3, x4, α2)
Trap{T}(x1, x2, y1, y2, z)General trapezoid (as G4Trap), with half length z. The faces at -z and +z are trapezoids with sides parallel to the x axis:
- at -z: half length
y1along y, half lengthsx1andx2of the sides at y = -y1 and y = +y1, andα1the angle to the y axis of the line joining the centres of these sides; - at +z: the same with
y2,x3,x4andα2.
θ and ϕ are the polar and azimuthal angles of the line joining the centres of the two faces. The second form is a right trapezoid with rectangular faces of half lengths (x1, y1) at -z and (x2, y2) at +z.
Geom4hep.Tube — Type
Tube{T}(rmin, rmax, z, ϕ₀, Δϕ)Tube or tube segment (as G4Tubs) along the z axis: inner and outer radii rmin and rmax (rmin = 0 for a solid cylinder), half length z, and the ϕ range [ϕ₀, ϕ₀ + Δϕ] (0, 2π for a full tube).
Geom4hep.Cone — Type
Cone{T}(rmin1, rmax1, rmin2, rmax2, z, ϕ₀, Δϕ)Cone or cone segment (as G4Cons) along the z axis, with half length z: inner and outer radii rmin1 and rmax1 at -z, rmin2 and rmax2 at +z, and the ϕ range [ϕ₀, ϕ₀ + Δϕ].
Geom4hep.CutTube — Type
CutTube{T}(rmin, rmax, z, ϕ₀, Δϕ, bottom_normal::Vector3, top_normal::Vector3)
CutTube{T}(rmin, rmax, z, ϕ₀, Δϕ, θb, ϕb, θt, ϕt)Tube segment cut by two planes (as G4CutTubs): a Tube with radii rmin, rmax and ϕ range [ϕ₀, ϕ₀ + Δϕ] whose ends are the planes through (0, 0, -z) and (0, 0, z) with outward normals bottom_normal and top_normal, given as vectors or by their polar and azimuthal angles.
Geom4hep.Sphere — Type
Sphere{T}(rmin, rmax, ϕ₀=0, Δϕ=2π, θ₀=0, Δθ=π)Spherical shell or section (as G4Sphere): inner and outer radii rmin and rmax, the ϕ range [ϕ₀, ϕ₀ + Δϕ] and the polar range [θ₀, θ₀ + Δθ]. Sphere{T}(0, r) is a full ball (G4Orb).
Geom4hep.EllipticalTube — Type
EllipticalTube{T}(dx, dy, dz)Tube with an elliptical cross section (as G4EllipticalTube): x²/dx² + y²/dy² <= 1 and |z| <= dz (half length).
Geom4hep.Ellipsoid — Type
Ellipsoid{T}(ax, by, cz, zbottom=0, ztop=0)Ellipsoid (as G4Ellipsoid) with semi-axes ax, by and cz, cut by the planes z = zbottom and z = ztop. As in Geant4, when both cuts are 0 the ellipsoid is not cut, and the cuts beyond the semi-axis cz are ignored.
Geom4hep.Torus — Type
Torus{T}(rmin, rmax, rtor, ϕ₀=0, Δϕ=2π)Torus or torus segment (as G4Torus): the points at a distance between rmin and rmax from the circle of radius rtor in the xy plane (the swept radius), within the ϕ range [ϕ₀, ϕ₀ + Δϕ].
Geom4hep.Polycone — Type
Polycone{T}(rmin::Vector, rmax::Vector, z::Vector, ϕ₀, Δϕ)Polycone (as G4Polycone, z-planes form): a sequence of cone sections along z. z are the z planes (increasing) and rmin, rmax the inner and outer radii at each plane; the ϕ range is [ϕ₀, ϕ₀ + Δϕ].
Geom4hep.Polyhedra — Type
Polyhedra{T}(nsides, rmin, rmax, z, ϕ₀=0, Δϕ=2π)Polyhedra (as G4Polyhedra) with nsides sides in the ϕ range [ϕ₀, ϕ₀+Δϕ] and z planes z with inner and outer radii rmin and rmax. The radii are the distances from the z axis to the sides.
Geom4hep.Para — Type
Para{T}(x, y, z, α, θ, ϕ)Parallelepiped (as G4Para) with half lengths x, y and z, α the angle to the y axis of the faces at -x and x, and θ and ϕ the polar and azimuthal angles of the line joining the centres of the faces at -z and z. The constructor returns the equivalent Trap.
Geom4hep.Tessellated — Type
Tessellated{T}(vertices, faces)Solid bounded by a closed surface of planar facets (as G4TessellatedSolid). vertices are points (anything with 3 coordinates) and faces are triangles or quadrilaterals (planar), given by the indices of their vertices. The faces are oriented outwards when the shape is built, whatever the order of their vertices, and the faces with no area are dropped. The surface can be non-convex.
It is also the shape built by ExtrudedSolid, GenericTrap and Tet.
Geom4hep.TessFacet — Type
Triangular facet of a Tessellated shape: vertices a, b, c and the outward unit normal n.
Geom4hep.ExtrudedSolid — Type
ExtrudedSolid{T}(polygon, sections)
ExtrudedSolid{T}(polygon, z, off1=(0, 0), scale1=1, off2=(0, 0), scale2=1)Extruded solid (as G4ExtrudedSolid): the polygon polygon (a vector of (x, y) vertices, convex or not, in any order), placed at the z planes of sections, a vector of (z, (x0, y0), scale) with non-decreasing z: the vertices of a section are (x0, y0) .+ scale .* (x, y). The second form has two sections, at -z and z (half length), with the offsets and scales of G4ExtrudedSolid.
The constructor returns a Tessellated shape, exact (the faces are planar).
Geom4hep.GenericTrap — Type
GenericTrap{T}(z, vertices; nslices=0)Generic trapezoid (as G4GenericTrap): the solid between the quadrilaterals at -z and z (half length) given by the 8 (x, y) vertices, the 4 at -z followed by the 4 at z, in the same order (clockwise or anticlockwise). Vertices can coincide (e.g. a triangle or a segment at one end). The side faces are planar or twisted (bilinear surfaces). The twisted faces are approximated by nslices slices along z, each made of 4 triangles around the centre of the slice: the volume is exact, and the surface deviates from the exact one by less than twist / (16 nslices), where twist is the difference of the vectors of the edges of the face at -z and z. By default, enough slices for a deviation below 1e-3 of the size of the solid (at most 64).
The constructor returns a Tessellated shape.
Geom4hep.Tet — Type
Tet{T}(a, b, c, d)Tetrahedron (as G4Tet) with the vertices a, b, c and d (anything with 3 coordinates), in any order. The constructor returns a Tessellated shape.
Geom4hep.BooleanUnion — Type
BooleanUnion(left, right, placement=one(Transformation3D{T}))
BooleanSubtraction(left, right, placement=one(Transformation3D{T}))
BooleanIntersection(left, right, placement=one(Transformation3D{T}))Boolean combination of two shapes (as G4UnionSolid, G4SubtractionSolid and G4IntersectionSolid): the points in left or right, in left and not in right, or in both. right is placed in the frame of left with placement (as in place_daughter!). The operands can themselves be boolean shapes.
Geom4hep.BooleanSubtraction — Type
See BooleanUnion.
Geom4hep.BooleanIntersection — Type
See BooleanUnion.
Geom4hep.MultiUnion — Type
MultiUnion{T}(shapes, transformations)
MultiUnion{T}()Union of any number of shapes (as G4MultiUnion), each one placed with its transformation (as in place_daughter!). Components can be added with add_component!.
Geom4hep.add_component! — Function
add_component!(mu::MultiUnion, shape, transformation=one(Transformation3D{T}))Add a component to a MultiUnion built by the user.
Geom4hep.NoShape — Type
NoShape{T}()Placeholder for a shape that is not supported (e.g. read from GDML), and the shape of an Assembly. It contains no points.
Shape functions
Geom4hep.inside — Function
inside(shape, point) -> kInside | kSurface | kOutsideClassify point (in the frame of shape) as inside the shape, on its surface (within tolerance) or outside it. The constants kInside, kSurface and kOutside are exported.
Geom4hep.distance_to_in — Function
distance_to_in(shape, point, dir)Distance along the unit direction dir from point, outside shape, to where the ray enters the shape. Inf if the ray misses the shape. A point on the surface moving into the shape gets 0. The result is not meaningful for points inside the shape (see inside).
Geom4hep.distance_to_out — Function
distance_to_out(shape, point, dir)Distance along the unit direction dir from point, inside shape, to where the ray leaves the shape. A point on the surface moving out of the shape gets 0, and a point outside the shape gets a negative value (-1).
Geom4hep.safety_to_in — Function
safety_to_in(shape, point)Lower bound of the distance from point, outside shape, to the shape (an isotropic safe step). It is cheaper to compute than the exact distance; it is ≤ 0 for points inside the shape.
Geom4hep.safety_to_out — Function
safety_to_out(shape, point)Lower bound of the distance from point, inside shape, to its surface (an isotropic safe step). It is ≤ 0 for points outside the shape.
Geom4hep.normal — Function
normal(shape, point)Unit outward normal of shape at point. On edges and corners the normals of the surfaces meeting there are averaged. Returns the zero vector if point is not on the surface (within tolerance).
Geom4hep.extent — Function
extent(shape) -> (lower::Point3, upper::Point3)Corners of an axis-aligned box, in the frame of the shape, that contains it.
Geom4hep.capacity — Function
capacity(shape)Volume of the shape. For shapes without a closed formula it is estimated by sampling (see estimate_capacity).
Geom4hep.surface — Function
surface(shape)Area of the surface of the shape. For shapes without a closed formula it is estimated by sampling (see estimate_surface).
Geom4hep.estimate_capacity — Function
estimate_capacity(shape; npoints=1_000_000)Volume of shape estimated from the fraction of npoints sample points of its bounding box that are inside it. Typical accuracy with the default number of points is better than 0.1%.
Geom4hep.estimate_surface — Function
estimate_surface(shape; npoints=1_000_000)Surface area of shape estimated by sampling segments of length δ with isotropic directions in its (enlarged) bounding box of volume V: the probability that a segment crosses the surface is A δ / 2V. Typical accuracy with the default number of points is about 1% (slightly underestimated).
Geom4hep.tolerance — Function
tolerance(T=Float64)Thickness of the surfaces of the shapes: a point closer than tolerance(T)/2 to a surface is on the surface (inside returns kSurface). 1 nm for Float64 and 1 µm for Float32 (lengths in mm).
Geom4hep.push_tolerance — Function
push_tolerance(T=Float64)Distance by which the navigator pushes a point beyond a boundary it has reached, to locate it in the next volume.
Materials
Geom4hep.Isotope — Type
Isotope{T}(name, Z, N, A=0; m=0)Isotope with atomic number Z, number of nucleons N, molar mass A (e.g. A=55.935g/mole) and isomer level m (as G4Isotope). When A is 0, the mass of the isotope is taken from the NIST data (natural isotopes only).
Geom4hep.Element — Type
Element{T}(name, symbol, Z, A)
Element{T}(name, symbol, isotopes, abundances)Chemical element (as G4Element), given by its effective atomic number Z and molar mass A (e.g. Element{T}("Iron", "Fe", 26, 55.845g/mole)), or by its isotopes and their relative abundances in number of atoms. In the first case, the isotopes are the natural ones of the NIST data.
The element holds the derived quantities of Geant4: the effective number of nucleons N (A/(g/mole)), the Coulomb correction fcoulomb and the Tsai factor radtsai of the radiation length (per atom, in mm²), and the mean excitation energy I of the NIST data. See also nist_element.
Geom4hep.Material — Type
Material{T}(name, Z, A, density; state=:undefined, temperature=NTP_Temperature, pressure=STP_Pressure, I=0)
Material{T}(name, density; atoms=[...] or fractions=[...], state=:undefined, temperature=NTP_Temperature, pressure=STP_Pressure, I=0, formula="")
Material{T}(name; density=0, state=:undefined, temperature=NTP_Temperature, pressure=STP_Pressure)Material of a volume (as G4Material), with the quantities in the units of Geom4hep.Units (the density in g/cm³, e.g. 7.874g/cm3 or 7.874).
- A material of a single element of atomic number
Zand molar massA(the element is the NIST one forZ, as in Geant4). - A compound given by the number of atoms of each element in a molecule,
atoms=[element => n, ...](asG4Material::AddElementByNumberOfAtoms), e.g.atoms=[H => 2, O => 1]. - A mixture given by mass fractions of elements and materials,
fractions=[element_or_material => w, ...](asAddElementByMassFractionandAddMaterial), e.g.fractions=[N => 0.755, O => 0.232, Ar => 0.013]orfractions=[water => 0.5, lead => 0.5]. The fractions are normalized, with a warning when their sum differs from 1 by more than 0.1%. - A material with only a density (no composition), e.g. for the navigation or
xraywith the mass thickness: its radiation and interaction lengths areNaN(Infif the density is 0).
state is :solid, :liquid, :gas or :undefined (solid above 10 mg/cm³, gas below). I is the mean excitation energy; when it is 0, it is computed from the ones of the elements (as G4IonisParamMat). The derived quantities are computed as in Geant4: see radiation_length, nuclear_interaction_length, electron_density, mean_excitation_energy, mass_fractions and atoms_per_volume. See also nist_material.
Geom4hep.nist_element — Function
nist_element([T=Float64,] symbol_or_Z)Element of the NIST data with its natural isotopic composition (as G4NistManager::FindOrBuildElement), given by its symbol (e.g. "Fe") or atomic number. The elements are built once and shared.
Geom4hep.nist_material — Function
nist_material([T=Float64,] name)Material of the NIST data of Geant4 (as G4NistManager::FindOrBuildMaterial), e.g. "G4_WATER", "G4_AIR", "G4_Si" or "G4_PbWO4": the simple materials G4_<symbol> of the elements, and a selection of compounds and HEP materials (see nist_material_names). The materials are built once and shared.
Geom4hep.nist_material_names — Function
Names of the materials available with nist_material.
Geom4hep.radiation_length — Function
Radiation length of a Material (mm), with Tsai's formula as in Geant4.
Geom4hep.nuclear_interaction_length — Function
Nuclear interaction length of a Material (mm), with the approximation of Geant4 (35 g/cm² × A^(2/3) per atom).
Geom4hep.electron_density — Function
Number of electrons per volume (1/mm³) of a Material.
Geom4hep.mean_excitation_energy — Function
Geom4hep.mass_fractions — Function
Mass fractions of the elements of a Material.
Geom4hep.atoms_per_volume — Function
Number of atoms per volume (1/mm³) of each element of a Material.
Volumes
Geom4hep.Volume — Type
Volume{T}(label, shape, material)A logical volume (as G4LogicalVolume): a shape filled with a material, with daughter volumes placed inside it with place_daughter!. The same volume can be placed several times. vol[i] gives the volume of the i-th daughter, and vol[i, j, ...] goes down the hierarchy.
Geom4hep.PlacedVolume — Type
PlacedVolume{T}A daughter volume placed in its mother: the volume and its transformation (see place_daughter!). The daughters of a Volume are in its daughters vector.
Geom4hep.place_daughter! — Function
place_daughter!(mother::Volume, placement::Transformation3D, daughter::Volume)Place daughter inside mother with placement (see Transformation3D: Transformation3D{T}(x, y, z) places the daughter at (x, y, z) of the mother). The daughter must be contained in the mother and must not overlap the other daughters (this is not checked). Placing an Assembly places each of its volumes. Returns mother.
Geom4hep.Assembly — Type
Assembly{T}(label)A group of volumes without a shape of its own (as G4AssemblyVolume): its daughters are placed directly in the mother when the assembly is placed with place_daughter!.
Geom4hep.world_volume — Function
world_volume(vol::Volume)vol if its label is "world"; otherwise a new world volume (a box of vacuum 5% larger than vol) with vol placed in it.
Geom4hep.read_gdml — Function
read_gdml(filename, T=Float64) -> Volume{T}Read a GDML file and return its world volume, with the shapes, materials and volume hierarchy it defines, with floating point type T. Lengths are converted to mm and angles to radians. Solids that are not supported are replaced by NoShape with a warning (and the booleans with such an operand are reduced to their valid operand). The numeric attributes can be expressions with the constants, variables, quantities and expressions of <define>, the units and the math functions.
Geometry model and navigation
Geom4hep.close_geometry — Function
close_geometry(world::Volume; bvh_threshold=4, with_index=false)Build a flat GeometryModel from a hierarchy of volumes. Boolean shapes are converted to CSG programs over primitive shapes, and a BVH is built for the daughters of volumes with more than bvh_threshold daughters.
With with_index=true it returns (model, index), where index.volumes[i] is the Volume stored as volume i of the model (the volume field of a NavState) and index.materials[i] the Material with index i (see material_index). This allows to attach information to the volumes and materials of the model, e.g. by name.
Geom4hep.GeometryModel — Type
GeometryModelFlat representation of a geometry, built with close_geometry. D is 1 if the model has boolean (CSG) shapes, 0 otherwise. Use Adapt.adapt(backend, model) to move it to a GPU.
Geom4hep.ShapeRef — Type
Reference to a shape of a GeometryModel: kind (index in the tuple of shape arrays) and index.
Geom4hep.shape_call — Function
shape_call(f, model::GeometryModel, ref::ShapeRef, args...)Call the shape function f (e.g. inside, distance_to_in, extent) on the shape ref of model without dynamic dispatch: shape_call(inside, model, model.volumes[1].shape, point).
Geom4hep.NavState — Type
NavState{T}Position of a point in the volume hierarchy of a GeometryModel: the current volume, the path of placements from the world (depth levels) and the transformation from the global frame to the frame of the current volume. volume == 0 when the point is outside the world. blocked is the daughter (placement) of the current volume that has just been left, if any (see compute_step).
Geom4hep.locate — Function
locate(model::GeometryModel, point) -> NavStateFind the deepest volume containing the (global) point.
Geom4hep.compute_step — Function
compute_step(model::GeometryModel, state, point, dir, step_limit) -> (step, new_state)Distance from the global point along dir to the next boundary (or step_limit), and the state after crossing it. The new state is computed for the point pushed slightly beyond the boundary.
Geom4hep.in_world — Function
in_world(state::NavState)true if the point of state is inside the world volume.
Geom4hep.material_index — Function
material_index(model::GeometryModel, state::NavState)Index in model.materials of the material of the current volume of state.
Geom4hep.xray — Function
xray(model::GeometryModel, axis, npixels; quantity=:mass, backend=CPU(), maxsteps=10_000, launch_time=0.5)X-ray image of the world volume of model with rays parallel to axis (1, 2 or 3 for x, y, z): the quantity integrated along each ray,
:mass: the mass thickness (density × length, in g/cm³ × mm);:radlen: the material budget in radiation lengths (length/X0);:nuclen: the material budget in nuclear interaction lengths (length/λ).
The materials without composition (only a density) have unknown X0 and λ, which make the pixels that cross them NaN (the ones with zero density, e.g. a vacuum, do not contribute). npixels is the number of pixels along the first transverse axis. Returns (u, v, image, nsteps) with the pixel centres along the two transverse axes, the image and the number of navigation steps per pixel.
backend is a KernelAbstractions backend: CPU() (Julia threads), or a GPU backend such as MetalBackend() or CUDABackend() (the model is copied to the device). On GPUs the image is computed in several kernel launches, each one taking about launch_time seconds: a long-running kernel on a GPU that also drives a display is aborted by the operating system (e.g. macOS error "Impacting Interactivity").
Visualization
Geom4hep.draw — Function
draw(object; kwargs...)Draw a shape, volume hierarchy or BVH in a new figure. Requires a Makie backend (e.g. using GLMakie). The keyword arguments are:
wireframe=false: draw the edges of the faces instead of the surfaces (shapes and volumes);bvh=falseandmaxlevel=999: draw the bounding boxes of the daughters, and the depth of the volume hierarchy to draw (volumes);colorby=:material(volumes,:levelwithwireframe=true): the color of the volumes is the one of the dominant element of their material (largest mass fraction), and the volumes of materials lighter than 0.25 g/cm³ (gases, vacuum) are not drawn; materials with only a density are grey. Withcolorby=:level, all the volumes are drawn with grey levels by depth;clip=:none(volumes)::x,:y,:z,:xy,:xz,:yzor:xyzcuts away the region of the world with positive coordinates along these axes (e.g. the quadrant x > 0, y > 0 for:xy), to see the inside of the geometry: the volumes that cross it are drawn as their subtraction with a box (withcsg_mesh), and the ones inside it are not drawn;- any other keyword argument is passed to the Makie plotting function (
mesh!,wireframe!orlinesegments!), and overrides the defaults, e.g.draw(shape; color=:blue),draw(shape; color=(:red, 0.5))ordraw(shape; wireframe=true, linewidth=2).
The world volume itself is not drawn. The meshes of all the volumes are merged into a single mesh with the colors at the vertices (each volume is meshed once, whatever its number of placements), so that Makie draws large hierarchies with a single plot.
Geom4hep.draw! — Function
draw!(scene, object; kwargs...)Draw a shape, volume hierarchy, AABB or BVH into an existing LScene. Requires a Makie backend. The keyword arguments are as for draw.
Geom4hep.draw_distance_to_in — Function
draw_distance_to_in(shape, npoints)Figure with the points where random rays from outside shape enter it (a test of distance_to_in). Requires a Makie backend.
Geom4hep.draw_distance_to_out — Function
draw_distance_to_out(shape, npoints)Figure with the points where random rays from inside shape leave it (a test of distance_to_out). Requires a Makie backend.
GeometryBasics.mesh — Function
mesh(shape::AbstractShape; facets=64)Surface mesh of a shape (GeometryBasics.Mesh), e.g. for visualization. facets controls the number of segments used to approximate curved surfaces.
Geom4hep.shape_to_mesh — Function
shape_to_mesh(shape; facets=64, transformation=one(Transformation3D{T}), crease_angle=π/6)Surface mesh of shape (a GeometryBasics.Mesh of triangles) with per-vertex normals, for smooth shading of curved surfaces and sharp shading of edges.
The mesh of mesh is processed as follows:
- duplicated vertices are merged, and the faces are split into triangles;
- the triangles are oriented outwards, using the
normalof the shape at their vertices (and, where the vertices are not on the surface, their neighbouring triangles); - the normal of a vertex is the average of the normals of the triangles around it that make an angle smaller than
crease_anglewith each other. A vertex on a hard edge is duplicated, one copy for each side of the edge. When the normal of the shape at a vertex agrees with this average, it is used instead, which is exact on curved surfaces.
facets is the number of segments of the curved surfaces, and transformation is applied to the mesh (it places the shape in the frame of its mother, as in place_daughter!).
Geom4hep.csg_mesh — Function
csg_mesh(shape; facets=64, eps=1e-7)Surface mesh of a boolean shape (or a MultiUnion) computed with boolean operations on the meshes of its operands (BSP trees, as csg.js). eps is the tolerance to classify vertices on the planes of the polygons, relative to the size of the shape.
The polygons of the result are cleaned up:
- the vertices are welded, and the T-junctions (vertices of a polygon in the middle of an edge of its neighbour, left by the splits) are removed by inserting these vertices in the edges;
- the connected coplanar fragments are merged into faces (with holes), and the vertices in the middle of straight edges are removed, and the faces are triangulated again.
The mesh is closed: every edge is shared by two triangles, in opposite directions.
Benchmarks
Geom4hep.ShapeBenchmark — Type
ShapeBenchmark{T}(name, shape, world, placement, npoints, nrep, vecgeom)A benchmark case: a shape placed with placement (a Transformation3D as given to place_daughter!: Transformation3D(x, y, z) puts the shape at (x, y, z)) in a world box of half lengths world, timed for npoints points and nrep repetitions. vecgeom is the VecGeom benchmark program (and options) with the same setup.
Geom4hep.benchmark_shape — Function
benchmark_shape(shape; world, placement, npoints=1024, nrep=4, inside_bias=0.5, toin_bias=0.8,
modes=(:shape, :model), seed=1, verbose=true)
benchmark_shape(b::ShapeBenchmark; kwargs...)Time the shape functions as the shape benchmarks of VecGeom: inside, contains, distance_to_in, safety_to_in, distance_to_out and safety_to_out (see the header of Benchmark.jl). world are the half lengths of the world box (default: 4 times the extent of the shape) and placement the placement of the shape in it (as for place_daughter!). Returns a vector of named tuples (case, T, mode, op, npoints, nrep, seconds, ns), with the total time and the time per call in ns.
Geom4hep.vecgeom_suite — Function
vecgeom_suite(T=Float64)The shape benchmarks of VecGeom (test/benchmark/*Benchmark.cpp) for the shapes of Geom4hep, with the same shape parameters, world box, placement, number of points and repetitions as the defaults of the VecGeom programs. Not reproduced: the corner-defined Trapezoid (type 1) and the (r,z) Polycone (type 4).
Units
Geom4hep.Units — Module
Geom4hep.UnitsSystem of units, with the conventions of Geant4 (CLHEP) for lengths (mm), angles (radian), energies (MeV) and temperatures (kelvin). Masses are in mg, so that densities are in g/cm³ (g/cm3 == 1) and molar masses in mg/mole (g/mole == 1000). Use as using Geom4hep.Units; Box{Float64}(1cm, 2cm, 3cm) or density = 7.87g/cm3.
It also defines the physical constants used for the materials: Avogadro, k_Boltzmann, amu, fine_structure_const, classic_electr_radius, the standard temperature and pressure (STP_Temperature, NTP_Temperature, STP_Pressure) and universe_mean_density, with the values of CLHEP.