Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ParticleGunMessenger Class Reference

#include <G4ParticleGunMessenger.hh>

Inheritance diagram for G4ParticleGunMessenger:
Collaboration diagram for G4ParticleGunMessenger:

Public Member Functions

 G4ParticleGunMessenger (G4ParticleGun *fPtclGun)
 
 ~G4ParticleGunMessenger ()
 
void SetNewValue (G4UIcommand *command, G4String newValues)
 
G4String GetCurrentValue (G4UIcommand *command)
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()
 
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
G4bool operator== (const G4UImessenger &messenger) const
 
G4bool CommandsShouldBeInMaster () const
 

Additional Inherited Members

- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (G4String s)
 
G4double StoD (G4String s)
 
G4bool StoB (G4String s)
 
void AddUIcommand (G4UIcommand *newCommand)
 
void CreateDirectory (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
template<typename T >
T * CreateCommand (const G4String &cname, const G4String &dsc)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir
 
G4String baseDirName
 
G4bool commandsShouldBeInMaster
 

Detailed Description

Definition at line 54 of file G4ParticleGunMessenger.hh.

Constructor & Destructor Documentation

G4ParticleGunMessenger::G4ParticleGunMessenger ( G4ParticleGun fPtclGun)

Definition at line 47 of file G4ParticleGunMessenger.cc.

48  :fParticleGun(fPtclGun),fShootIon(false),
49  fAtomicNumber(0),fAtomicMass(0),fIonCharge(0),fIonExciteEnergy(0.0),
50  fIonFloatingLevelBase('\0'),fIonEnergyLevel(0)
51 {
52  particleTable = G4ParticleTable::GetParticleTable();
53 
54  gunDirectory = new G4UIdirectory("/gun/");
55  gunDirectory->SetGuidance("Particle Gun control commands.");
56 
57  listCmd = new G4UIcmdWithoutParameter("/gun/List",this);
58  listCmd->SetGuidance("List available particles.");
59  listCmd->SetGuidance(" Invoke G4ParticleTable.");
60 
61  particleCmd = new G4UIcmdWithAString("/gun/particle",this);
62  particleCmd->SetGuidance("Set particle to be generated.");
63  particleCmd->SetGuidance(" (geantino is default)");
64  particleCmd->SetGuidance(" (ion can be specified for shooting ions)");
65  particleCmd->SetParameterName("particleName",true);
66  particleCmd->SetDefaultValue("geantino");
67  G4String candidateList;
68  G4ParticleTable::G4PTblDicIterator* itr = particleTable->GetIterator();
69  itr->reset();
70  while( (*itr)() )
71  {
72  G4ParticleDefinition* pd = itr->value();
73  if( !(pd->IsShortLived()) || pd->GetDecayTable() )
74  {
75  candidateList += pd->GetParticleName();
76  candidateList += " ";
77  }
78  }
79  candidateList += "ion ";
80  particleCmd->SetCandidates(candidateList);
81 
82  directionCmd = new G4UIcmdWith3Vector("/gun/direction",this);
83  directionCmd->SetGuidance("Set momentum direction.");
84  directionCmd->SetGuidance("Direction needs not to be a unit vector.");
85  directionCmd->SetParameterName("ex","ey","ez",true,true);
86  directionCmd->SetRange("ex != 0 || ey != 0 || ez != 0");
87 
88  energyCmd = new G4UIcmdWithADoubleAndUnit("/gun/energy",this);
89  energyCmd->SetGuidance("Set kinetic energy.");
90  energyCmd->SetParameterName("Energy",true,true);
91  energyCmd->SetDefaultUnit("GeV");
92  //energyCmd->SetUnitCategory("Energy");
93  //energyCmd->SetUnitCandidates("eV keV MeV GeV TeV");
94 
95  momCmd = new G4UIcmdWith3VectorAndUnit("/gun/momentum",this);
96  momCmd->SetGuidance("Set momentum. This command is equivalent to two commands /gun/direction and /gun/momentumAmp");
97  momCmd->SetParameterName("px","py","pz",true,true);
98  momCmd->SetRange("px != 0 || py != 0 || pz != 0");
99  momCmd->SetDefaultUnit("GeV");
100 
101  momAmpCmd = new G4UIcmdWithADoubleAndUnit("/gun/momentumAmp",this);
102  momAmpCmd->SetGuidance("Set absolute value of momentum.");
103  momAmpCmd->SetGuidance("Direction should be set by /gun/direction command.");
104  momAmpCmd->SetGuidance("This command should be used alternatively with /gun/energy.");
105  momAmpCmd->SetParameterName("Momentum",true,true);
106  momAmpCmd->SetDefaultUnit("GeV");
107 
108  positionCmd = new G4UIcmdWith3VectorAndUnit("/gun/position",this);
109  positionCmd->SetGuidance("Set starting position of the particle.");
110  positionCmd->SetParameterName("X","Y","Z",true,true);
111  positionCmd->SetDefaultUnit("cm");
112  //positionCmd->SetUnitCategory("Length");
113  //positionCmd->SetUnitCandidates("microm mm cm m km");
114 
115  timeCmd = new G4UIcmdWithADoubleAndUnit("/gun/time",this);
116  timeCmd->SetGuidance("Set initial time of the particle.");
117  timeCmd->SetParameterName("t0",true,true);
118  timeCmd->SetDefaultUnit("ns");
119  //timeCmd->SetUnitCategory("Time");
120  //timeCmd->SetUnitCandidates("ns ms s");
121 
122  polCmd = new G4UIcmdWith3Vector("/gun/polarization",this);
123  polCmd->SetGuidance("Set polarization.");
124  polCmd->SetParameterName("Px","Py","Pz",true,true);
125  polCmd->SetRange("Px>=-1.&&Px<=1.&&Py>=-1.&&Py<=1.&&Pz>=-1.&&Pz<=1.");
126 
127  numberCmd = new G4UIcmdWithAnInteger("/gun/number",this);
128  numberCmd->SetGuidance("Set number of particles to be generated.");
129  numberCmd->SetParameterName("N",true,true);
130  numberCmd->SetRange("N>0");
131 
132  ionCmd = new G4UIcommand("/gun/ion",this);
133  ionCmd->SetGuidance("Set properties of ion to be generated.");
134  ionCmd->SetGuidance("[usage] /gun/ion Z A [Q E flb]");
135  ionCmd->SetGuidance(" Z:(int) AtomicNumber");
136  ionCmd->SetGuidance(" A:(int) AtomicMass");
137  ionCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)");
138  ionCmd->SetGuidance(" E:(double) Excitation energy (in keV)");
139  ionCmd->SetGuidance(" flb:(char) Floating level base");
140 
141  G4UIparameter* param;
142  param = new G4UIparameter("Z",'i',false);
143  ionCmd->SetParameter(param);
144  param = new G4UIparameter("A",'i',false);
145  ionCmd->SetParameter(param);
146  param = new G4UIparameter("Q",'i',true);
147  param->SetDefaultValue(-1);
148  ionCmd->SetParameter(param);
149  param = new G4UIparameter("E",'d',true);
150  param->SetDefaultValue(0.0);
151  ionCmd->SetParameter(param);
152  param = new G4UIparameter("flb",'c',true);
153  param->SetDefaultValue("noFloat");
154  param->SetParameterCandidates("noFloat X Y Z U V W R S T A B C D E");
155  ionCmd->SetParameter(param);
156 
157  ionLvlCmd = new G4UIcommand("/gun/ionL",this);
158  ionLvlCmd->SetGuidance("Set properties of ion to be generated.");
159  ionLvlCmd->SetGuidance("[usage] /gun/ionL Z A [Q I]");
160  ionLvlCmd->SetGuidance(" Z:(int) AtomicNumber");
161  ionLvlCmd->SetGuidance(" A:(int) AtomicMass");
162  ionLvlCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)");
163  ionLvlCmd->SetGuidance(" I:(int) Level number of metastable state (0 = ground)");
164 
165  G4UIparameter* paraml;
166  paraml = new G4UIparameter("Z",'i',false);
167  ionLvlCmd->SetParameter(paraml);
168  paraml = new G4UIparameter("A",'i',false);
169  ionLvlCmd->SetParameter(paraml);
170  paraml = new G4UIparameter("Q",'i',true);
171  paraml->SetDefaultValue(-1);
172  ionLvlCmd->SetParameter(paraml);
173  paraml = new G4UIparameter("I",'i',true);
174  paraml->SetDefaultValue("0");
175  ionLvlCmd->SetParameter(paraml);
176 
177  // set initial value to G4ParticleGun
178  fParticleGun->SetParticleDefinition( G4Geantino::Geantino() );
179  fParticleGun->SetParticleMomentumDirection( G4ThreeVector(1.0,0.0,0.0) );
180  fParticleGun->SetParticleEnergy( 1.0*GeV );
181  fParticleGun->SetParticlePosition(G4ThreeVector(0.0*cm, 0.0*cm, 0.0*cm));
182  fParticleGun->SetParticleTime( 0.0*ns );
183 }
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
CLHEP::Hep3Vector G4ThreeVector
void SetParameterCandidates(const char *theString)
void SetDefaultUnit(const char *defUnit)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(const char *theDefaultValue)
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
const G4String & GetParticleName() const
G4DecayTable * GetDecayTable() const
void SetParticlePosition(G4ThreeVector aPosition)
void reset(G4bool ifSkipIon=true)
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
static constexpr double cm
Definition: G4SIunits.hh:119
void SetParticleEnergy(G4double aKineticEnergy)
static G4ParticleTable * GetParticleTable()
void SetDefaultValue(const char *defVal)
void SetDefaultUnit(const char *defUnit)
static constexpr double GeV
Definition: G4SIunits.hh:217
static G4Geantino * Geantino()
Definition: G4Geantino.cc:87
void SetCandidates(const char *candidateList)
G4PTblDicIterator * GetIterator() const
#define ns
Definition: xmlparse.cc:614
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
void SetParticleTime(G4double aTime)

