Geant4 Version:11.1.1
Operating System:MacOS
Compiler/Version:clang 15.0.0
CMake Version: 3.26.5
Question
/NP/det/SetWorldMat G4_AIR
This mac didn’t work!
Code
1. DetectorConstruction
/*********************************************************
* @function: DefineMaterials
* @brief: Define the materials for AuNP , cell , world
*********************************************************/
void DetectorConstruction::DefineMaterials() {
// World: Vacuum
G4NistManager *nist_manager = G4NistManager::Instance();
nist_manager->FindOrBuildMaterial("G4_Galactic");
nist_manager->FindOrBuildMaterial("G4_AIR");
// Cell
nist_manager->FindOrBuildMaterial("G4_WATER");
// nucleus
nist_manager->BuildMaterialWithNewDensity("Nucleus", "G4_WATER", 1.74 * g/cm3);
// AuNP
nist_manager->FindOrBuildMaterial("G4_Au");
}
void DetectorConstruction::SetWorldMaterial(G4String val) {
G4Material *material = G4Material::GetMaterial(val);
if(material) world_mat = material;
G4RunManager::GetRunManager()->PhysicsHasBeenModified();
}
DetectorConstruction::DetectorConstruction() : G4VUserDetectorConstruction(),
world_mat(nullptr), cell_mat(nullptr), nucleus_mat(nullptr), NP_mat(nullptr),
cell_radius(15 * um), nucleus_radius(5.5 * um),
addAuNP(false), number_of_NPs(0), radius_of_NPs(0.), dis_type("Uniform") {
radius_of_NPs = 15 * nm;
number_of_NPs = 1000;
DefineMaterials();
SetCellMaterial("G4_WATER");
SetNucleusMaterial("Nucleus");
SetNPMaterial("G4_Au");
det_messenger = std::make_unique<DetectorConstructionMessenger>(this);
}
2. DetectorConstructionMessenger
DetectorConstructionMessenger::DetectorConstructionMessenger(DetectorConstruction *pDet) : G4UImessenger(), det(pDet) {
NP_dir = std::make_unique<G4UIdirectory>("/NP/");
NP_dir->SetGuidance("UI command specific to this Nano particle setup");
det_dir = std::make_unique<G4UIdirectory>("/NP/det/");
det_dir->SetGuidance("Detector construction commands");
world_mat_cmd = std::make_unique<G4UIcmdWithAString>("/NP/det/SetWorldMat", this);
world_mat_cmd->SetGuidance("Set World Material");
world_mat_cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
world_mat_cmd->SetToBeBroadcasted(false);
cell_mat_cmd = std::make_unique<G4UIcmdWithAString>("/NP/det/SetCellMat", this);
cell_mat_cmd->SetGuidance("Set World Material");
cell_mat_cmd->AvailableForStates(G4State_PreInit, G4State_Idle);
cell_mat_cmd->SetToBeBroadcasted(false);
add_NPs_cmd = std::make_unique<G4UIcmdWithABool>("/NP/det/addNP", this);
add_NPs_cmd->SetGuidance("If add NPs");
add_NPs_cmd->AvailableForStates(G4State_PreInit,G4State_Idle);
add_NPs_cmd->SetToBeBroadcasted(false);
NP_number_cmd = std::make_unique<G4UIcmdWithAnInteger>("/NP/det/SetN", this);
NP_number_cmd->SetGuidance("Set Number of NPs");
NP_number_cmd->SetParameterName("N", false);
NP_number_cmd->SetRange("N>0");
NP_number_cmd->AvailableForStates(G4State_PreInit,G4State_Idle);
NP_number_cmd->SetToBeBroadcasted(false);
NP_radius_cmd = std::make_unique<G4UIcmdWithADouble>("/NP/det/SetNPR",this);
NP_radius_cmd->SetGuidance("Set radius of NPs");
NP_radius_cmd->SetParameterName("Radius",false);
NP_radius_cmd->SetRange("Radius>0.");
NP_radius_cmd->AvailableForStates(G4State_PreInit,G4State_Idle);
NP_radius_cmd->SetToBeBroadcasted(false);
}
DetectorConstructionMessenger::~DetectorConstructionMessenger() = default;
void DetectorConstructionMessenger::SetNewValue(G4UIcommand *command, G4String newValue) {
if(command == world_mat_cmd.get()) {
det->SetWorldMaterial(newValue);
}
if(command == cell_mat_cmd.get()) {
det->SetCellMaterial(newValue);
}
if(command == add_NPs_cmd.get()) {
det->SetAddNP(add_NPs_cmd->GetNewBoolValue(newValue));
}
if(command == NP_number_cmd.get()) {
det->SetNumberOfNP(NP_number_cmd->GetNewIntValue(newValue));
}
if(command == NP_radius_cmd.get()) {
det->SetRadiusOfNP(NP_radius_cmd->GetNewDoubleValue(newValue));
}
}
How to solve it?