File indexing completed on 2026-09-10 08:28:56
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 fTesthadDir = new G4UIdirectory("/testhadr/");
0045 fTesthadDir->SetGuidance("commands specific to this example");
0046
0047 fDetDir = new G4UIdirectory("/testhadr/det/");
0048 fDetDir->SetGuidance("detector construction commands");
0049
0050 fMaterCmd = new G4UIcmdWithAString("/testhadr/det/setMat", this);
0051 fMaterCmd->SetGuidance("Select material of the box.");
0052 fMaterCmd->SetParameterName("choice", false);
0053 fMaterCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0054 fMaterCmd->SetToBeBroadcasted(false);
0055
0056 fSizeCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setSize", this);
0057 fSizeCmd->SetGuidance("Set size of the box");
0058 fSizeCmd->SetParameterName("Size", false);
0059 fSizeCmd->SetRange("Size>0.");
0060 fSizeCmd->SetUnitCategory("Length");
0061 fSizeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0062 fSizeCmd->SetToBeBroadcasted(false);
0063
0064 fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat", this);
0065 fIsotopeCmd->SetGuidance("Build and select a material with single isotope");
0066 fIsotopeCmd->SetGuidance(" symbol of isotope, Z, A, density of material");
0067
0068 G4UIparameter* symbPrm = new G4UIparameter("isotope", 's', false);
0069 symbPrm->SetGuidance("isotope symbol");
0070 fIsotopeCmd->SetParameter(symbPrm);
0071
0072 G4UIparameter* ZPrm = new G4UIparameter("Z", 'i', false);
0073 ZPrm->SetGuidance("Z");
0074 ZPrm->SetParameterRange("Z>0");
0075 fIsotopeCmd->SetParameter(ZPrm);
0076
0077 G4UIparameter* APrm = new G4UIparameter("A", 'i', false);
0078 APrm->SetGuidance("A");
0079 APrm->SetParameterRange("A>0");
0080 fIsotopeCmd->SetParameter(APrm);
0081
0082 G4UIparameter* densityPrm = new G4UIparameter("density", 'd', false);
0083 densityPrm->SetGuidance("density of material");
0084 densityPrm->SetParameterRange("density>0.");
0085 fIsotopeCmd->SetParameter(densityPrm);
0086
0087 G4UIparameter* unitPrm = new G4UIparameter("unit", 's', false);
0088 unitPrm->SetGuidance("unit of density");
0089 G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("g/cm3"));
0090 unitPrm->SetParameterCandidates(unitList);
0091 fIsotopeCmd->SetParameter(unitPrm);
0092
0093 fIsotopeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0094 fIsotopeCmd->SetToBeBroadcasted(false);
0095 }
0096
0097
0098
0099 DetectorMessenger::~DetectorMessenger()
0100 {
0101 delete fMaterCmd;
0102 delete fSizeCmd;
0103 delete fIsotopeCmd;
0104 delete fDetDir;
0105 delete fTesthadDir;
0106 }
0107
0108
0109
0110 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0111 {
0112 if (command == fMaterCmd) {
0113 fDetector->SetMaterial(newValue);
0114 }
0115
0116 if (command == fSizeCmd) {
0117 fDetector->SetSize(fSizeCmd->GetNewDoubleValue(newValue));
0118 }
0119
0120 if (command == fIsotopeCmd) {
0121 G4int Z;
0122 G4int A;
0123 G4double dens;
0124 G4String name, unt;
0125 std::istringstream is(newValue);
0126 is >> name >> Z >> A >> dens >> unt;
0127 dens *= G4UIcommand::ValueOf(unt);
0128 fDetector->MaterialWithSingleIsotope(name, name, dens, Z, A);
0129 fDetector->SetMaterial(name);
0130 }
0131 }
0132
0133