File indexing completed on 2025-01-31 09:21:53
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
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #include <G4UIcmdWithAString.hh>
0045 #include <G4UIcmdWithADoubleAndUnit.hh>
0046 #include <G4UIcmdWith3Vector.hh>
0047 #include <G4UIcmdWith3VectorAndUnit.hh>
0048 #include <G4ParticleDefinition.hh>
0049 #include <G4ParticleTable.hh>
0050 #include "CexmcParticleGun.hh"
0051 #include "CexmcParticleGunMessenger.hh"
0052 #include "CexmcRunManager.hh"
0053 #include "CexmcException.hh"
0054 #include "CexmcMessenger.hh"
0055
0056
0057 CexmcParticleGunMessenger::CexmcParticleGunMessenger(
0058 CexmcParticleGun * particleGun_ ) :
0059 particleGun( particleGun_ ), setParticle( NULL ), setOrigPosition( NULL ),
0060 setOrigDirection( NULL ), setOrigMomentumAmp( NULL )
0061 {
0062 setParticle = new G4UIcmdWithAString(
0063 ( CexmcMessenger::gunDirName + "particle" ).c_str(), this );
0064 setParticle->SetGuidance( "Incident beam particle" );
0065 setParticle->SetParameterName( "BeamParticle", false );
0066 setParticle->SetCandidates( "pi-" );
0067 setParticle->SetDefaultValue( "pi-" );
0068 setParticle->AvailableForStates( G4State_PreInit, G4State_Idle );
0069
0070 setOrigPosition = new G4UIcmdWith3VectorAndUnit(
0071 ( CexmcMessenger::gunDirName + "position" ).c_str(), this );
0072 setOrigPosition->SetGuidance( "Original position of the beam" );
0073 setOrigPosition->SetParameterName( "PositionX", "PositionY", "PositionZ",
0074 false );
0075 setOrigPosition->SetUnitCandidates( "mm cm m" );
0076 setOrigPosition->SetDefaultUnit( "cm" );
0077 setOrigPosition->AvailableForStates( G4State_PreInit, G4State_Idle );
0078
0079 setOrigDirection = new G4UIcmdWith3Vector(
0080 ( CexmcMessenger::gunDirName + "direction" ).c_str(), this );
0081 setOrigDirection->SetGuidance( "Original direction of the beam" );
0082 setOrigDirection->SetParameterName( "DirectionX", "DirectionY",
0083 "DirectionZ", false );
0084 setOrigDirection->SetRange(
0085 "DirectionX >= -1.0 && DirectionX <= 1.0 && "
0086 "DirectionY >= -1.0 && DirectionY <= 1.0 && "
0087 "DirectionZ >= -1.0 && DirectionZ <= 1.0" );
0088 setOrigDirection->AvailableForStates( G4State_PreInit, G4State_Idle );
0089
0090 setOrigMomentumAmp = new G4UIcmdWithADoubleAndUnit(
0091 ( CexmcMessenger::gunDirName + "momentumAmp" ).c_str(), this );
0092 setOrigMomentumAmp->SetGuidance( "Original momentum of the beam" );
0093 setOrigMomentumAmp->SetParameterName( "MomentumAmp", false );
0094 setOrigMomentumAmp->SetRange( "MomentumAmp > 0" );
0095 setOrigMomentumAmp->SetUnitCandidates( "eV keV MeV GeV" );
0096 setOrigMomentumAmp->SetDefaultUnit( "MeV" );
0097 setOrigMomentumAmp->AvailableForStates( G4State_PreInit, G4State_Idle );
0098 }
0099
0100
0101 CexmcParticleGunMessenger::~CexmcParticleGunMessenger()
0102 {
0103 delete setParticle;
0104 delete setOrigPosition;
0105 delete setOrigDirection;
0106 delete setOrigMomentumAmp;
0107 }
0108
0109
0110 void CexmcParticleGunMessenger::SetNewValue( G4UIcommand * cmd,
0111 G4String value )
0112 {
0113 do
0114 {
0115 if ( cmd == setParticle )
0116 {
0117 G4ParticleDefinition * particleDefinition(
0118 G4ParticleTable::GetParticleTable()->FindParticle( value ) );
0119
0120 if ( ! particleDefinition )
0121 throw CexmcException( CexmcWeirdException );
0122
0123 particleGun->SetBeamParticle( particleDefinition );
0124
0125 CexmcRunManager * runManager( static_cast< CexmcRunManager * >(
0126 G4RunManager::GetRunManager() ) );
0127 runManager->BeamParticleChangeHook();
0128 break;
0129 }
0130 if ( cmd == setOrigPosition )
0131 {
0132 particleGun->SetOrigPosition(
0133 G4UIcmdWith3VectorAndUnit::GetNew3VectorValue( value ) );
0134 break;
0135 }
0136 if ( cmd == setOrigDirection )
0137 {
0138 particleGun->SetOrigDirection(
0139 G4UIcmdWith3Vector::GetNew3VectorValue( value ) );
0140 break;
0141 }
0142 if ( cmd == setOrigMomentumAmp )
0143 {
0144 particleGun->SetOrigMomentumAmp(
0145 G4UIcmdWithADoubleAndUnit::GetNewDoubleValue( value ) );
0146 break;
0147 }
0148 } while ( false );
0149 }
0150