Geant4 11.4.0
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 (const 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 53 of file G4ParticleGunMessenger.hh.

Constructor & Destructor Documentation

◆ G4ParticleGunMessenger()

G4ParticleGunMessenger::G4ParticleGunMessenger ( G4ParticleGun * fPtclGun)
explicit

Definition at line 49 of file G4ParticleGunMessenger.cc.

50 : fParticleGun(fPtclGun)
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() != nullptr )
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");
97 momCmd->SetGuidance(" /gun/direction and /gun/momentumAmp");
98 momCmd->SetParameterName("px","py","pz",true,true);
99 momCmd->SetRange("px != 0 || py != 0 || pz != 0");
100 momCmd->SetDefaultUnit("GeV");
101
102 momAmpCmd = new G4UIcmdWithADoubleAndUnit("/gun/momentumAmp",this);
103 momAmpCmd->SetGuidance("Set absolute value of momentum.");
104 momAmpCmd->SetGuidance(" Direction should be set by /gun/direction command.");
105 momAmpCmd->SetGuidance(" This command should be used alternatively with /gun/energy.");
106 momAmpCmd->SetParameterName("Momentum",true,true);
107 momAmpCmd->SetDefaultUnit("GeV");
108
109 positionCmd = new G4UIcmdWith3VectorAndUnit("/gun/position",this);
110 positionCmd->SetGuidance("Set starting position of the particle.");
111 positionCmd->SetGuidance(" Position must be located inside the world volume.");
112 positionCmd->SetParameterName("X","Y","Z",true,true);
113 positionCmd->SetDefaultUnit("cm");
114 // positionCmd->SetUnitCategory("Length");
115 // positionCmd->SetUnitCandidates("microm mm cm m km");
116
117 timeCmd = new G4UIcmdWithADoubleAndUnit("/gun/time",this);
118 timeCmd->SetGuidance("Set initial time of the particle.");
119 timeCmd->SetParameterName("t0",true,true);
120 timeCmd->SetDefaultUnit("ns");
121 // timeCmd->SetUnitCategory("Time");
122 // timeCmd->SetUnitCandidates("ns ms s");
123
124 polCmd = new G4UIcmdWith3Vector("/gun/polarization",this);
125 polCmd->SetGuidance("Set polarization.");
126 polCmd->SetParameterName("Px","Py","Pz",true,true);
127 polCmd->SetRange("Px>=-1.&&Px<=1.&&Py>=-1.&&Py<=1.&&Pz>=-1.&&Pz<=1.");
128
129 numberCmd = new G4UIcmdWithAnInteger("/gun/number",this);
130 numberCmd->SetGuidance("Set number of particles to be generated.");
131 numberCmd->SetParameterName("N",true,true);
132 numberCmd->SetRange("N>0");
133
134 ionCmd = new G4UIcommand("/gun/ion",this);
135 ionCmd->SetGuidance("Set properties of ion to be generated.");
136 ionCmd->SetGuidance("[usage] /gun/ion Z A [Q E flb]");
137 ionCmd->SetGuidance(" Z:(int) AtomicNumber");
138 ionCmd->SetGuidance(" A:(int) AtomicMass");
139 ionCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)");
140 ionCmd->SetGuidance(" E:(double) Excitation energy (in keV)");
141 ionCmd->SetGuidance(" flb:(char) Floating level base");
142
143 G4UIparameter* param;
144 param = new G4UIparameter("Z",'i',false);
145 ionCmd->SetParameter(param);
146 param = new G4UIparameter("A",'i',false);
147 ionCmd->SetParameter(param);
148 param = new G4UIparameter("Q",'i',true);
149 param->SetDefaultValue(-1);
150 ionCmd->SetParameter(param);
151 param = new G4UIparameter("E",'d',true);
152 param->SetDefaultValue(0.0);
153 ionCmd->SetParameter(param);
154 param = new G4UIparameter("flb",'c',true);
155 param->SetDefaultValue("noFloat");
156 param->SetParameterCandidates("noFloat X Y Z U V W R S T A B C D E");
157 ionCmd->SetParameter(param);
158
159 ionLvlCmd = new G4UIcommand("/gun/ionL",this);
160 ionLvlCmd->SetGuidance("THIS COMMAND IS DEPRECATED and will be removed in future releases.");
161 ionLvlCmd->SetGuidance(" Use /gun/ion instead.");
162 ionLvlCmd->SetGuidance(" Set properties of ion to be generated.");
163 ionLvlCmd->SetGuidance(" [usage] /gun/ionL Z A [Q I]");
164 ionLvlCmd->SetGuidance(" Z:(int) AtomicNumber");
165 ionLvlCmd->SetGuidance(" A:(int) AtomicMass");
166 ionLvlCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)");
167 ionLvlCmd->SetGuidance(" I:(int) Level number of metastable state (0 = ground)");
168
169 G4UIparameter* paraml;
170 paraml = new G4UIparameter("Z",'i',false);
171 ionLvlCmd->SetParameter(paraml);
172 paraml = new G4UIparameter("A",'i',false);
173 ionLvlCmd->SetParameter(paraml);
174 paraml = new G4UIparameter("Q",'i',true);
175 paraml->SetDefaultValue(-1);
176 ionLvlCmd->SetParameter(paraml);
177 paraml = new G4UIparameter("I",'i',true);
178 paraml->SetDefaultValue("0");
179 ionLvlCmd->SetParameter(paraml);
180
181 volChkCmd = new G4UIcmdWithABool("/gun/checkVolume",this);
182 volChkCmd->SetGuidance("Switch on/off the check if the vertex position is inside the world volume.");
183 volChkCmd->SetGuidance("By default the check is on. There is a small performance gain if this check is off,");
184 volChkCmd->SetGuidance("but the user has to make sure setting the vertex position inside the world.");
185 volChkCmd->SetParameterName("switch",true,true);
186
187 // Set initial value to G4ParticleGun
188 //
189 fParticleGun->SetParticleDefinition( G4Geantino::Geantino() );
190 fParticleGun->SetParticleMomentumDirection( G4ThreeVector(1.0,0.0,0.0) );
191 fParticleGun->SetParticleEnergy( 1.0*GeV );
192 fParticleGun->SetParticleTime( 0.0*ns );
193}
CLHEP::Hep3Vector G4ThreeVector
static G4Geantino * Geantino()
Definition G4Geantino.cc:81
G4DecayTable * GetDecayTable() const
const G4String & GetParticleName() const
void reset(G4bool ifSkipIon=true)
static G4ParticleTable * GetParticleTable()
G4ParticleTableIterator< G4String, G4ParticleDefinition * > G4PTblDicIterator
void SetDefaultValue(const char *theDefaultValue)
void SetParameterCandidates(const char *theString)
#define ns(x)
Definition xmltok.c:1649

