Geant4 10.7.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 ()
 
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 ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
virtual void SetNewValue (G4UIcommand *command, G4String newValue)
 
G4bool operator== (const G4UImessenger &messenger) const
 
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)
 
G4long StoL (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 = nullptr
 
G4String baseDirName = ""
 
G4bool commandsShouldBeInMaster = false
 

Detailed Description

Definition at line 52 of file G4ParticleGunMessenger.hh.

Constructor & Destructor Documentation

◆ G4ParticleGunMessenger()

G4ParticleGunMessenger::G4ParticleGunMessenger ( G4ParticleGun fPtclGun)

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->SetParameterName("X","Y","Z",true,true);
112 positionCmd->SetDefaultUnit("cm");
113 // positionCmd->SetUnitCategory("Length");
114 // positionCmd->SetUnitCandidates("microm mm cm m km");
115
116 timeCmd = new G4UIcmdWithADoubleAndUnit("/gun/time",this);
117 timeCmd->SetGuidance("Set initial time of the particle.");
118 timeCmd->SetParameterName("t0",true,true);
119 timeCmd->SetDefaultUnit("ns");
120 // timeCmd->SetUnitCategory("Time");
121 // timeCmd->SetUnitCandidates("ns ms s");
122
123 polCmd = new G4UIcmdWith3Vector("/gun/polarization",this);
124 polCmd->SetGuidance("Set polarization.");
125 polCmd->SetParameterName("Px","Py","Pz",true,true);
126 polCmd->SetRange("Px>=-1.&&Px<=1.&&Py>=-1.&&Py<=1.&&Pz>=-1.&&Pz<=1.");
127
128 numberCmd = new G4UIcmdWithAnInteger("/gun/number",this);
129 numberCmd->SetGuidance("Set number of particles to be generated.");
130 numberCmd->SetParameterName("N",true,true);
131 numberCmd->SetRange("N>0");
132
133 ionCmd = new G4UIcommand("/gun/ion",this);
134 ionCmd->SetGuidance("Set properties of ion to be generated.");
135 ionCmd->SetGuidance("[usage] /gun/ion Z A [Q E flb]");
136 ionCmd->SetGuidance(" Z:(int) AtomicNumber");
137 ionCmd->SetGuidance(" A:(int) AtomicMass");
138 ionCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)");
139 ionCmd->SetGuidance(" E:(double) Excitation energy (in keV)");
140 ionCmd->SetGuidance(" flb:(char) Floating level base");
141
142 G4UIparameter* param;
143 param = new G4UIparameter("Z",'i',false);
144 ionCmd->SetParameter(param);
145 param = new G4UIparameter("A",'i',false);
146 ionCmd->SetParameter(param);
147 param = new G4UIparameter("Q",'i',true);
148 param->SetDefaultValue(-1);
149 ionCmd->SetParameter(param);
150 param = new G4UIparameter("E",'d',true);
151 param->SetDefaultValue(0.0);
152 ionCmd->SetParameter(param);
153 param = new G4UIparameter("flb",'c',true);
154 param->SetDefaultValue("noFloat");
155 param->SetParameterCandidates("noFloat X Y Z U V W R S T A B C D E");
156 ionCmd->SetParameter(param);
157
158 ionLvlCmd = new G4UIcommand("/gun/ionL",this);
159 ionLvlCmd->SetGuidance("THIS COMMAND IS DEPRECATED and will be removed in future releases.");
160 ionLvlCmd->SetGuidance(" Use /gun/ion instead.");
161 ionLvlCmd->SetGuidance(" Set properties of ion to be generated.");
162 ionLvlCmd->SetGuidance(" [usage] /gun/ionL Z A [Q I]");
163 ionLvlCmd->SetGuidance(" Z:(int) AtomicNumber");
164 ionLvlCmd->SetGuidance(" A:(int) AtomicMass");
165 ionLvlCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)");
166 ionLvlCmd->SetGuidance(" I:(int) Level number of metastable state (0 = ground)");
167
168 G4UIparameter* paraml;
169 paraml = new G4UIparameter("Z",'i',false);
170 ionLvlCmd->SetParameter(paraml);
171 paraml = new G4UIparameter("A",'i',false);
172 ionLvlCmd->SetParameter(paraml);
173 paraml = new G4UIparameter("Q",'i',true);
174 paraml->SetDefaultValue(-1);
175 ionLvlCmd->SetParameter(paraml);
176 paraml = new G4UIparameter("I",'i',true);
177 paraml->SetDefaultValue("0");
178 ionLvlCmd->SetParameter(paraml);
179
180 // Set initial value to G4ParticleGun
181 //
183 fParticleGun->SetParticleMomentumDirection( G4ThreeVector(1.0,0.0,0.0) );
184 fParticleGun->SetParticleEnergy( 1.0*GeV );
185 fParticleGun->SetParticlePosition(G4ThreeVector(0.0*cm, 0.0*cm, 0.0*cm));
186 fParticleGun->SetParticleTime( 0.0*ns );
187}
CLHEP::Hep3Vector G4ThreeVector
static G4Geantino * Geantino()
Definition: G4Geantino.cc:86
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)
Definition: G4UIcommand.hh:146
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
void SetRange(const char *rs)
Definition: G4UIcommand.hh:120
void SetDefaultValue(const char *theDefaultValue)
void SetParameterCandidates(const char *theString)
void SetParticleTime(G4double aTime)
void SetParticlePosition(G4ThreeVector aPosition)
#define ns
Definition: xmlparse.cc:614

◆ ~G4ParticleGunMessenger()

G4ParticleGunMessenger::~G4ParticleGunMessenger ( )

Definition at line 189 of file G4ParticleGunMessenger.cc.

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

Member Function Documentation

◆ GetCurrentValue()

G4String G4ParticleGunMessenger::GetCurrentValue ( G4UIcommand command)
virtual

Reimplemented from G4UImessenger.

Definition at line 283 of file G4ParticleGunMessenger.cc.

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

◆ SetNewValue()

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

Reimplemented from G4UImessenger.

Definition at line 206 of file G4ParticleGunMessenger.cc.

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

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