Hi all,
I would like to share some practical experience on importing CAD geometries into Geant4, as this question comes up regularly and many of the problems are not obvious from the documentation.
Geant4 official guidance
Geant4 already provides some guidance on importing CAD models as tessellated shapes. It is highly recommended to read this first:
https://geant4-userdoc.web.cern.ch/UsersGuides/ForApplicationDeveloper/html/Detector/Geometry/geomSolids.html#importing-cad-models-as-tessellated-shapes
Reading CAD files into Geant4
In the FCC software stack (DD4hep-based), the external library ASSIMP (Open Asset Import Library) is used to read CAD / mesh formats. ASSIMP supports more than 30 formats (e.g. STL, OBJ, PLY, etc.) and provides access to triangulated meshes, which can be directly converted into G4TessellatedSolid.
A concrete example of how ASSIMP is used to build a tessellated solid for Geant4/DD4hep can be found here:
https://github.com/AIDASoft/DD4hep/blob/master/DDCAD/src/ASSIMPReader.cpp
Other tools such as CADMESH may also work, but I do not have direct experience with them.
Common issues (often caused by CAD export settings)
In practice, many geometry problems originate on the CAD side, not in Geant4 itself. Some key points to check:
1. Mesh tolerance / facet size
Geant4 uses a numerical tolerance of of 1e-9 mm (1e-3 nm). If the CAD mesh is generated with a tolerance smaller than this, Geant4 may discard facets, leading to holes, navigation errors, or stuck tracks.
Recommendation:
Ask CAD designers to export meshes with a minimum point spacing / tolerance of at least the Geant4 numerical tolerance. See next point.
2. Mesh complexity and performance considerations
Issues frequently arise when CAD meshes are generated with excessively fine tolerances, leading to an unnecessarily large number of facets. This can:
-
Significantly degrade navigation and tracking performance.
-
Increase the probability of numerical edge cases (e.g. degenerate or nearly coplanar facets).
-
Make geometry debugging considerably harder.
Practical recommendation:
Use the coarsest mesh tolerance that still preserves the relevant mechanical details of the detector.
3. Shared edges
Geant4 does not allow an edge of a tessellated solid to be shared by more than two facets. This situation often arises when CAD volumes are designed to touch exactly along an edge.
Recommendation:
Introduce a small protrusion or leave a gap larger than the meshing tolerance between adjacent volumes before meshing.
4. Incorrectly oriented faces
Wrongly oriented facets are a known issue and still occur in complex CAD-derived geometries. This is often due to how the CAD software generates the triangulation.
Debugging tip:
Run geantinos through the geometry. When a geantino hits a badly oriented facet, the Geant4 navigator reports an error including the position. This information is usually sufficient for CAD designers to locate and fix the problematic region.
Validation strategy
Before running physics simulations, it is highly recommended to validate imported CAD geometries using geantinos. Since geantino runs are fast, using a large number (e.g. 1e7–1e8) is feasible and helps identify problematic regions early. Providing precise locations of errors to CAD designers greatly reduces iteration cycles.
Final recommendation: CAD for validation, simplified geometry for production
While importing full CAD geometries can be very useful for validation and debugging, it is often not optimal for large-scale production simulations.
In many cases, a better strategy is to:
-
Use the CAD-based tessellated geometry to validate dimensions, overlaps, and clearances.
-
Then re-implement an approximate version of the detector using simpler Geant4 solids (e.g.
G4Box,G4Tubs,G4Cons), preserving the relevant material budget and dimensions.
This approach typically results in:
-
Much better navigation and tracking performance.
-
More robust geometries with fewer numerical corner cases.
-
Easier maintenance and long-term stability of the simulation.
The CAD geometry can still be kept as a reference and validation tool, but simplified shapes are often preferable for production runs.
Call to the community
@evc @agheata @gcosmo and other users with experience in this topic – if you have additional tips or corrections, it would be great to hear from you. Do you consider this information useful enough to be added to the official Geant4 documentation?
I hope these notes are useful to others facing similar issues. Feedback and contributions are very welcome!
Best regards,
Alvaro