File indexing completed on 2026-09-21 08:29:38
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 "G4UIdirectory.hh"
0037 #include "globals.hh"
0038
0039
0040
0041 DetectorMessenger::DetectorMessenger(DetectorConstruction* myDet) : fDetector(myDet)
0042 {
0043 fDetectorDir = new G4UIdirectory("/mydet/");
0044 fDetectorDir->SetGuidance("Detector control.");
0045
0046 fMaterial = new G4UIcmdWithAString("/mydet/material", this);
0047 fMaterial->SetGuidance("Choice of the material:");
0048 fMaterial->SetGuidance(" a Geant4 NIST material, e.g. G4_Fe ");
0049 fMaterial->SetParameterName("choiceMaterial", true);
0050 fMaterial->SetDefaultValue("G4_Fe");
0051 fMaterial->AvailableForStates(G4State_PreInit, G4State_Idle);
0052
0053 fRadius = new G4UIcmdWithADoubleAndUnit("/mydet/radius", this);
0054 fRadius->SetParameterName("choiceRadius", true);
0055 fRadius->SetGuidance("Target sphere radius");
0056 fRadius->SetDefaultValue(1000.0);
0057 fRadius->AvailableForStates(G4State_PreInit, G4State_Idle);
0058
0059 fUpdateCommand = new G4UIcmdWithoutParameter("/mydet/update", this);
0060 fUpdateCommand->SetGuidance("Update geometry.");
0061 fUpdateCommand->SetGuidance("This command MUST be applied before \"beamOn\" ");
0062 fUpdateCommand->SetGuidance("if you changed geometrical value(s).");
0063 fUpdateCommand->AvailableForStates(G4State_Idle);
0064 }
0065
0066
0067
0068 DetectorMessenger::~DetectorMessenger()
0069 {
0070 delete fDetectorDir;
0071 delete fMaterial;
0072 delete fRadius;
0073 delete fUpdateCommand;
0074 }
0075
0076
0077
0078 void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
0079 {
0080 if (command == fMaterial) {
0081 fDetector->SetMaterial(newValue);
0082 }
0083 if (command == fRadius) {
0084 fDetector->SetRadius(fRadius->GetNewDoubleValue(newValue));
0085 }
0086 if (command == fUpdateCommand) {
0087 fDetector->UpdateGeometry();
0088 }
0089 }
0090
0091