Here is the call graph for this function:

G4ParticleGunMessenger::~G4ParticleGunMessenger ( )

Definition at line 185 of file G4ParticleGunMessenger.cc.

186 {
187  delete listCmd;
188  delete particleCmd;
189  delete directionCmd;
190  delete energyCmd;
191  delete momCmd;
192  delete momAmpCmd;
193  delete positionCmd;
194  delete timeCmd;
195  delete polCmd;
196  delete numberCmd;
197  delete ionCmd;
198  delete ionLvlCmd;
199  delete gunDirectory;
200 }

Member Function Documentation

G4String G4ParticleGunMessenger::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 238 of file G4ParticleGunMessenger.cc.

239 {
240  G4String cv;
241 
242  if( command==directionCmd )
243  { cv = directionCmd->ConvertToString(fParticleGun->GetParticleMomentumDirection()); }
244  else if( command==particleCmd )
245  { cv = fParticleGun->GetParticleDefinition()->GetParticleName(); }
246  else if( command==energyCmd )
247  {
248  G4double ene = fParticleGun->GetParticleEnergy();
249  if(ene == 0.)
250  { G4cerr << " G4ParticleGun: was defined in terms of momentum." << G4endl; }
251  else
252  { cv = energyCmd->ConvertToString(ene,"GeV"); }
253  }
254  else if( command==momCmd || command==momAmpCmd )
255  {
256  G4double mom = fParticleGun->GetParticleMomentum();
257  if(mom == 0.)
258  { G4cerr << " G4ParticleGun: was defined in terms of kinetic energy." << G4endl; }
259  else
260  {
261  if( command==momCmd )
262  { cv = momCmd->ConvertToString(mom*(fParticleGun->GetParticleMomentumDirection()),"GeV"); }
263  else
264  { cv = momAmpCmd->ConvertToString(mom,"GeV"); }
265  }
266  }
267  else if( command==positionCmd )
268  { cv = positionCmd->ConvertToString(fParticleGun->GetParticlePosition(),"cm"); }
269  else if( command==timeCmd )
270  { cv = timeCmd->ConvertToString(fParticleGun->GetParticleTime(),"ns"); }
271  else if( command==polCmd )
272  { cv = polCmd->ConvertToString(fParticleGun->GetParticlePolarization()); }
273  else if( command==numberCmd )
274  { cv = numberCmd->ConvertToString(fParticleGun->GetNumberOfParticles()); }
275  else if( command==ionCmd )
276  {
277  if (fShootIon) {
278  cv = ItoS(fAtomicNumber) + " " + ItoS(fAtomicMass) + " ";
279  cv += ItoS(fIonCharge);
280  } else {
281  cv = "";
282  }
283  }
284  return cv;
285 }
G4double GetParticleMomentum() const
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:372
G4ThreeVector GetParticlePosition()
const G4String & GetParticleName() const
G4ParticleMomentum GetParticleMomentumDirection() const
G4ThreeVector GetParticlePolarization() const
G4String ItoS(G4int i)
G4int GetNumberOfParticles() const
G4ParticleDefinition * GetParticleDefinition() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4double GetParticleEnergy() const
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