◆ ~G4ParticleGunMessenger()

G4ParticleGunMessenger::~G4ParticleGunMessenger ( )
override

Definition at line 195 of file G4ParticleGunMessenger.cc.

196{
197 delete listCmd;
198 delete particleCmd;
199 delete directionCmd;
200 delete energyCmd;
201 delete momCmd;
202 delete momAmpCmd;
203 delete positionCmd;
204 delete timeCmd;
205 delete polCmd;
206 delete numberCmd;
207 delete ionCmd;
208 delete ionLvlCmd;
209 delete volChkCmd;
210 delete gunDirectory;
211}

Member Function Documentation

◆ GetCurrentValue()

G4String G4ParticleGunMessenger::GetCurrentValue ( G4UIcommand * command)
overridevirtual

Reimplemented from G4UImessenger.

Definition at line 294 of file G4ParticleGunMessenger.cc.

295{
296 G4String cv;
297
298 if( command==directionCmd )
299 { cv = directionCmd->ConvertToString(fParticleGun->GetParticleMomentumDirection()); }
300 else if( command==particleCmd )
301 { cv = fParticleGun->GetParticleDefinition()->GetParticleName(); }
302 else if( command==energyCmd )
303 {
304 G4double ene = fParticleGun->GetParticleEnergy();
305 if(ene == 0.)
306 { G4cerr << " G4ParticleGun: was defined in terms of momentum." << G4endl; }
307 else
308 { cv = energyCmd->ConvertToString(ene,"GeV"); }
309 }
310 else if( command==momCmd || command==momAmpCmd )
311 {
312 G4double mom = fParticleGun->GetParticleMomentum();
313 if(mom == 0.)
314 {
315 G4cerr << " G4ParticleGun: was defined in terms of kinetic energy."
316 << G4endl;
317 }
318 else
319 {
320 if( command==momCmd )
321 { cv = momCmd->ConvertToString(mom*(fParticleGun->GetParticleMomentumDirection()),"GeV"); }
322 else
323 { cv = momAmpCmd->ConvertToString(mom,"GeV"); }
324 }
325 }
326 else if( command==positionCmd )
327 { cv = positionCmd->ConvertToString(fParticleGun->GetParticlePosition(),"cm"); }
328 else if( command==timeCmd )
329 { cv = timeCmd->ConvertToString(fParticleGun->GetParticleTime(),"ns"); }
330 else if( command==polCmd )
331 { cv = polCmd->ConvertToString(fParticleGun->GetParticlePolarization()); }
332 else if( command==numberCmd )
333 { cv = numberCmd->ConvertToString(fParticleGun->GetNumberOfParticles()); }
334 else if( command==ionCmd )
335 {
336 if (fShootIon)
337 {
338 cv = ItoS(fAtomicNumber) + " " + ItoS(fAtomicMass) + " ";
339 cv += ItoS(fIonCharge);
340 }
341 else
342 {
343 cv = "";
344 }
345 }
346 else if( command==volChkCmd )
347 { cv = volChkCmd->ConvertToString(fParticleGun->IfCheckInside()); }
348 return cv;
349}
double G4double
Definition G4Types.hh:83
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4String ItoS(G4int i)

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 213 of file G4ParticleGunMessenger.cc.

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

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