Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:21:53

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /*
0027  * ============================================================================
0028  *
0029  *       Filename:  CexmcParticleGunMessenger.cc
0030  *
0031  *    Description:  original position and momentum of the incident beam particle
0032  *
0033  *        Version:  1.0
0034  *        Created:  15.12.2009 14:02:01
0035  *       Revision:  none
0036  *       Compiler:  gcc
0037  *
0038  *         Author:  Alexey Radkov (), 
0039  *        Company:  PNPI
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