Good morning Geant4 users,
I have a silly question for you. In order to correctly simulate thermal neutron scattering, it is necessary to create the elements that contain the information of neutron cross sections in the thermal energy range (e.g. TS_H_of_Water).
However, because of the complexity of the geometry of my model to be simulated I am using a GDML file. I know that GDML files can accept matrial assignment using NIST nomenclature (e.g. G4_H, etc.).
Unfortunately, when I try to use the nomenclature for thermal neutron scattering (having defined in my PhysicsList both the thermal data set and the model, as described in the example Hadr04) it gives me the error:
“Referenced material/element ‘TS_H_of_Water’ was not found”
Have any of you had the same problem? Do you know another way to call thermal data for a GDML file?
Thank you in advance for your help.
1 Like
Bump to this! If I wanted to define thermal scattering materials via gdml, what would I have to do?
I think the options are either:
- Define the materials in the GDML file itself, using the
<materials>
section. See the extended/persistency/gdml
examples for cases of this.
- It should also be possible to define the materials in the constructor of the concrete
G4VUserDetectorConstruction
class, or at least anywhere before the input GDML is parsed in. The GDML parser uses G4Material::GetMaterial
to look up the material (before falling back to NIST), so provided it’s been defined before parsing it should be found.
It does not let me define them in the gdml, but If I implemented them in DetectorConstruction I could then use them freely. Thank’s for the idea!
Hello all,
I have limited experience in this field but would like to recommend “GDML Workbench” addon to FreeCAD to convert STEP to GDML file format and define the used materials. Additionally I used an extra class - Materials, where I described custom materials used in simulations. After that I used the code like this (in reality some mix from examples with dumps mainly):
//…oooOO0OOooo…oooOO0OOooo…oooOO0OOooo…oooOO0OOooo…
void DetectorConstruction::ReadGDML()
{
fReader = new ColorReader;
parser = new G4GDMLParser(fReader);
parser->Read(gdmlFile ,false); //TRUE - require internet connection for GDML schema validation
G4VPhysicalVolume* World = parser->GetWorldVolume();
G4cout << World->GetTranslation() << G4endl << G4endl;
if (verbose)
{
G4cout << "Found World: " << World->GetName() << G4endl;
G4cout << "World LV: " << World->GetLogicalVolume()->GetName() << G4endl;
}
G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
if (verbose)
{
G4cout << "Found " << pLVStore->size() << " logical volumes." << G4endl << G4endl;
for (auto it = pLVStore->begin(); it != pLVStore->end(); ++it)
{
G4cout << (*it)->GetName() << G4endl;
}
}
G4PhysicalVolumeStore* pPVStore = G4PhysicalVolumeStore::GetInstance();
if (verbose)
{
G4cout << "Found " << pPVStore->size() << " physical volumes." << G4endl << G4endl;
for (auto it = pPVStore->begin(); it != pPVStore->end(); ++it)
{
G4cout << (*it)->GetName() << G4endl;
}
}
}
//…oooOO0OOooo…oooOO0OOooo…oooOO0OOooo…oooOO0OOooo…
G4VPhysicalVolume* DetectorConstruction::Construct()
{
ReadGDML();
/////////////////////////////////////////////////////////////
//
// Enumerate available materials
//
G4cout << "DetectorConstruction::Construct(). Available materials: " << G4endl;
G4MaterialTable* tbl = G4Material::GetMaterialTable();
for (auto it = tbl->begin(); it != tbl->end(); ++it)
{
G4cout << (*it)->GetName() << G4endl;
G4MaterialPropertiesTable* ptbl = (*it)->GetMaterialPropertiesTable();
if (ptbl) { ptbl->DumpTable(); }
}
//Create custom materials and Update user-defined parameters of existing ones
G4Material* mat = Materials::GetInstance()->GetMaterial("GAGG");
G4cout << "DetectorConstruction::Construct(). After materials update: " << G4endl;
//Show updated properties
for (auto it = tbl->begin(); it != tbl->end(); ++it)
{
G4cout << (*it)->GetName() << G4endl;
G4MaterialPropertiesTable* ptbl = (*it)->GetMaterialPropertiesTable();
if (ptbl) { ptbl->DumpTable(); }
}
//Parse auxiliary information
const G4GDMLAuxMapType* auxmap = parser->GetAuxMap();
if (verbose)
{
G4cout << "DetectorConstruction::Construct(). Found " << auxmap->size() << " volume(s) with auxiliary information." << G4endl << G4endl;
}
for (G4GDMLAuxMapType::const_iterator iter = auxmap->begin(); iter != auxmap->end(); iter++)
{
if (verbose)
{
G4cout << "Volume " << ((*iter).first)->GetName() << " has the following list of auxiliary information: " << G4endl;
}
for (G4GDMLAuxListType::const_iterator vit = (*iter).second.begin(); vit != (*iter).second.end(); vit++)
{
if (verbose)
{
G4cout << "--> Type: " << (*vit).type << " Value: " << (*vit).value << G4endl;
}
if ((*vit).type == "StepLimit")
{
G4UserLimits* fStepLimit = new G4UserLimits(atof((*vit).value));
((*iter).first)->SetUserLimits(fStepLimit);
}
}
}
//-------------------------------------------------
// Define regions etc...
//-------------------------------------------------
…
and my custom Materials.cc have the method:
G4Material* Materials::GetMaterial(const G4String& name)
{
G4Material* mat = fNistMan->FindOrBuildMaterial(name);
if (!mat)
{
mat = G4Material::GetMaterial(name);
}
if (!mat)
{
G4ExceptionDescription ed;
ed << "Material " << name << " not found!";
G4Exception("Materials::GetMaterial", "", FatalException, ed);
}
if (mat)
{
G4cout << "Materials::GetMaterial. Selected material: " << mat->GetName() << G4endl;
}
return mat;
}
}