|
DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
|
Zero-scaffolding Compile-time pluggable geometry modules, with run-time selectable recipes for Geant4.
GeoModules is designed for frequently modified detector geometries, especially for HPGe where samples and supporters may change frequently.
It now uses zero app-side scaffolding, no customization of DetectorConstruction.hh/cc is usually needed. You only need to use the provided one for most uses, and add content in your own pluggable modules.
Geometries are modular with runtime recipe selection. Materials are selected by user defined name or NIST name.
It is now packaged with DLG4::VolumeBuilders and uses features from it.
The system uses compile-time pluggable, runtime selectable .cc and .inc (essentially headers) to add materials, modular geometry parts, and "context" variables that connect them.
At present individual modules are not runtime-selectable, in part because not all define a world volume. Instead pre-defined recipes are runtime selectable. Most samples will define a short recipe that simply lists the materials module, detector module, and supporter modules it needs. Run-time definable recipes could be added if there's a motivation.
There is no difference between module types. They are just code, but most are meant to define a geometry element. They simply define a constructor MyModuleGeoModule::MyModuleGeoModule()
and are available to all modules via the context object.
provides access to myvar. This allows global interface variables for aligning modules.
Materials can be defined in any module, such as MaterialsGeoModule.cc/inc, and are now accessed in other modules via their Geant global material names through VBHelpers::GetMaterial("some_name")
Nist materials are also retrieved the same way using the NIST material name. Often this can
Every .cc gets a .inc that declares its module name.
Every .inc can optionally declare a recipe that can be selected at runtime. Recipes are just a small bit of code, but generally just call module constructoin to construct
The interface has been completely refactored and, for the user, simplified.
You can define:
In the geometry modules (the .cc files) there is a "context" variable passed. The geometries have access to the shared variable names and world pointer through that.
context->your_shared_variable context->Colors.white
context->SetWorldVolume(logical_volume_ptr) context->GetWorldVolume()
You can also call other modules through context->ConstructGeoModule("SomeModule")
Methods are made available via the VolumeBuilders libraries, particularly through the VBHelpers alias:
VBHelpers::GetMaterial("copper") VBHelpers::GetElement("Pb") VBHelpers::CopyMaterial("old","new",density,unit)
GetMaterial now operates by name and accepts NIST material names.
Methods are made available via the VolumeBuilders libraries, particularly through the VBHelpers alias:
There are a few details to the format of the module file, particularly how they include their own .inc files.
While the library is very modular now, still the best way to use it is just to copy the demo folder to your project and change the VolumeBuilders and GeoModules directories in the CMakeLists.txt to point back to the respective sources.
The provided demo has no physics or tracking included, just geometry, but demo/src/core/TheSimulation.cc (and .hh) is ready to add them and comes with examples commented out for CupSim usage.
You can copy and .cc and .inc in the demo/src/Geometries directories and just rename things. I'll go over that below. But easiest is to just open the demo/CMakeLists.txt as a project in Clion (it's already configured for Clion, which has free versions) and go to
You will get a box asking for three inputs which you can fill out like this example:
1) MODULE_BASE_NAME : TestBox 2) GEORECIPE_NAME : TestBox 3) MATERIAL : G4_CONCRETE
The material can be one you defined in the materials file or a NIST one like here. No quotes.
Click ok and you're done. You can modify the shape to your desire. This just creates code for a simple one-material starter shape, but you can customize from there. That part is your job. The recipe loads materials, a world geometry and your shape.
Choose VBDemo command_line from the build panel on the upper right and click play to compile and run it. (Be sure to read the BuildInstructions first to setup your environment variables.)
Alternatively, select VBDemo gui < demo/input.txt This takes input from the mentioned file. By default it this is setup to run the assembly demo.
We'll get to details of modules, but at least one must call
The default build as a WorldGeoModule included so you just have to modify it and include it in your recipes.
Other modules position parts relative to the shared variables you define in the file described above. So you can assign values to a vector in your world module and position things based on that in your sample module.
Here's an example X-header and recipe produced by the present version of the Clion template:
These examples can and will change, so best to check the latest demo code.
The MODULE_BASE defines the base name of the class for your module, which as written because BoxTestGeoModules. A recipe is defined for "BoxTest" (you can name it differently and even add multiple recipes). It selects a Materials module, the "World" module and the "BoxExample" module that will be provided in the corresponding cc file.
And here is the cc code for the same:
The preamble, up to the Construct() signature, has a mostly required format. You can add more includes or such of course. But BoxTest include and Construct call must be defined correctly. The Clion template does it though.
This example uses VolumeBuilders to define the geometry. It has many advantages, but even if you define it traditionally, VB provides helpers to get the material names etc.
Copy the vb_user_setup_general.sh script to your home directory and edit the geant and root paths. These should point to the top of the install directory for geant, build directory for root, as in the example file.
You do NOT need to source this before running an IDE or such. The CMakeLists.txt siphons variables from it. That's (one reason) why it must be in the right place.
From there you can use the Clion instructions above for development. For building from CLI, for cluster use, etc... the instructions are essentially the same as for DLG4::VolumeBuilders and in fact you can build the demo from either the top VolumeBuilders directory/config or from the demo directory and build config.
From either your VolumeBuilders install or VolumeBuilders/demo do:
To run the demo, it's best if your geant has OGL and QT support through:
The library will be in build/libVolumeBuilders.a and the demo will be in build/bin/Demo