Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ParticleGunMessenger Class Reference

#include <G4ParticleGunMessenger.hh>

+ Inheritance diagram for G4ParticleGunMessenger:

Public Member Functions

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

Additional Inherited Members

- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String LtoS (G4long l)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (const G4String &s)
 
G4long StoL (const G4String &s)
 
G4double StoD (const 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 = nullptr
 
G4String baseDirName = ""
 
G4bool commandsShouldBeInMaster = false
 

Detailed Description

Definition at line 52 of file G4ParticleGunMessenger.hh.

Constructor & Destructor Documentation

◆ G4ParticleGunMessenger()

G4ParticleGunMessenger::G4ParticleGunMessenger ( G4ParticleGun * fPtclGun)
explicit

Definition at line 48 of file G4ParticleGunMessenger.cc.

49 : fParticleGun(fPtclGun)
50{
51 particleTable = G4ParticleTable::GetParticleTable();
52
53 gunDirectory = new G4UIdirectory("/gun/");
54 gunDirectory->SetGuidance("Particle Gun control commands.");
55
56 listCmd = new G4UIcmdWithoutParameter("/gun/List",this);
57 listCmd->SetGuidance("List available particles.");
58 listCmd->SetGuidance(" Invoke G4ParticleTable.");
59
60 particleCmd = new G4UIcmdWithAString("/gun/particle",this);
61 particleCmd->SetGuidance("Set particle to be generated.");
62 particleCmd->SetGuidance(" (geantino is default)");
63 particleCmd->SetGuidance(" (ion can be specified for shooting ions)");
64 particleCmd->SetParameterName("particleName",true);
65 particleCmd->SetDefaultValue("geantino");
66 G4String candidateList;
67 G4ParticleTable::G4PTblDicIterator* itr = particleTable->GetIterator();
68 itr->reset();
69 while( (*itr)() )
70 {
71 G4ParticleDefinition* pd = itr->value();
72 if( !(pd->IsShortLived()) || pd->GetDecayTable() != nullptr )
73 {
74 candidateList += pd->GetParticleName();
75 candidateList += " ";
76 }
77 }
78 candidateList += "ion ";
79 particleCmd->SetCandidates(candidateList);
80
81 directionCmd = new G4UIcmdWith3Vector("/gun/direction",this);
82 directionCmd->SetGuidance("Set momentum direction.");
83 directionCmd->SetGuidance(" Direction needs not to be a unit vector.");
84 directionCmd->SetParameterName("ex","ey","ez",true,true);
85 directionCmd->SetRange("ex != 0 || ey != 0 || ez != 0");
86
87 energyCmd = new G4UIcmdWithADoubleAndUnit("/gun/energy",this);
88 energyCmd->SetGuidance("Set kinetic energy.");
89 energyCmd->SetParameterName("Energy",true,true);
90 energyCmd->SetDefaultUnit("GeV");
91 //energyCmd->SetUnitCategory("Energy");
92 //energyCmd->SetUnitCandidates("eV keV MeV GeV TeV");
93
94 momCmd = new G4UIcmdWith3VectorAndUnit("/gun/momentum",this);
95 momCmd->SetGuidance("Set momentum. This command is equivalent to two commands");
96 momCmd->SetGuidance(" /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("THIS COMMAND IS DEPRECATED and will be removed in future releases.");
159 ionLvlCmd->SetGuidance(" Use /gun/ion instead.");
160 ionLvlCmd->SetGuidance(" Set properties of ion to be generated.");
161 ionLvlCmd->SetGuidance(" [usage] /gun/ionL Z A [Q I]");
162 ionLvlCmd->SetGuidance(" Z:(int) AtomicNumber");
163 ionLvlCmd->SetGuidance(" A:(int) AtomicMass");
164 ionLvlCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)");
165 ionLvlCmd->SetGuidance(" I:(int) Level number of metastable state (0 = ground)");
166
167 G4UIparameter* paraml;
168 paraml = new G4UIparameter("Z",'i',false);
169 ionLvlCmd->SetParameter(paraml);
170 paraml = new G4UIparameter("A",'i',false);
171 ionLvlCmd->SetParameter(paraml);
172 paraml = new G4UIparameter("Q",'i',true);
173 paraml->SetDefaultValue(-1);
174 ionLvlCmd->SetParameter(paraml);
175 paraml = new G4UIparameter("I",'i',true);
176 paraml->SetDefaultValue("0");
177 ionLvlCmd->SetParameter(paraml);
178
179 // Set initial value to G4ParticleGun
180 //
182 fParticleGun->SetParticleMomentumDirection( G4ThreeVector(1.0,0.0,0.0) );
183 fParticleGun->SetParticleEnergy( 1.0*GeV );
184 fParticleGun->SetParticlePosition(G4ThreeVector(0.0*cm, 0.0*cm, 0.0*cm));
185 fParticleGun->SetParticleTime( 0.0*ns );
186}
CLHEP::Hep3Vector G4ThreeVector
static G4Geantino * Geantino()
Definition G4Geantino.cc:81
G4DecayTable * GetDecayTable() const
const G4String & GetParticleName() const
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
void SetParticleEnergy(G4double aKineticEnergy)
void SetParticleMomentumDirection(G4ParticleMomentum aMomDirection)
void reset(G4bool ifSkipIon=true)
G4PTblDicIterator * GetIterator() const
static G4ParticleTable * GetParticleTable()
void SetDefaultUnit(const char *defUnit)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultUnit(const char *defUnit)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetCandidates(const char *candidateList)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(const char *defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
void SetGuidance(const char *aGuidance)
void SetRange(const char *rs)
void SetDefaultValue(const char *theDefaultValue)
void SetParameterCandidates(const char *theString)
void SetParticleTime(G4double aTime)
void SetParticlePosition(G4ThreeVector aPosition)

◆ ~G4ParticleGunMessenger()

G4ParticleGunMessenger::~G4ParticleGunMessenger ( )
override

Definition at line 188 of file G4ParticleGunMessenger.cc.

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

Member Function Documentation

◆ GetCurrentValue()

G4String G4ParticleGunMessenger::GetCurrentValue ( G4UIcommand * command)
overridevirtual

Reimplemented from G4UImessenger.

Definition at line 282 of file G4ParticleGunMessenger.cc.

283{
284 G4String cv;
285
286 if( command==directionCmd )
287 { cv = directionCmd->ConvertToString(fParticleGun->GetParticleMomentumDirection()); }
288 else if( command==particleCmd )
289 { cv = fParticleGun->GetParticleDefinition()->GetParticleName(); }
290 else if( command==energyCmd )
291 {
292 G4double ene = fParticleGun->GetParticleEnergy();
293 if(ene == 0.)
294 { G4cerr << " G4ParticleGun: was defined in terms of momentum." << G4endl; }
295 else
296 { cv = energyCmd->ConvertToString(ene,"GeV"); }
297 }
298 else if( command==momCmd || command==momAmpCmd )
299 {
300 G4double mom = fParticleGun->GetParticleMomentum();
301 if(mom == 0.)
302 {
303 G4cerr << " G4ParticleGun: was defined in terms of kinetic energy."
304 << G4endl;
305 }
306 else
307 {
308 if( command==momCmd )
309 { cv = momCmd->ConvertToString(mom*(fParticleGun->GetParticleMomentumDirection()),"GeV"); }
310 else
311 { cv = momAmpCmd->ConvertToString(mom,"GeV"); }
312 }
313 }
314 else if( command==positionCmd )
315 { cv = positionCmd->ConvertToString(fParticleGun->GetParticlePosition(),"cm"); }
316 else if( command==timeCmd )
317 { cv = timeCmd->ConvertToString(fParticleGun->GetParticleTime(),"ns"); }
318 else if( command==polCmd )
319 { cv = polCmd->ConvertToString(fParticleGun->GetParticlePolarization()); }
320 else if( command==numberCmd )
321 { cv = numberCmd->ConvertToString(fParticleGun->GetNumberOfParticles()); }
322 else if( command==ionCmd )
323 {
324 if (fShootIon)
325 {
326 cv = ItoS(fAtomicNumber) + " " + ItoS(fAtomicMass) + " ";
327 cv += ItoS(fIonCharge);
328 }
329 else
330 {
331 cv = "";
332 }
333 }
334 return cv;
335}
double G4double
Definition G4Types.hh:83
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4ThreeVector GetParticlePolarization() const
G4ParticleMomentum GetParticleMomentumDirection() const
G4double GetParticleMomentum() const
G4ParticleDefinition * GetParticleDefinition() const
G4int GetNumberOfParticles() const
G4double GetParticleEnergy() const
static G4String ConvertToString(G4bool boolVal)
G4String ItoS(G4int i)
G4ThreeVector GetParticlePosition()

◆ SetNewValue()

void G4ParticleGunMessenger::SetNewValue ( G4UIcommand * command,
G4String newValues )
overridevirtual

Reimplemented from G4UImessenger.

Definition at line 205 of file G4ParticleGunMessenger.cc.

207{
209 if (command==listCmd)
210 {
211 particleTable->DumpTable();
212 }
213 else if (command==particleCmd)
214 {
215 if (newValues =="ion")
216 {
217 fShootIon = true;
218 }
219 else
220 {
221 fShootIon = false;
222 G4ParticleDefinition* pd = particleTable->FindParticle(newValues);
223 if(pd != nullptr)
224 {
225 fParticleGun->SetParticleDefinition( pd );
226 }
227 else
228 {
229 ed << "Particle [" << newValues << "] is not found.";
230 command->CommandFailed(ed);
231 }
232 }
233
234 } else if( command==directionCmd )
235 { fParticleGun->SetParticleMomentumDirection(directionCmd->GetNew3VectorValue(newValues)); }
236 else if( command==energyCmd )
237 { fParticleGun->SetParticleEnergy(energyCmd->GetNewDoubleValue(newValues)); }
238 else if( command==momCmd )
239 { fParticleGun->SetParticleMomentum(momCmd->GetNew3VectorValue(newValues)); }
240 else if( command==momAmpCmd )
241 { fParticleGun->SetParticleMomentum(momAmpCmd->GetNewDoubleValue(newValues)); }
242 else if( command==positionCmd )
243 { fParticleGun->SetParticlePosition(positionCmd->GetNew3VectorValue(newValues)); }
244 else if( command==timeCmd )
245 { fParticleGun->SetParticleTime(timeCmd->GetNewDoubleValue(newValues)); }
246 else if( command==polCmd )
247 { fParticleGun->SetParticlePolarization(polCmd->GetNew3VectorValue(newValues)); }
248 else if( command==numberCmd )
249 { fParticleGun->SetNumberOfParticles(numberCmd->GetNewIntValue(newValues)); }
250 else if( command==ionCmd )
251 {
252 if (fShootIon)
253 {
254 IonCommand(newValues);
255 }
256 else
257 {
258 ed << "Set /gun/particle to ion before using /gun/ion command";
259 command->CommandFailed(ed);
260 }
261 }
262 else if( command==ionLvlCmd )
263 {
264 G4ExceptionDescription depWarn;
265 depWarn << "\nCommand /gun/ionL is deprecated and will be removed in future releases.\n"
266 << "Use /gun/ion instead.\n";
267 G4Exception("G4ParticleGunMessenger::SetNewValue", "IonLWarn",
268 JustWarning, depWarn);
269
270 if (fShootIon)
271 {
272 IonLevelCommand(newValues);
273 }
274 else
275 {
276 ed << "Set /gun/particle to ion before using /gun/ion command";
277 command->CommandFailed(ed);
278 }
279 }
280}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
void SetNumberOfParticles(G4int i)
void SetParticlePolarization(G4ThreeVector aVal)
void SetParticleMomentum(G4double aMomentum)
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
void DumpTable(const G4String &particle_name="ALL")
static G4ThreeVector GetNew3VectorValue(const char *paramString)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
static G4double GetNewDoubleValue(const char *paramString)
static G4int GetNewIntValue(const char *paramString)
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)

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