void G4ParticleGunMessenger::SetNewValue ( G4UIcommand command,
G4String  newValues 
)
virtual

Reimplemented from G4UImessenger.

Definition at line 202 of file G4ParticleGunMessenger.cc.

203 {
204  if (command==listCmd) {
205  particleTable->DumpTable();
206  } else if (command==particleCmd) {
207  if (newValues =="ion") {
208  fShootIon = true;
209  } else {
210  fShootIon = false;
211  G4ParticleDefinition* pd = particleTable->FindParticle(newValues);
212  if(pd != 0)
213  { fParticleGun->SetParticleDefinition( pd ); }
214  }
215 
216  } else if( command==directionCmd )
217  { fParticleGun->SetParticleMomentumDirection(directionCmd->GetNew3VectorValue(newValues)); }
218  else if( command==energyCmd )
219  { fParticleGun->SetParticleEnergy(energyCmd->GetNewDoubleValue(newValues)); }
220  else if( command==momCmd )
221  { fParticleGun->SetParticleMomentum(momCmd->GetNew3VectorValue(newValues)); }
222  else if( command==momAmpCmd )
223  { fParticleGun->SetParticleMomentum(momAmpCmd->GetNewDoubleValue(newValues)); }
224  else if( command==positionCmd )
225  { fParticleGun->SetParticlePosition(positionCmd->GetNew3VectorValue(newValues)); }
226  else if( command==timeCmd )
227  { fParticleGun->SetParticleTime(timeCmd->GetNewDoubleValue(newValues)); }
228  else if( command==polCmd )
229  { fParticleGun->SetParticlePolarization(polCmd->GetNew3VectorValue(newValues)); }
230  else if( command==numberCmd )
231  { fParticleGun->SetNumberOfParticles(numberCmd->GetNewIntValue(newValues)); }
232  else if( command==ionCmd )
233  { IonCommand(newValues); }
234  else if( command==ionLvlCmd )
235  { IonLevelCommand(newValues); }
236 }
void SetParticleMomentum(G4double aMomentum)
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
void DumpTable(const G4String &particle_name="ALL")
static G4int GetNewIntValue(const char *paramString)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
static G4double GetNewDoubleValue(const char *paramString)
void SetParticlePolarization(G4ThreeVector aVal)
void SetParticlePosition(G4ThreeVector aPosition)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
void SetNumberOfParticles(G4int i)
void SetParticleEnergy(G4double aKineticEnergy)
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
void SetParticleTime(G4double aTime)

Here is the call graph for this function:


The documentation for this class was generated from the following files: