Physicists usually spend most of the time developing the mass model when developing a Geant4-based Monte Carlo simulation package. For simple geometries, it is relatively easy to describe them using CGS models. However, this becomes almost impossible for complex geometries. G4CAD is a free, open-source FreeCAD workbench. With the workbench and FreeCAD, users can
- import and edit CAD files
- set materials and material management. Users can define their own materials and set the predefined materials for different solids
- add simple CGS models
- set the tessellation tolerance for each individual solid
- convert models to GDML files
G4CAD also provides other tools useful for creating mass models and converting CAD files to GDML, like measuring tools, tools to find/remove small solids.
Make sure you have already installed FreeCAD 0.19 or 0.20 (should also work with v0.17 and v0.18).
- To install it on Linux, execute the following commands:
git clone --depth 1 https://github.com/drhlxiao/g4cad
mkdir -p ~/.FreeCAD/Mod
cp -r g4cad/g4cad ~/.FreeCAD/Mod
- To install it on Windows, please follow the steps as follows:
- Download the source code https://github.com/drhlxiao/g4cad/archive/refs/heads/main.zip
- unzip file downloaded file
- copy g4cad/g4cad to <FREECAD_INSTALLATION_PATH>/Mod. You should have user_materials.json in the folder <FREECAD_INSTALLATION_PATH>/Mod/g4cad/
More information about installing FreeCAD workbenchs can be found at https://wiki.freecadweb.org/Installing_more_workbenches
- Open FreeCAD
- Activate the workbench "G4CAD" in FreeCAD (View->Workbench->G4CAD)
- Import a CAD file
- Click the icon "add world volume" in the G4CAD toolbar to add a world volume
- Select a solid or multiple solids, set material(s)
- If not set, the default material G4_Al is used when exporting
- Adding more materials: open the file user_materials.json in the source code folder, open it with a text editor, add materials to it, validate the json file before saving it.
- Select the solids in the tree view to be exported
- click the button "Export solids to GDML files" in the toolbar to generate GDML files
- Only visible solids will be exported
- If everything goes well, GDML files will be written to gdml/ in your specified folder and a log file will also be created.
- Reading the exported GDML files in Geant4 Here is a code snippet
G4VPhysicalVolume* DetectorConstruction::Construct(){
G4String worldGdmlFilename="<GDML_PATH>/gdml/World.gdml"
G4GDMLParser parser;
parser.Read(worldGdmlFilename);
world = parser.GetWorldVolume();
//other code goes here
return world;
}
Extended services related to this tool can be provided by SE2S Ltd.
SE2S GmbH is a Swiss-based high-tech company with over 30 years of experience in radiation qualification, particle detection, and data analysis. Its founders gathered profound expertise in radiation qualification and testing, electronics design, hardware and software development, and data evaluation for applications in aerospace. SE2S GmbH offers next-generation services and products in the following fields:
- Radiation detection systems
- Radiation analysis software and services
- Radiation qualification and testing services
For more info about SE2S, please visit: https://se2s.ch
If you use G4CAD in your work, please use the following citation,
@software{g4cad,
author = {Hualin Xiao, Wojtek Hajdas},
title = {{G4CAD - A FreeCAD Workbench for converting CAD
files to gdml}},
month = sep,
year = 2022,
publisher = {Zenodo},
version = {v1.0},
doi = {10.5281/zenodo.7085915},
url = {https://doi.org/10.5281/zenodo.7085915}
}
- If you find issues, please create an github issue on this repo
- If you want to contribute code, please create a pull request
- send an email to [email protected] if you have anything else
We also developed a web-based CAD to GDML converter. URL: http://polar.psi.ch/cadmc/converter/