Heading Inclusions

#include "B2aDetectorMessenger.hh" #include "B2aDetectorConstruction.hh" #include "G4UIdirectory.hh" #include "G4UIcmdWithAString.hh" #include "G4UIcmdWithADoubleAndUnit.hh"

Constructor

B2aDetectorMessenger::B2aDetectorMessenger(B2aDetectorConstruction* Det) : G4UImessenger(), fDetectorConstruction(Det) { fB2Directory = new G4UIdirectory("/B2/"); fB2Directory->SetGuidance("UI commands specific to this example."); fDetDirectory = new G4UIdirectory("/B2/det/"); fDetDirectory->SetGuidance("Detector construction control"); fTargMatCmd = new G4UIcmdWithAString("/B2/det/setTargetMaterial",this); fTargMatCmd->SetGuidance("Select Material of the Target."); fTargMatCmd->SetParameterName("choice",false); fTargMatCmd->AvailableForStates(G4State_PreInit,G4State_Idle); // fChamMatCmd = new G4UIcmdWithAString("/B2/det/setChamberMaterial",this); // fChamMatCmd->SetGuidance("Select Material of the Chamber."); // fChamMatCmd->SetParameterName("choice",false); // fChamMatCmd->AvailableForStates(G4State_PreInit,G4State_Idle); fStepMaxCmd = new G4UIcmdWithADoubleAndUnit("/B2/det/stepMax",this); fStepMaxCmd->SetGuidance("Define a step max"); fStepMaxCmd->SetParameterName("stepMax",false); fStepMaxCmd->SetUnitCategory("Length"); fStepMaxCmd->AvailableForStates(G4State_Idle);

This constructor initializes the messenger and sets up UI commands:

Destructor

B2aDetectorMessenger::~B2aDetectorMessenger() { delete fTargMatCmd; delete fChamMatCmd; delete fStepMaxCmd; delete fB2Directory; delete fDetDirectory; }

This destructor cleans up the allocated UI command objects.

Set New Value Method

void B2aDetectorMessenger::SetNewValue(G4UIcommand* command,G4String newValue) { if( command == fTargMatCmd ) { fDetectorConstruction->SetTargetMaterial(newValue);} // if( command == fChamMatCmd ) // { fDetectorConstruction->SetChamberMaterial(newValue);} if( command == fStepMaxCmd ) { fDetectorConstruction ->SetMaxStep(fStepMaxCmd->GetNewDoubleValue(newValue)); } }

This method is called when a UI command is issued. It handles:

Key Points: