Home » Projects » Unified Solids - New software library for modeling of solids in Geant4 and ROOT

Unified Solids - New software library for modeling of solids in Geant4 and ROOT


The geometrical models in Geant4 and ROOT are used to describe the experimental setups in simulation or reconstruction programs and include the implementation of geometrical solid primitives as building blocks for the description of complex detector setups. These include a large collection of 3D primitives, ranging from simple shapes like boxes, tubes or cones to more complex ones, also allowing for Boolean combinations among these.


From experience from the past decade, it is estimated that a good fraction (not less than 70-80%) of the effort spent on code maintenance in the geometry modeler is devoted to improve the implementation of the geometrical primitives. This code, written in C++, provides all the algorithms required for tracking efficiently particles in detectors simulation with high level of precision. In order to reduce the effort required for support and maintenance, and converge on a unique solution based on high quality code, a project to create a new software library of geometrical primitives has started within the EU-AIDA initiative. The new library is meant to unify and in future replace the existing implementations in Geant4 and ROOT, improving wherever possible both reliability and CPU performance of the implemented algorithms. The new library is realized as a standalone package, not depending on any external package, and the interfaces have been defined by combining the APIs provided in Geant4 and ROOT to guarantee full compatibility. Simple adapter classes have been implemented to allow the use of the new optimized code from Geant4 and ROOT.


Reviewed implementation of several solids using existing algorithms, Box, Orb, Trapezoid, Sphere, Tube, Cone, Generic trapezoid, Tetrahedron, Arbitrary Trapezoid, have been already completed. In some cases, new algorithms have been designed and implemented, as for the case of “Polycone”, a geometrical shape rather heavily used in most experimental setups, and for which considerable performance improvement has been achieved.

“Multi-Union” is a new structure implementing a composite set of solids (several or many). It differentiates from the simple technique based on Boolean union of solids traditionally implemented in Geant4 or ROOT, with the aim to provide excellent scalability on the number of constituent solids. Multi-Union introduces the use of voxelization as optimization technique to improve speed and scalability; this consists in adopting 3D space partition for fast localization of the components, and allows for the ability to determine which constituent solids are localized in a determined portion of the partitioned space, which is candidate for intersection with the particle being tracked. This allows to achieve logarithmic scalability vs. linear provided with the old algorithms, resulting in significant performance speedup especially for the case where a large number of constituent solids is considered.

The new library also provides a new implementation of Tessellated Solid, originally implemented in Geant4. A Tessellated Solid consists in a composition of connected triangular and quadrangular facets forming any kind of regular or irregular shape as a closed solid. The original implementation suffered of low performance, mostly due to the fact that no spatial optimization for the composing facets was used. The new implementation adopts spatial partitioning for the facets into 3D grid of voxels in a similar way characterizing the Multi-Union. Such technique allowed reaching factor thousands speedup for relatively complex structures of the order of 100k facets, like the LHCb VELO foil description imported from CAD drawings and used as test case. The memory footprint for the Tessellated Solid has also been reduced by roughly 25-30%. Thanks to all this, it is now possible to use tessellated geometries for tuning the precision in simulation by increasing the meshes resolution, something that was not possible before.


One fundamental aspect of the procedure adopted for implementing the new library was to put in place a comprehensive testing suite, to systematically monitor correctness and performance of the new algorithms in comparison to the corresponding implementations in Geant4 and ROOT. Tests to verify the scalability of the algorithms as a function of the complexity of the geometrical setup have been also deployed. These include the development of a tool, Unified Solid Batch Test, designed to measure computing performance and compare the results, and used to identify differences between implementations and identify areas of improvement. Some existing tests from the Geant4 and ROOT suites are also used and adapted. The Unified Solid Batch Test allows concurrent testing of the new code in parallel with existing Geant4 and ROOT algorithms and can compare performance and output values in either numerical or visual form. The testing suite has also become useful to identify potential problems in the existing Geant4 and ROOT geometry code.

Future work

It is in plan to complete the implementation of the remaining shapes needed to be included in the Unified Solids library. Adapter classes have been implemented, allowing for easy future integration of Unified Solids in Geant4 and ROOT in their next versions.


The people involved in the Unified Solids project are: John Apostolakis, Gabriele Cosmo, Marek Gayer, Andrei Gheata, Tatiana Nikitina and Pere Mato Vila.

More information