File indexing completed on 2026-09-15 08:28:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "DetectorMessenger.hh"
0030
0031 #include "DetectorConstruction.hh"
0032
0033 #include "G4UIcmdWithADoubleAndUnit.hh"
0034 #include "G4UIcmdWithAString.hh"
0035 #include "G4UIcmdWithoutParameter.hh"
0036 #include "G4UIcommand.hh"
0037 #include "G4UIdirectory.hh"
0038 #include "G4UIparameter.hh"
0039
0040
0041
0042 DetectorMessenger::DetectorMessenger(DetectorConstruction* Det) : fDetector(Det)
0043 {
0044 fTestemDir = new G4UIdirectory("/testhadr/");
0045 fTestemDir->SetGuidance("commands specific to this example");
0046
0047 G4bool broadcast = false;
0048 fDetDir = new G4UIdirectory("/testhadr/det/", broadcast);
0049 fDetDir->SetGuidance("detector construction commands");
0050
0051 fMaterCmd = new G4UIcmdWithAString("/testhadr/det/setMat", this);
0052 fMaterCmd->SetGuidance("Select material of the box.");
0053 fMaterCmd->SetParameterName("choice", false);
0054 fMaterCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0055
0056 fSizeCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setRadius", this);
0057 fSizeCmd->SetGuidance("Set size of the sphere");
0058 fSizeCmd->SetParameterName("Size", false);
0059 fSizeCmd->SetRange("Size>0.");
0060 fSizeCmd->SetUnitCategory("Length");
0061 fSizeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0062
0063 fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat", this);
0064 fIsotopeCmd->SetGuidance("Build and select a material with single isotope");
0065 fIsotopeCmd->SetGuidance(" symbol of isotope, Z, A, density of material");
0066
0067 G4UIparameter* symbPrm = new G4UIparameter("isotope", 's', false);
0068 symbPrm->SetGuidance("isotope symbol");
0069 fIsotopeCmd->SetParameter(symbPrm);
0070
0071 G4UIparameter* ZPrm = new G4UIparameter("Z", 'i', false);
0072 ZPrm->SetGuidance("Z");
0073 ZPrm->SetParameterRange("Z>0");
0074 fIsotopeCmd->SetParameter(ZPrm);
0075
0076 G4UIparameter* APrm = new G4UIparameter("A", 'i', false);
0077 APrm->SetGuidance("A");
0078 APrm->SetParameterRange("A>0");
0079 fIsotopeCmd->SetParameter(APrm);
0080
0081 G4UIparameter* densityPrm = new G4UIparameter("density", 'd', false);
0082 densityPrm->SetGuidance("density of material");
0083 densityPrm->SetParameterRange("density>0.");
0084 fIsotopeCmd->SetParameter(densityPrm);
0085
0086 G4UIparameter* unitPrm = new G4UIparameter("unit", 's', false);
0087 unitPrm->SetGuidance("unit of density");
0088 G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("g/cm3"));
0089 unitPrm->SetParameterCandidates(unitList);
0090 fIsotopeCmd->SetParameter(unitPrm);
0091
0092 fIsotopeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0093 }
0094
0095
0096
0097 DetectorMessenger::~DetectorMessenger()
0098 {
0099 delete fMaterCmd;
0100 delete fSizeCmd;
0101 delete fIsotopeCmd;
0102 delete fDetDir;
0103 delete fTestemDir;
0104 }
0105
0106
0107
0108 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0109 {
0110 if (command == fMaterCmd) {
0111 fDetector->SetMaterial(newValue);
0112 }
0113
0114 if (command == fSizeCmd) {
0115 fDetector->SetRadius(fSizeCmd->GetNewDoubleValue(newValue));
0116 }
0117
0118 if (command == fIsotopeCmd) {
0119 G4int Z;
0120 G4int A;
0121 G4double dens;
0122 G4String name, unt;
0123 std::istringstream is(newValue);
0124 is >> name >> Z >> A >> dens >> unt;
0125 dens *= G4UIcommand::ValueOf(unt);
0126 fDetector->MaterialWithSingleIsotope(name, name, dens, Z, A);
0127 fDetector->SetMaterial(name);
0128 }
0129 }
0130
0131