KAHIBARO
Discord Login Register

NIST Material Database

`G4NistManager`

In Geant4 you rarely need to define common materials from scratch. Instead, you can rely on a built in database of standard materials provided by NIST, the National Institute of Standards and Technology. Access to this database is handled through the class G4NistManager.

G4NistManager is a singleton, which means there is exactly one instance of it in a Geant4 application. You do not create it with new. Instead, you obtain the instance through a static method:

cpp
auto nist = G4NistManager::Instance();

From this point you use nist to access predefined elements and materials.

The database contains many common elements and materials that are already defined with consistent densities, atomic compositions, and mean excitation energies. For example, you can get air, water, silicon, aluminum, or lead directly by name. The result of these calls is a pointer to a G4Material object that you can use when building your detector geometry.

A typical usage inside DetectorConstruction::Construct() looks like this:

cpp
auto nist = G4NistManager::Instance();
G4Material* worldMat  = nist->FindOrBuildMaterial("G4_AIR");
G4Material* targetMat = nist->FindOrBuildMaterial("G4_WATER");

FindOrBuildMaterial checks if the material already exists. If it does, the existing material is returned. If not, it creates the material from NIST data and then returns it. This means you can safely call FindOrBuildMaterial multiple times with the same name without creating duplicates.

You can use these materials anywhere a G4Material* is required, for example when you construct a logical volume:

cpp
auto logicWorld = new G4LogicalVolume(solidWorld, worldMat, "World");

Important rule: Always obtain standard materials through G4NistManager::Instance() and FindOrBuildMaterial("G4_..."). Do not redefine common materials manually unless you have a very specific reason, because that can introduce inconsistencies with physics models.

Internally, the NIST database uses a consistent set of physical constants and material definitions, so using it improves the reliability and reproducibility of your simulations, especially when you compare results with other Geant4 users.

Searching for materials

To use a NIST material you must know its name. NIST material names in Geant4 follow a simple convention. Elements usually have the form "G4_X" where X is the chemical symbol, for example "G4_Si" for silicon or "G4_Pb" for lead. Many common compounds and mixtures are available with names like "G4_WATER", "G4_AIR", or "G4_CONCRETE".

If you do not know the exact name, G4NistManager provides helper methods to list and inspect materials and elements. After obtaining the instance

cpp
auto nist = G4NistManager::Instance();

you can query the number of NIST materials and elements, then loop over them:

cpp
G4int nMaterials = nist->GetNumberOfMaterials();
for (G4int i = 0; i < nMaterials; ++i) {
    G4Material* mat = nist->GetMaterial(i);
    if (mat) {
        G4cout << i << "  " << mat->GetName() << G4endl;
    }
}

This kind of loop prints the index and name of every material that NIST provides in your Geant4 build. You can run this code in your DetectorConstruction once during construction and inspect the output to discover valid material names.

You can do something similar for elements:

cpp
G4int nElements = nist->GetNumberOfElements();
for (G4int i = 0; i < nElements; ++i) {
    G4Element* el = nist->GetElement(i);
    if (el) {
        G4cout << i << "  " << el->GetName()
               << "  " << el->GetSymbol() << G4endl;
    }
}

The most common operation is to look up a known name with FindOrBuildMaterial or FindOrBuildElement. The essential methods are summarized below.

PurposeMethodExample
Get a materialFindOrBuildMaterial("name")nist->FindOrBuildMaterial("G4_WATER");
Get an elementFindOrBuildElement("symbol")nist->FindOrBuildElement("Si");
List all materialsGetNumberOfMaterials(), GetMaterialLoop over indices and print GetName()
List all elementsGetNumberOfElements(), GetElementLoop over indices and print symbol and name

When searching by name, Geant4 is case sensitive. "G4_WATER" is not the same as "g4_water". If you pass an incorrect name, FindOrBuildMaterial will return nullptr and print an error message. You should always check the returned pointer if there is any chance of a typo.

A simple pattern to handle this safely is:

cpp
G4Material* water = nist->FindOrBuildMaterial("G4_WATER");
if (!water) {
    G4Exception("DetectorConstruction::Construct()",
                "MyCode0001", FatalException,
                "Material G4_WATER not found in NIST database.");
}

Important rule: Material names are case sensitive and must match the NIST definitions exactly. If FindOrBuildMaterial returns nullptr, do not use the pointer. Always verify material creation when you are unsure about the name.

By combining the listing methods and careful name checking you can quickly find the correct NIST materials and integrate them into your detector geometry without redefining them manually.

Views: 10

Comments

Please login to add a comment.

Don't have an account? Register now!