00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "G4ParticleGunMessenger.hh"
00031 #include "G4SystemOfUnits.hh"
00032 #include "G4ParticleGun.hh"
00033 #include "G4Geantino.hh"
00034 #include "G4ThreeVector.hh"
00035 #include "G4ParticleTable.hh"
00036 #include "G4IonTable.hh"
00037 #include "G4UIdirectory.hh"
00038 #include "G4UIcmdWithoutParameter.hh"
00039 #include "G4UIcmdWithAString.hh"
00040 #include "G4UIcmdWithADoubleAndUnit.hh"
00041 #include "G4UIcmdWith3Vector.hh"
00042 #include "G4UIcmdWith3VectorAndUnit.hh"
00043 #include "G4UIcmdWithAnInteger.hh"
00044 #include "G4ios.hh"
00045 #include "G4Tokenizer.hh"
00046
00047 G4ParticleGunMessenger::G4ParticleGunMessenger(G4ParticleGun * fPtclGun)
00048 :fParticleGun(fPtclGun),fShootIon(false)
00049 {
00050 particleTable = G4ParticleTable::GetParticleTable();
00051
00052 gunDirectory = new G4UIdirectory("/gun/");
00053 gunDirectory->SetGuidance("Particle Gun control commands.");
00054
00055 listCmd = new G4UIcmdWithoutParameter("/gun/List",this);
00056 listCmd->SetGuidance("List available particles.");
00057 listCmd->SetGuidance(" Invoke G4ParticleTable.");
00058
00059 particleCmd = new G4UIcmdWithAString("/gun/particle",this);
00060 particleCmd->SetGuidance("Set particle to be generated.");
00061 particleCmd->SetGuidance(" (geantino is default)");
00062 particleCmd->SetGuidance(" (ion can be specified for shooting ions)");
00063 particleCmd->SetParameterName("particleName",true);
00064 particleCmd->SetDefaultValue("geantino");
00065 G4String candidateList;
00066 G4int nPtcl = particleTable->entries();
00067 for(G4int i=0;i<nPtcl;i++)
00068 {
00069 G4ParticleDefinition* pd = particleTable->GetParticle(i);
00070 if( !(pd->IsShortLived()) || pd->GetDecayTable() )
00071 {
00072 candidateList += pd->GetParticleName();
00073 candidateList += " ";
00074 }
00075 }
00076 candidateList += "ion ";
00077 particleCmd->SetCandidates(candidateList);
00078
00079 directionCmd = new G4UIcmdWith3Vector("/gun/direction",this);
00080 directionCmd->SetGuidance("Set momentum direction.");
00081 directionCmd->SetGuidance("Direction needs not to be a unit vector.");
00082 directionCmd->SetParameterName("ex","ey","ez",true,true);
00083 directionCmd->SetRange("ex != 0 || ey != 0 || ez != 0");
00084
00085 energyCmd = new G4UIcmdWithADoubleAndUnit("/gun/energy",this);
00086 energyCmd->SetGuidance("Set kinetic energy.");
00087 energyCmd->SetParameterName("Energy",true,true);
00088 energyCmd->SetDefaultUnit("GeV");
00089
00090
00091
00092 momCmd = new G4UIcmdWith3VectorAndUnit("/gun/momentum",this);
00093 momCmd->SetGuidance("Set momentum. This command is equivalent to two commands /gun/direction and /gun/momentumAmp");
00094 momCmd->SetParameterName("px","py","pz",true,true);
00095 momCmd->SetRange("px != 0 || py != 0 || pz != 0");
00096 momCmd->SetDefaultUnit("GeV");
00097
00098 momAmpCmd = new G4UIcmdWithADoubleAndUnit("/gun/momentumAmp",this);
00099 momAmpCmd->SetGuidance("Set absolute value of momentum.");
00100 momAmpCmd->SetGuidance("Direction should be set by /gun/direction command.");
00101 momAmpCmd->SetGuidance("This command should be used alternatively with /gun/energy.");
00102 momAmpCmd->SetParameterName("Momentum",true,true);
00103 momAmpCmd->SetDefaultUnit("GeV");
00104
00105 positionCmd = new G4UIcmdWith3VectorAndUnit("/gun/position",this);
00106 positionCmd->SetGuidance("Set starting position of the particle.");
00107 positionCmd->SetParameterName("X","Y","Z",true,true);
00108 positionCmd->SetDefaultUnit("cm");
00109
00110
00111
00112 timeCmd = new G4UIcmdWithADoubleAndUnit("/gun/time",this);
00113 timeCmd->SetGuidance("Set initial time of the particle.");
00114 timeCmd->SetParameterName("t0",true,true);
00115 timeCmd->SetDefaultUnit("ns");
00116
00117
00118
00119 polCmd = new G4UIcmdWith3Vector("/gun/polarization",this);
00120 polCmd->SetGuidance("Set polarization.");
00121 polCmd->SetParameterName("Px","Py","Pz",true,true);
00122 polCmd->SetRange("Px>=-1.&&Px<=1.&&Py>=-1.&&Py<=1.&&Pz>=-1.&&Pz<=1.");
00123
00124 numberCmd = new G4UIcmdWithAnInteger("/gun/number",this);
00125 numberCmd->SetGuidance("Set number of particles to be generated.");
00126 numberCmd->SetParameterName("N",true,true);
00127 numberCmd->SetRange("N>0");
00128
00129 ionCmd = new G4UIcommand("/gun/ion",this);
00130 ionCmd->SetGuidance("Set properties of ion to be generated.");
00131 ionCmd->SetGuidance("[usage] /gun/ion Z A Q");
00132 ionCmd->SetGuidance(" Z:(int) AtomicNumber");
00133 ionCmd->SetGuidance(" A:(int) AtomicMass");
00134 ionCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)");
00135 ionCmd->SetGuidance(" E:(double) Excitation energy (in keV)");
00136
00137 G4UIparameter* param;
00138 param = new G4UIparameter("Z",'i',false);
00139 param->SetDefaultValue("1");
00140 ionCmd->SetParameter(param);
00141 param = new G4UIparameter("A",'i',false);
00142 param->SetDefaultValue("1");
00143 ionCmd->SetParameter(param);
00144 param = new G4UIparameter("Q",'i',true);
00145 param->SetDefaultValue("0");
00146 ionCmd->SetParameter(param);
00147 param = new G4UIparameter("E",'d',true);
00148 param->SetDefaultValue("0.0");
00149 ionCmd->SetParameter(param);
00150
00151
00152 fParticleGun->SetParticleDefinition( G4Geantino::Geantino() );
00153 fParticleGun->SetParticleMomentumDirection( G4ThreeVector(1.0,0.0,0.0) );
00154 fParticleGun->SetParticleEnergy( 1.0*GeV );
00155 fParticleGun->SetParticlePosition(G4ThreeVector(0.0*cm, 0.0*cm, 0.0*cm));
00156 fParticleGun->SetParticleTime( 0.0*ns );
00157 }
00158
00159 G4ParticleGunMessenger::~G4ParticleGunMessenger()
00160 {
00161 delete listCmd;
00162 delete particleCmd;
00163 delete directionCmd;
00164 delete energyCmd;
00165 delete momCmd;
00166 delete momAmpCmd;
00167 delete positionCmd;
00168 delete timeCmd;
00169 delete polCmd;
00170 delete numberCmd;
00171 delete ionCmd;
00172 delete gunDirectory;
00173 }
00174
00175 void G4ParticleGunMessenger::SetNewValue(G4UIcommand * command,G4String newValues)
00176 {
00177 if( command==listCmd )
00178 { particleTable->DumpTable(); }
00179 else if( command==particleCmd )
00180 {
00181 if (newValues =="ion") {
00182 fShootIon = true;
00183 } else {
00184 fShootIon = false;
00185 G4ParticleDefinition* pd = particleTable->FindParticle(newValues);
00186 if(pd != 0)
00187 { fParticleGun->SetParticleDefinition( pd ); }
00188 }
00189 }
00190 else if( command==directionCmd )
00191 { fParticleGun->SetParticleMomentumDirection(directionCmd->GetNew3VectorValue(newValues)); }
00192 else if( command==energyCmd )
00193 { fParticleGun->SetParticleEnergy(energyCmd->GetNewDoubleValue(newValues)); }
00194 else if( command==momCmd )
00195 { fParticleGun->SetParticleMomentum(momCmd->GetNew3VectorValue(newValues)); }
00196 else if( command==momAmpCmd )
00197 { fParticleGun->SetParticleMomentum(momAmpCmd->GetNewDoubleValue(newValues)); }
00198 else if( command==positionCmd )
00199 { fParticleGun->SetParticlePosition(positionCmd->GetNew3VectorValue(newValues)); }
00200 else if( command==timeCmd )
00201 { fParticleGun->SetParticleTime(timeCmd->GetNewDoubleValue(newValues)); }
00202 else if( command==polCmd )
00203 { fParticleGun->SetParticlePolarization(polCmd->GetNew3VectorValue(newValues)); }
00204 else if( command==numberCmd )
00205 { fParticleGun->SetNumberOfParticles(numberCmd->GetNewIntValue(newValues)); }
00206 else if( command==ionCmd )
00207 { IonCommand(newValues); }
00208 }
00209
00210 G4String G4ParticleGunMessenger::GetCurrentValue(G4UIcommand * command)
00211 {
00212 G4String cv;
00213
00214 if( command==directionCmd )
00215 { cv = directionCmd->ConvertToString(fParticleGun->GetParticleMomentumDirection()); }
00216 else if( command==particleCmd )
00217 { cv = fParticleGun->GetParticleDefinition()->GetParticleName(); }
00218 else if( command==energyCmd )
00219 {
00220 G4double ene = fParticleGun->GetParticleEnergy();
00221 if(ene == 0.)
00222 { G4cerr << " G4ParticleGun: was defined in terms of momentum." << G4endl; }
00223 else
00224 { cv = energyCmd->ConvertToString(ene,"GeV"); }
00225 }
00226 else if( command==momCmd || command==momAmpCmd )
00227 {
00228 G4double mom = fParticleGun->GetParticleMomentum();
00229 if(mom == 0.)
00230 { G4cerr << " G4ParticleGun: was defined in terms of kinetic energy." << G4endl; }
00231 else
00232 {
00233 if( command==momCmd )
00234 { cv = momCmd->ConvertToString(mom*(fParticleGun->GetParticleMomentumDirection()),"GeV"); }
00235 else
00236 { cv = momAmpCmd->ConvertToString(mom,"GeV"); }
00237 }
00238 }
00239 else if( command==positionCmd )
00240 { cv = positionCmd->ConvertToString(fParticleGun->GetParticlePosition(),"cm"); }
00241 else if( command==timeCmd )
00242 { cv = timeCmd->ConvertToString(fParticleGun->GetParticleTime(),"ns"); }
00243 else if( command==polCmd )
00244 { cv = polCmd->ConvertToString(fParticleGun->GetParticlePolarization()); }
00245 else if( command==numberCmd )
00246 { cv = numberCmd->ConvertToString(fParticleGun->GetNumberOfParticles()); }
00247 else if( command==ionCmd )
00248 {
00249 if (fShootIon) {
00250 cv = ItoS(fAtomicNumber) + " " + ItoS(fAtomicMass) + " ";
00251 cv += ItoS(fIonCharge);
00252 } else {
00253 cv = "";
00254 }
00255 }
00256 return cv;
00257 }
00258
00259 void G4ParticleGunMessenger::IonCommand(G4String newValues)
00260 {
00261 if (fShootIon) {
00262 G4Tokenizer next( newValues );
00263
00264 fAtomicNumber = StoI(next());
00265 fAtomicMass = StoI(next());
00266 G4String sQ = next();
00267 if (sQ.isNull()) {
00268 fIonCharge = fAtomicNumber;
00269 } else {
00270 fIonCharge = StoI(sQ);
00271 sQ = next();
00272 if (sQ.isNull()) {
00273 fIonExciteEnergy = 0.0;
00274 } else {
00275 fIonExciteEnergy = StoD(sQ) * keV;
00276 }
00277 }
00278
00279 G4ParticleDefinition* ion;
00280 ion = particleTable->GetIon( fAtomicNumber, fAtomicMass, fIonExciteEnergy);
00281 if (ion==0) {
00282 G4cout << "Ion with Z=" << fAtomicNumber;
00283 G4cout << " A=" << fAtomicMass << "is not be defined" << G4endl;
00284 } else {
00285 fParticleGun->SetParticleDefinition(ion);
00286 fParticleGun->SetParticleCharge(fIonCharge*eplus);
00287 }
00288 } else {
00289 G4cout << "Set /gun/particle to ion before using /gun/ion command";
00290 G4cout << G4endl;
00291 }
00292 }
00293