35.4. Define Materials
Table of Contents
Connecting Materials to the Final Project
In the final project you already defined a geometry and you know what each volume represents in the real detector. Now you need to tell Geant4 what each volume is made of. This step controls how particles slow down, interact and deposit energy in your simulation, so material choices are as important as geometry and physics lists.
In this chapter you do not learn all material features in Geant4 again. Instead, you focus on how to design and implement the materials specifically for your complete project, and how to keep them consistent and easy to maintain.
In Geant4, every volume must have a material assigned. Forgetting to set a material, or using an unrealistic one, will usually give physically meaningless results, even if the simulation appears to run.
Planning a Material Model for Your Detector
Before writing any code, translate your conceptual detector into a small list of distinct materials. Walk through each part of your geometry and write down what it is physically made of and how detailed you need to be.
The typical categories are:
Detector media. Active detector regions such as scintillator crystals, semiconductor sensors, gas volumes, water phantoms and biological tissue. These are where you expect to record energy deposition or dose, so material realism matters most here.
Structural materials. Supports, housings, cryostats, shielding blocks and mechanical parts. These often use metals such as aluminum and steel or dense materials such as lead and concrete. They mainly affect scattering and attenuation.
World and fill materials. The space outside your detector, often air, vacuum or water for phantoms. This choice strongly affects how particles travel into and out of your detector.
Electronics and readout. Light guides, optical couplers and detector windows, for example glass or plastics. In a basic final project you might model them with a simple generic material or omit them entirely.
When planning, decide which materials require realistic composition and which can be approximated. For example, a clinical water phantom usually must be close to ICRU standard water, but an aluminum support can almost always be standard Al from the NIST database.
A smaller, well chosen set of materials is better than many poorly defined ones. Use detailed compositions only when they affect your observables, such as dose or detector response.
Using NIST Materials vs Custom Definitions
Geant4 provides a large material database via G4NistManager. For the final project, this should be your first choice whenever possible. It saves time and avoids mistakes in elemental composition and density.
Typical calls in your detector construction look like:
auto nist = G4NistManager::Instance();
G4Material* worldMat = nist->FindOrBuildMaterial("G4_AIR");
G4Material* leadMat = nist->FindOrBuildMaterial("G4_Pb");
G4Material* siliconMat = nist->FindOrBuildMaterial("G4_Si");Use NIST materials when:
You need standard elements like Al, Cu, Si, Pb or Fe.
You need common compounds like water or air.
You simulate shielding, structural parts or standard detector materials that have NIST entries.
You must define a custom material when:
Your material is a specific compound or mixture that is not in the NIST list, such as a custom scintillator, a plastic with a given hydrogen fraction or a biological tissue with a known elemental composition.
You want to tune the density or composition for a particular study such as varying mixture fractions.
Your application includes materials defined by mass fractions or by number of atoms per molecule that differ from any NIST entry.
In a final project, a typical compromise is:
Use NIST for world, shields, standard metals, water and silicon.
Define custom materials only for the detector active medium or specialized tissues.
Implementing Materials in Your DetectorConstruction
For the final project, it is important to keep your material definitions in a clear and centralized place. The usual pattern is to put them inside your DetectorConstruction class, in helper methods that are called before you build logical volumes.
A simple structure is:
class DetectorConstruction : public G4VUserDetectorConstruction
{
public:
DetectorConstruction();
virtual ~DetectorConstruction();
virtual G4VPhysicalVolume* Construct();
private:
void DefineMaterials();
void DefineDetectorMaterials();
G4Material* fWorldMaterial;
G4Material* fDetectorMaterial;
// Add more material pointers as needed
};
In Construct(), you call your helper function first:
G4VPhysicalVolume* DetectorConstruction::Construct()
{
DefineMaterials();
DefineDetectorMaterials();
// Use fWorldMaterial, fDetectorMaterial, ...
// to build logical volumes here
return physicalWorld;
}This pattern has several advantages for a final project:
All material definitions are in one place. This makes later documentation and validation easier.
You store pointers to the key materials as class members, so they are easy to reuse in geometry, sensitive detectors or other components.
You can later connect configuration options or macros to select different materials without refactoring the entire geometry.
Never define the same material twice with different densities or compositions under the same name. Reuse pointers, or define them once and share them across your geometry.
Choosing Materials for Different Parts of the Final Project
The specific materials you choose will depend on the kind of detector you are building in your final project, but the basic strategy is always similar. Below are some common cases you may adapt.
World and surrounding environment. For a generic lab detector, choose air:
auto nist = G4NistManager::Instance();
fWorldMaterial = nist->FindOrBuildMaterial("G4_AIR");If you want to neglect attenuation and interactions outside the sensitive region, you might choose vacuum:
fWorldMaterial = nist->FindOrBuildMaterial("G4_Galactic");
Active detector material. For a scintillation detector, you might use one of the standard NIST-like entries if available, or define your own crystal. For a semiconductor, use silicon from NIST. For water phantoms in a medical project, use G4_WATER.
Structural and shielding materials. For housings, arms, or collimators, use:
G4Material* aluminum = nist->FindOrBuildMaterial("G4_Al");
G4Material* lead = nist->FindOrBuildMaterial("G4_Pb");
G4Material* concrete = nist->FindOrBuildMaterial("G4_CONCRETE");Biological tissues. For simplified tissue representation, you can either use NIST-based tissues if available or define approximate soft tissue as a custom material with density around 1 g/cm$^3$ and an appropriate C, H, O, N composition.
For your final project, choose the minimum set of materials that still captures the physics you plan to analyze. For example, if your primary observable is the energy spectrum in a scintillator, you need to be careful with the scintillator material, but a simple air world and aluminum housing can be sufficient.
Creating Custom Materials for the Project
When you need a custom material, define it carefully in terms of elements, density and composition. The typical workflow in your DefineMaterials() method is:
Create or access elements. Use either the NIST manager to get elements or define them explicitly:
auto nist = G4NistManager::Instance();
G4Element* elC = nist->FindOrBuildElement("C");
G4Element* elH = nist->FindOrBuildElement("H");
G4Element* elO = nist->FindOrBuildElement("O");Define the material with density and number of components:
G4double density = 1.032*g/cm3;
G4int ncomponents = 3;
G4Material* plasticScint =
new G4Material("PlasticScintillator", density, ncomponents);Add elements by mass fraction:
plasticScint->AddElement(elC, 0.915);
plasticScint->AddElement(elH, 0.078);
plasticScint->AddElement(elO, 0.007);You then store this pointer in a member variable, for example:
fDetectorMaterial = plasticScint;
For mixtures of existing materials, you can also combine previously defined G4Material objects with AddMaterial and their mass fractions.
When defining a material with mass fractions, the sum of all fractions must equal 1. If you use atom counts instead, be consistent and use AddElement(element, numberOfAtoms). Mixing these conventions incorrectly leads to wrong compositions.
In a full detector project, consider collecting your custom active materials into a separate helper function, such as DefineDetectorMaterials(), so they are easy to find and modify independently of world or structural materials.
Linking Materials to Geometry and Other Components
Once materials are defined, you must connect them to the logical volumes that represent the detector components. This is where the member pointers such as fWorldMaterial become useful.
For example:
G4Box* solidWorld =
new G4Box("World", 0.5*worldSizeX, 0.5*worldSizeY, 0.5*worldSizeZ);
G4LogicalVolume* logicWorld =
new G4LogicalVolume(solidWorld, fWorldMaterial, "WorldLV");And for your detector:
G4Box* solidDetector =
new G4Box("Det", 0.5*detSizeX, 0.5*detSizeY, 0.5*detSizeZ);
G4LogicalVolume* logicDetector =
new G4LogicalVolume(solidDetector, fDetectorMaterial, "DetLV");Assigning materials in this clear and consistent way has several benefits for the final project:
If you switch the detector material, for example between different scintillators or tissues, you only change fDetectorMaterial in one place.
You can later expose material selection to macro commands by mapping strings from a macro to these member pointers.
Your sensitive detector and analysis code can identify which material a volume uses, if needed, by accessing the logical volume and calling GetMaterial().
Always ensure that your world material is defined and assigned before placing any other volumes. Geant4 requires that the outermost world logical volume is fully defined, including its material, before you start building the rest of your geometry.
Material Documentation and Validation in the Final Project
A complete final project should make it clear to a reader exactly what materials were used. To achieve this, include the following in your code or accompanying documentation:
A short comment above each custom material definition that states its source, such as a reference, a paper, or a standard.
The density value with units, and a note if you adjusted it from a standard value.
Whether the composition is by mass fraction or atomic composition.
Name your materials in a self-explanatory way, for example "Scintillator_LYSO", "WaterPhantom", "Tissue_Soft", rather than generic names like "mat1".
As part of validation, check that:
Your main observables, such as attenuation through shielding or depth dose in a phantom, are consistent with known reference data for the selected materials.
There are no warnings from Geant4 about undefined or missing materials when you start the run.
If possible, print a summary of your key materials at initialization using G4cout and G4Material::DumpTable() or by iterating over G4Material::GetMaterialTable(), to quickly confirm that densities and compositions are what you expect.
By carefully planning, implementing, and documenting your materials, you ensure that the final project provides physically meaningful results and is understandable to others who read or reuse your simulation.
Views: 9
KAHIBARO