File indexing completed on 2025-02-23 09:22:40
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
0030
0031
0032
0033 #include "DetectorMessenger.hh"
0034
0035 #include "DetectorConstruction.hh"
0036
0037 #include "G4UIcmdWithADoubleAndUnit.hh"
0038 #include "G4UIcmdWithAString.hh"
0039 #include "G4UIcmdWithoutParameter.hh"
0040 #include "G4UIcommand.hh"
0041 #include "G4UIdirectory.hh"
0042 #include "G4UIparameter.hh"
0043
0044
0045
0046 DetectorMessenger::DetectorMessenger(DetectorConstruction* det) : fDetector(det)
0047 {
0048 fTestemDir = new G4UIdirectory("/testhadr/");
0049 fTestemDir->SetGuidance("commands specific to this example");
0050
0051 G4bool broadcast = false;
0052 fDetDir = new G4UIdirectory("/testhadr/det/", broadcast);
0053 fDetDir->SetGuidance("detector construction commands");
0054
0055 fMaterCmd = new G4UIcmdWithAString("/testhadr/det/setMat", this);
0056 fMaterCmd->SetGuidance("Select material of the box.");
0057 fMaterCmd->SetParameterName("choice", false);
0058 fMaterCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0059
0060 fThickCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setThickness", this);
0061 fThickCmd->SetGuidance("Set thickness of the absor");
0062 fThickCmd->SetParameterName("Thickness", false);
0063 fThickCmd->SetRange("Thickness>0.");
0064 fThickCmd->SetUnitCategory("Length");
0065 fThickCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0066
0067 fSizeYZCmd = new G4UIcmdWithADoubleAndUnit("/testhadr/det/setSizeYZ", this);
0068 fSizeYZCmd->SetGuidance("Set transverse size of the absor");
0069 fSizeYZCmd->SetParameterName("Size", false);
0070 fSizeYZCmd->SetRange("Size>0.");
0071 fSizeYZCmd->SetUnitCategory("Length");
0072 fSizeYZCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0073
0074 fIsotopeCmd = new G4UIcommand("/testhadr/det/setIsotopeMat", this);
0075 fIsotopeCmd->SetGuidance("Build and select a material with single isotope");
0076 fIsotopeCmd->SetGuidance(" symbol of isotope, Z, A, density of material");
0077
0078 G4UIparameter* symbPrm = new G4UIparameter("isotope", 's', false);
0079 symbPrm->SetGuidance("isotope symbol");
0080 fIsotopeCmd->SetParameter(symbPrm);
0081
0082 G4UIparameter* ZPrm = new G4UIparameter("Z", 'i', false);
0083 ZPrm->SetGuidance("Z");
0084 ZPrm->SetParameterRange("Z>0");
0085 fIsotopeCmd->SetParameter(ZPrm);
0086
0087 G4UIparameter* APrm = new G4UIparameter("A", 'i', false);
0088 APrm->SetGuidance("A");
0089 APrm->SetParameterRange("A>0");
0090 fIsotopeCmd->SetParameter(APrm);
0091
0092 G4UIparameter* densityPrm = new G4UIparameter("density", 'd', false);
0093 densityPrm->SetGuidance("density of material");
0094 densityPrm->SetParameterRange("density>0.");
0095 fIsotopeCmd->SetParameter(densityPrm);
0096
0097 G4UIparameter* unitPrm = new G4UIparameter("unit", 's', false);
0098 unitPrm->SetGuidance("unit of density");
0099 G4String unitList = G4UIcommand::UnitsList(G4UIcommand::CategoryOf("g/cm3"));
0100 unitPrm->SetParameterCandidates(unitList);
0101 fIsotopeCmd->SetParameter(unitPrm);
0102
0103 fIsotopeCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
0104 }
0105
0106
0107
0108 DetectorMessenger::~DetectorMessenger()
0109 {
0110 delete fMaterCmd;
0111 delete fThickCmd;
0112 delete fSizeYZCmd;
0113 delete fIsotopeCmd;
0114 delete fDetDir;
0115 delete fTestemDir;
0116 }
0117
0118
0119
0120 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0121 {
0122 if (command == fMaterCmd) {
0123 fDetector->SetAbsorMaterial(newValue);
0124 }
0125
0126 if (command == fThickCmd) {
0127 fDetector->SetAbsorThickness(fThickCmd->GetNewDoubleValue(newValue));
0128 }
0129
0130 if (command == fSizeYZCmd) {
0131 fDetector->SetAbsorSizeYZ(fSizeYZCmd->GetNewDoubleValue(newValue));
0132 }
0133
0134 if (command == fIsotopeCmd) {
0135 G4int Z;
0136 G4int A;
0137 G4double dens;
0138 G4String name, unt;
0139 std::istringstream is(newValue);
0140 is >> name >> Z >> A >> dens >> unt;
0141 dens *= G4UIcommand::ValueOf(unt);
0142 fDetector->MaterialWithSingleIsotope(name, name, dens, Z, A);
0143 fDetector->SetAbsorMaterial(name);
0144 }
0145 }
0146
0147