File indexing completed on 2026-03-30 07:51:11
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 fThickCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setThickness", this);
0057 fThickCmd->SetGuidance("Set thickness of the absor");
0058 fThickCmd->SetParameterName("Thickness", false);
0059 fThickCmd->SetRange("Thickness>0.");
0060 fThickCmd->SetUnitCategory("Length");
0061 fThickCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0062
0063 fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setSizeYZ", this);
0064 fSizeYZCmd->SetGuidance("Set transverse size of the absor");
0065 fSizeYZCmd->SetParameterName("Size", false);
0066 fSizeYZCmd->SetRange("Size>0.");
0067 fSizeYZCmd->SetUnitCategory("Length");
0068 fSizeYZCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0069
0070 fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat", this);
0071 fIsotopeCmd->SetGuidance("Build and select a material with single isotope");
0072 fIsotopeCmd->SetGuidance(" symbol of isotope, Z, A, density of material");
0073
0074 G4UIparameter* symbPrm = new G4UIparameter("isotope", 's', false);
0075 symbPrm->SetGuidance("isotope symbol");
0076 fIsotopeCmd->SetParameter(symbPrm);
0077
0078 G4UIparameter* ZPrm = new G4UIparameter("Z", 'i', false);
0079 ZPrm->SetGuidance("Z");
0080 ZPrm->SetParameterRange("Z>0");
0081 fIsotopeCmd->SetParameter(ZPrm);
0082
0083 G4UIparameter* APrm = new G4UIparameter("A", 'i', false);
0084 APrm->SetGuidance("A");
0085 APrm->SetParameterRange("A>0");
0086 fIsotopeCmd->SetParameter(APrm);
0087
0088 G4UIparameter* densityPrm = new G4UIparameter("density", 'd', false);
0089 densityPrm->SetGuidance("density of material");
0090 densityPrm->SetParameterRange("density>0.");
0091 fIsotopeCmd->SetParameter(densityPrm);
0092
0093 G4UIparameter* unitPrm = new G4UIparameter("unit", 's', false);
0094 unitPrm->SetGuidance("unit of density");
0095 G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("g/cm3"));
0096 unitPrm->SetParameterCandidates(unitList);
0097 fIsotopeCmd->SetParameter(unitPrm);
0098
0099 fIsotopeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0100 }
0101
0102
0103
0104 DetectorMessenger::~DetectorMessenger()
0105 {
0106 delete fMaterCmd;
0107 delete fThickCmd;
0108 delete fSizeYZCmd;
0109 delete fIsotopeCmd;
0110 delete fDetDir;
0111 delete fTestemDir;
0112 }
0113
0114
0115
0116 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0117 {
0118 if (command == fMaterCmd) {
0119 fDetector->SetAbsorMaterial(newValue);
0120 }
0121
0122 if (command == fThickCmd) {
0123 fDetector->SetAbsorThickness(fThickCmd->GetNewDoubleValue(newValue));
0124 }
0125
0126 if (command == fSizeYZCmd) {
0127 fDetector->SetAbsorSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));
0128 }
0129
0130 if (command == fIsotopeCmd) {
0131 G4int Z;
0132 G4int A;
0133 G4double dens;
0134 G4String name, unt;
0135 std::istringstream is(newValue);
0136 is >> name >> Z >> A >> dens >> unt;
0137 dens *= G4UIcommand::ValueOf(unt);
0138 fDetector->MaterialWithSingleIsotope(name, name, dens, Z, A);
0139 fDetector->SetAbsorMaterial(name);
0140 }
0141 }
0142
0143