Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4ParticleGunMessenger.cc
이 파일의 문서화 페이지로 가기
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4ParticleGunMessenger.cc 108396 2018-02-12 10:19:18Z gcosmo $
28 //
29 
31 #include "G4SystemOfUnits.hh"
32 #include "G4ParticleGun.hh"
33 #include "G4Geantino.hh"
34 #include "G4ThreeVector.hh"
35 #include "G4ParticleTable.hh"
36 #include "G4IonTable.hh"
37 #include "G4UIdirectory.hh"
39 #include "G4UIcmdWithAString.hh"
41 #include "G4UIcmdWith3Vector.hh"
43 #include "G4UIcmdWithAnInteger.hh"
44 #include "G4ios.hh"
45 #include "G4Tokenizer.hh"
46 
48  :fParticleGun(fPtclGun),fShootIon(false),
49  fAtomicNumber(0),fAtomicMass(0),fIonCharge(0),fIonExciteEnergy(0.0),
50  fIonFloatingLevelBase('\0'),fIonEnergyLevel(0)
51 {
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;
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);
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 release 10.5.");
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
185 }
186 
188 {
189  delete listCmd;
190  delete particleCmd;
191  delete directionCmd;
192  delete energyCmd;
193  delete momCmd;
194  delete momAmpCmd;
195  delete positionCmd;
196  delete timeCmd;
197  delete polCmd;
198  delete numberCmd;
199  delete ionCmd;
200  delete ionLvlCmd;
201  delete gunDirectory;
202 }
203 
205 {
207  if (command==listCmd) {
209  } else if (command==particleCmd) {
210  if (newValues =="ion") {
211  fShootIon = true;
212  } else {
213  fShootIon = false;
215  if(pd != 0) {
217  } else {
218  ed << "Particle [" << newValues << "] is not found.";
219  command->CommandFailed(ed);
220  }
221  }
222 
223  } else if( command==directionCmd )
225  else if( command==energyCmd )
227  else if( command==momCmd )
229  else if( command==momAmpCmd )
231  else if( command==positionCmd )
233  else if( command==timeCmd )
235  else if( command==polCmd )
237  else if( command==numberCmd )
239  else if( command==ionCmd )
240  {
241  if (fShootIon) {
242  IonCommand(newValues);
243  } else {
244  ed << "Set /gun/particle to ion before using /gun/ion command";
245  command->CommandFailed(ed);
246  }
247  }
248  else if( command==ionLvlCmd )
249  {
250  G4ExceptionDescription depWarn;
251  depWarn << "\nCommand /gun/ionL is deprecated and will be removed in release 10.5.\n"
252  << "Use /gun/ion instead.\n";
253  G4Exception("G4ParticleGunMessenger::SetNewValue","IonLWarn",JustWarning,depWarn);
254 
255  if (fShootIon) {
256  IonLevelCommand(newValues);
257  } else {
258  ed << "Set /gun/particle to ion before using /gun/ion command";
259  command->CommandFailed(ed);
260  }
261  }
262 }
263 
265 {
266  G4String cv;
267 
268  if( command==directionCmd )
270  else if( command==particleCmd )
272  else if( command==energyCmd )
273  {
275  if(ene == 0.)
276  { G4cerr << " G4ParticleGun: was defined in terms of momentum." << G4endl; }
277  else
278  { cv = energyCmd->ConvertToString(ene,"GeV"); }
279  }
280  else if( command==momCmd || command==momAmpCmd )
281  {
283  if(mom == 0.)
284  { G4cerr << " G4ParticleGun: was defined in terms of kinetic energy." << G4endl; }
285  else
286  {
287  if( command==momCmd )
289  else
290  { cv = momAmpCmd->ConvertToString(mom,"GeV"); }
291  }
292  }
293  else if( command==positionCmd )
295  else if( command==timeCmd )
297  else if( command==polCmd )
299  else if( command==numberCmd )
301  else if( command==ionCmd )
302  {
303  if (fShootIon) {
304  cv = ItoS(fAtomicNumber) + " " + ItoS(fAtomicMass) + " ";
305  cv += ItoS(fIonCharge);
306  } else {
307  cv = "";
308  }
309  }
310  return cv;
311 }
312 
313 #include "G4IonTable.hh"
314 
316 {
317  G4Tokenizer next( newValues );
318  // check argument
319  fAtomicNumber = StoI(next());
320  fAtomicMass = StoI(next());
321  G4String sQ = next();
322  if (sQ.isNull() || StoI(sQ)<0) {
324  } else {
325  fIonCharge = StoI(sQ);
326  }
327  sQ = next();
328  if (sQ.isNull()) {
329  fIonEnergyLevel = 0;
330  } else {
331  fIonEnergyLevel = StoI(sQ);
332  }
335  if (ion == 0) {
337  ed << "Ion with Z = " << fAtomicNumber << ", A = " << fAtomicMass
338  << ", I = " << fIonEnergyLevel << " is not defined ";
340  } else {
343  }
344 }
345 
347 {
348  G4Tokenizer next( newValues );
349  // check argument
350  fAtomicNumber = StoI(next());
351  fAtomicMass = StoI(next());
353  fIonExciteEnergy = 0.0;
354  fIonFloatingLevelBase = '\0';
355  G4String sQ = next();
356  if (!(sQ.isNull()))
357  {
358  if (StoI(sQ)>=0)
359  fIonCharge = StoI(sQ);
360 
361  sQ = next();
362  if (!(sQ.isNull()))
363  {
364  fIonExciteEnergy = StoD(sQ) * keV;
365 
366  sQ = next();
367  if (sQ.isNull()||sQ=="noFloat")
368  { fIonFloatingLevelBase = '\0'; }
369  else
370  { fIonFloatingLevelBase = sQ[(size_t)0]; }
371  }
372  }
376  if (ion==0) {
378  ed << "Ion with Z=" << fAtomicNumber;
379  ed << " A=" << fAtomicMass << "is not defined";
380  ionCmd->CommandFailed(ed);
381  } else {
384  }
385 }
386 
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
G4int StoI(G4String s)
void DumpTable(const G4String &particle_name="ALL")
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetParticleTime(G4double aTime)
G4bool isNull() const
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
Definition: G4UIcommand.hh:202
CLHEP::Hep3Vector G4ThreeVector
G4UIcmdWith3VectorAndUnit * momCmd
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
G4DecayTable * GetDecayTable() const
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void IonCommand(G4String newValues)
static G4ParticleTable * GetParticleTable()
static G4Geantino * Geantino()
Definition: G4Geantino.cc:87
G4UIcmdWithAString * particleCmd
G4String ItoS(G4int i)
static G4IonTable * GetIonTable()
Definition: G4IonTable.hh:78
void SetNewValue(G4UIcommand *command, G4String newValues)
static constexpr double keV
Definition: G4SIunits.hh:216
G4UIcmdWithAnInteger * numberCmd
#define G4endl
Definition: G4ios.hh:61
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
G4String GetCurrentValue(G4UIcommand *command)
const G4String & GetParticleName() const
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetDefaultValue(const char *defVal)
G4UIcmdWithoutParameter * listCmd
void SetParticlePosition(G4ThreeVector aPosition)
G4PTblDicIterator * GetIterator() const
void reset(G4bool ifSkipIon=true)
G4double GetParticleMomentum() const
void IonLevelCommand(G4String newValues)
G4int GetNumberOfParticles() const
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetDefaultValue(const char *theDefaultValue)
static G4double GetNewDoubleValue(const char *paramString)
double G4double
Definition: G4Types.hh:76
G4UIcmdWithADoubleAndUnit * energyCmd
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
G4ThreeVector GetParticlePolarization() const
G4UIcmdWithADoubleAndUnit * timeCmd
void SetParticlePolarization(G4ThreeVector aVal)
G4ParticleGunMessenger(G4ParticleGun *fPtclGun)
void SetCandidates(const char *candidateList)
G4UIcmdWithADoubleAndUnit * momAmpCmd
G4GLOB_DLL std::ostream G4cerr
static G4ThreeVector GetNew3VectorValue(const char *paramString)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:374
G4UIcmdWith3VectorAndUnit * positionCmd
static constexpr double eplus
Definition: G4SIunits.hh:199
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4ThreeVector GetParticlePosition()
G4UIcmdWith3Vector * polCmd
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4double GetParticleEnergy() const
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
G4double StoD(G4String s)
static constexpr double cm
Definition: G4SIunits.hh:119
void SetParticleEnergy(G4double aKineticEnergy)
void SetParticleMomentum(G4double aMomentum)
G4ParticleDefinition * GetIon(G4int Z, G4int A, G4int lvl=0)
Definition: G4IonTable.cc:504
void SetDefaultUnit(const char *defUnit)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
G4ParticleDefinition * GetParticleDefinition() const
G4ParticleMomentum GetParticleMomentumDirection() const
void SetParameterCandidates(const char *theString)
void SetNumberOfParticles(G4int i)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
G4UIcmdWith3Vector * directionCmd
static constexpr double GeV
Definition: G4SIunits.hh:217
#define ns
Definition: xmlparse.cc:614
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
void SetParticleCharge(G4double aCharge)
void SetDefaultUnit(const char *defUnit)