// M Hentz, 2016 #include "G4UIdirectory.hh" #include "G4UIcommand.hh" #include "G4UIparameter.hh" #include "G4UIcmdWithAString.hh" #include "G4UIcmdWith3VectorAndUnit.hh" #include "G4UIcmdWithAnInteger.hh" #include "G4UIcmdWithADoubleAndUnit.hh" #include "G4UIcmdWithoutParameter.hh" #include "DetectorMessenger.hh" #include "DetectorConstruction.hh" DetectorMessenger::DetectorMessenger( DetectorConstruction* det ) :G4UImessenger(), fDetector(det), fSimDir(0), fDetDir(0), fMatCmd(0), fPosCmd(0), fSizeZCmd(0), fSizeXYCmd(0), fLayerSizeXYCmd(0), fLayerNumberCmd(0), fUpdateCmd(0) { fSimDir = new G4UIdirectory( "/cb_sim/" ); fSimDir->SetGuidance( "simulation control" ); fDetDir = new G4UIdirectory( "/cb_sim/det/" ); fDetDir->SetGuidance( "detector construction commands" ); fMatCmd = new G4UIcmdWithAString( "/cb_sim/det/setMaterial", this ); fMatCmd->SetGuidance( "Select material of the absorber" ); fMatCmd->SetParameterName( "fMaterial", false ); fMatCmd->AvailableForStates( G4State_PreInit, G4State_Idle ); fPosCmd = new G4UIcmdWith3VectorAndUnit( "/cb_sim/det/setPosition", this ); fPosCmd->SetGuidance( "Set position of the detector" ); fPosCmd->SetParameterName( "fPosX", "fPosY", "fPosZ", false ); fPosCmd->SetUnitCategory( "Length" ); fPosCmd->AvailableForStates( G4State_PreInit, G4State_Idle ); fSizeZCmd = new G4UIcmdWithADoubleAndUnit( "/cb_sim/det/setSizeZ", this ); fSizeZCmd->SetGuidance( "Set dimension in z of the absorber" ); fSizeZCmd->SetParameterName( "fSizeZ", false ); fSizeZCmd->SetRange( "fSizeZ > 0." ); fSizeZCmd->SetUnitCategory( "Length" ); fSizeZCmd->AvailableForStates( G4State_PreInit, G4State_Idle ); fSizeXYCmd = new G4UIcmdWithADoubleAndUnit( "/cb_sim/det/setSizeXY", this ); fSizeXYCmd->SetGuidance( "Set dimensions in x and y of the absorber" ); fSizeXYCmd->SetParameterName( "fSizeXY", false ); fSizeXYCmd->SetRange( "fSizeXY > 0." ); fSizeXYCmd->SetUnitCategory( "Length" ); fSizeXYCmd->AvailableForStates( G4State_PreInit, G4State_Idle ); fLayerSizeXYCmd = new G4UIcmdWithADoubleAndUnit( "/cb_sim/det/setSliceSizeXY", this ); fLayerSizeXYCmd->SetGuidance( "Set dimensions in x and y of the layers of the absorber" ); fLayerSizeXYCmd->SetParameterName( "fLayerSizeXY", false ); fLayerSizeXYCmd->SetRange( "fLayerSizeXY > 0." ); fLayerSizeXYCmd->SetUnitCategory( "Length" ); fLayerSizeXYCmd->AvailableForStates( G4State_PreInit, G4State_Idle ); fLayerNumberCmd = new G4UIcmdWithAnInteger( "/cb_sim/det/sliceNumber", this ); fLayerNumberCmd->SetGuidance( "Set number of layers in the absorber" ); fLayerNumberCmd->SetParameterName( "fNoOfLayers", false ); fLayerNumberCmd->SetRange(" fNoOfLayers >= 0" ); fLayerNumberCmd->AvailableForStates( G4State_PreInit, G4State_Idle ); fUpdateCmd = new G4UIcmdWithoutParameter( "/cb_sim/det/update", this ); fUpdateCmd->SetGuidance( "Update geometry of detector volume." ); fUpdateCmd->SetGuidance( "This command MUST be applied before \"beamOn\" " ); fUpdateCmd->SetGuidance( "if you changed geometrical value(s)." ); fUpdateCmd->AvailableForStates( G4State_Idle ); } DetectorMessenger::~DetectorMessenger() { delete fSimDir; delete fDetDir; delete fMatCmd; delete fPosCmd; delete fSizeZCmd; delete fSizeXYCmd; delete fLayerSizeXYCmd; delete fLayerNumberCmd; delete fUpdateCmd; } void DetectorMessenger::SetNewValue( G4UIcommand* command, G4String newValue ) { if ( command == fMatCmd ) { fDetector->SetMaterial( newValue ); } if ( command == fPosCmd ) { fDetector->SetDetPosition( fPosCmd->GetNew3VectorValue( newValue ) ); } if ( command == fSizeZCmd ) { fDetector->SetSizeZ( fSizeZCmd->GetNewDoubleValue( newValue ) ); } if ( command == fSizeXYCmd ) { fDetector->SetSizeXY( fSizeXYCmd->GetNewDoubleValue( newValue ) ); } if ( command == fLayerSizeXYCmd ) { fDetector->SetLayerSizeXY( fLayerSizeXYCmd->GetNewDoubleValue( newValue ) ); } if ( command == fLayerNumberCmd ) { fDetector->SetLayerNumber( fLayerNumberCmd->GetNewIntValue( newValue ) ); } if ( command == fUpdateCmd ) { fDetector->UpdateGeometry(); } }