Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4ParticleGunMessenger class implementation << 27 // 23 // 28 // Author: Makoto Asai, 1997 << 24 // $Id: G4ParticleGunMessenger.cc,v 1.12 2005/04/27 01:32:46 asaim Exp $ 29 // ------------------------------------------- << 25 // GEANT4 tag $Name: geant4-07-01 $ >> 26 // 30 27 31 #include "G4ParticleGunMessenger.hh" 28 #include "G4ParticleGunMessenger.hh" 32 #include "G4SystemOfUnits.hh" << 33 #include "G4ParticleGun.hh" 29 #include "G4ParticleGun.hh" 34 #include "G4Geantino.hh" 30 #include "G4Geantino.hh" 35 #include "G4ThreeVector.hh" 31 #include "G4ThreeVector.hh" 36 #include "G4ParticleTable.hh" 32 #include "G4ParticleTable.hh" 37 #include "G4IonTable.hh" 33 #include "G4IonTable.hh" 38 #include "G4UIdirectory.hh" 34 #include "G4UIdirectory.hh" 39 #include "G4UIcmdWithoutParameter.hh" 35 #include "G4UIcmdWithoutParameter.hh" 40 #include "G4UIcmdWithAString.hh" 36 #include "G4UIcmdWithAString.hh" 41 #include "G4UIcmdWithADoubleAndUnit.hh" 37 #include "G4UIcmdWithADoubleAndUnit.hh" 42 #include "G4UIcmdWith3Vector.hh" 38 #include "G4UIcmdWith3Vector.hh" 43 #include "G4UIcmdWith3VectorAndUnit.hh" 39 #include "G4UIcmdWith3VectorAndUnit.hh" 44 #include "G4UIcmdWithAnInteger.hh" 40 #include "G4UIcmdWithAnInteger.hh" 45 #include "G4UIcmdWithABool.hh" << 46 #include "G4ios.hh" 41 #include "G4ios.hh" 47 #include "G4Tokenizer.hh" 42 #include "G4Tokenizer.hh" 48 43 49 G4ParticleGunMessenger::G4ParticleGunMessenger << 44 #include <iomanip> 50 : fParticleGun(fPtclGun) << 45 #include <strstream> >> 46 >> 47 G4ParticleGunMessenger::G4ParticleGunMessenger(G4ParticleGun * fPtclGun) >> 48 :fParticleGun(fPtclGun),fShootIon(false) 51 { 49 { 52 particleTable = G4ParticleTable::GetParticle 50 particleTable = G4ParticleTable::GetParticleTable(); 53 51 54 gunDirectory = new G4UIdirectory("/gun/"); 52 gunDirectory = new G4UIdirectory("/gun/"); 55 gunDirectory->SetGuidance("Particle Gun cont 53 gunDirectory->SetGuidance("Particle Gun control commands."); 56 54 57 listCmd = new G4UIcmdWithoutParameter("/gun/ 55 listCmd = new G4UIcmdWithoutParameter("/gun/List",this); 58 listCmd->SetGuidance("List available particl 56 listCmd->SetGuidance("List available particles."); 59 listCmd->SetGuidance(" Invoke G4ParticleTabl 57 listCmd->SetGuidance(" Invoke G4ParticleTable."); 60 58 61 particleCmd = new G4UIcmdWithAString("/gun/p 59 particleCmd = new G4UIcmdWithAString("/gun/particle",this); 62 particleCmd->SetGuidance("Set particle to be 60 particleCmd->SetGuidance("Set particle to be generated."); 63 particleCmd->SetGuidance(" (geantino is defa 61 particleCmd->SetGuidance(" (geantino is default)"); 64 particleCmd->SetGuidance(" (ion can be speci 62 particleCmd->SetGuidance(" (ion can be specified for shooting ions)"); 65 particleCmd->SetParameterName("particleName" 63 particleCmd->SetParameterName("particleName",true); 66 particleCmd->SetDefaultValue("geantino"); 64 particleCmd->SetDefaultValue("geantino"); 67 G4String candidateList; 65 G4String candidateList; 68 G4ParticleTable::G4PTblDicIterator* itr = pa << 66 G4int nPtcl = particleTable->entries(); 69 itr->reset(); << 67 for(G4int i=0;i<nPtcl;i++) 70 while( (*itr)() ) << 71 { 68 { 72 G4ParticleDefinition* pd = itr->value(); << 69 G4ParticleDefinition* pd = particleTable->GetParticle(i); 73 if( !(pd->IsShortLived()) || pd->GetDecayT << 70 if( !(pd->IsShortLived()) || pd->GetDecayTable() ) 74 { 71 { 75 candidateList += pd->GetParticleName(); 72 candidateList += pd->GetParticleName(); 76 candidateList += " "; 73 candidateList += " "; 77 } 74 } 78 } 75 } 79 candidateList += "ion "; 76 candidateList += "ion "; 80 particleCmd->SetCandidates(candidateList); 77 particleCmd->SetCandidates(candidateList); 81 78 82 directionCmd = new G4UIcmdWith3Vector("/gun/ 79 directionCmd = new G4UIcmdWith3Vector("/gun/direction",this); 83 directionCmd->SetGuidance("Set momentum dire 80 directionCmd->SetGuidance("Set momentum direction."); 84 directionCmd->SetGuidance(" Direction needs << 81 directionCmd->SetGuidance("Direction needs not to be a unit vector."); 85 directionCmd->SetParameterName("ex","ey","ez << 82 directionCmd->SetParameterName("Px","Py","Pz",true,true); 86 directionCmd->SetRange("ex != 0 || ey != 0 | << 83 directionCmd->SetRange("Px != 0 || Py != 0 || Pz != 0"); 87 84 88 energyCmd = new G4UIcmdWithADoubleAndUnit("/ 85 energyCmd = new G4UIcmdWithADoubleAndUnit("/gun/energy",this); 89 energyCmd->SetGuidance("Set kinetic energy." 86 energyCmd->SetGuidance("Set kinetic energy."); 90 energyCmd->SetParameterName("Energy",true,tr 87 energyCmd->SetParameterName("Energy",true,true); 91 energyCmd->SetDefaultUnit("GeV"); 88 energyCmd->SetDefaultUnit("GeV"); 92 //energyCmd->SetUnitCategory("Energy"); 89 //energyCmd->SetUnitCategory("Energy"); 93 //energyCmd->SetUnitCandidates("eV keV MeV G 90 //energyCmd->SetUnitCandidates("eV keV MeV GeV TeV"); 94 91 95 momCmd = new G4UIcmdWith3VectorAndUnit("/gun << 96 momCmd->SetGuidance("Set momentum. This comm << 97 momCmd->SetGuidance(" /gun/direction and /gu << 98 momCmd->SetParameterName("px","py","pz",true << 99 momCmd->SetRange("px != 0 || py != 0 || pz ! << 100 momCmd->SetDefaultUnit("GeV"); << 101 << 102 momAmpCmd = new G4UIcmdWithADoubleAndUnit("/ << 103 momAmpCmd->SetGuidance("Set absolute value o << 104 momAmpCmd->SetGuidance(" Direction should be << 105 momAmpCmd->SetGuidance(" This command should << 106 momAmpCmd->SetParameterName("Momentum",true, << 107 momAmpCmd->SetDefaultUnit("GeV"); << 108 << 109 positionCmd = new G4UIcmdWith3VectorAndUnit( 92 positionCmd = new G4UIcmdWith3VectorAndUnit("/gun/position",this); 110 positionCmd->SetGuidance("Set starting posit 93 positionCmd->SetGuidance("Set starting position of the particle."); 111 positionCmd->SetGuidance(" Position must be << 112 positionCmd->SetParameterName("X","Y","Z",tr 94 positionCmd->SetParameterName("X","Y","Z",true,true); 113 positionCmd->SetDefaultUnit("cm"); 95 positionCmd->SetDefaultUnit("cm"); 114 // positionCmd->SetUnitCategory("Length"); << 96 //positionCmd->SetUnitCategory("Length"); 115 // positionCmd->SetUnitCandidates("microm mm << 97 //positionCmd->SetUnitCandidates("microm mm cm m km"); 116 98 117 timeCmd = new G4UIcmdWithADoubleAndUnit("/gu 99 timeCmd = new G4UIcmdWithADoubleAndUnit("/gun/time",this); 118 timeCmd->SetGuidance("Set initial time of th 100 timeCmd->SetGuidance("Set initial time of the particle."); 119 timeCmd->SetParameterName("t0",true,true); 101 timeCmd->SetParameterName("t0",true,true); 120 timeCmd->SetDefaultUnit("ns"); 102 timeCmd->SetDefaultUnit("ns"); 121 // timeCmd->SetUnitCategory("Time"); << 103 //timeCmd->SetUnitCategory("Time"); 122 // timeCmd->SetUnitCandidates("ns ms s"); << 104 //timeCmd->SetUnitCandidates("ns ms s"); 123 105 124 polCmd = new G4UIcmdWith3Vector("/gun/polari 106 polCmd = new G4UIcmdWith3Vector("/gun/polarization",this); 125 polCmd->SetGuidance("Set polarization."); 107 polCmd->SetGuidance("Set polarization."); 126 polCmd->SetParameterName("Px","Py","Pz",true 108 polCmd->SetParameterName("Px","Py","Pz",true,true); 127 polCmd->SetRange("Px>=-1.&&Px<=1.&&Py>=-1.&& 109 polCmd->SetRange("Px>=-1.&&Px<=1.&&Py>=-1.&&Py<=1.&&Pz>=-1.&&Pz<=1."); 128 110 129 numberCmd = new G4UIcmdWithAnInteger("/gun/n 111 numberCmd = new G4UIcmdWithAnInteger("/gun/number",this); 130 numberCmd->SetGuidance("Set number of partic 112 numberCmd->SetGuidance("Set number of particles to be generated."); 131 numberCmd->SetParameterName("N",true,true); 113 numberCmd->SetParameterName("N",true,true); 132 numberCmd->SetRange("N>0"); 114 numberCmd->SetRange("N>0"); 133 115 134 ionCmd = new G4UIcommand("/gun/ion",this); 116 ionCmd = new G4UIcommand("/gun/ion",this); 135 ionCmd->SetGuidance("Set properties of ion t 117 ionCmd->SetGuidance("Set properties of ion to be generated."); 136 ionCmd->SetGuidance("[usage] /gun/ion Z A [Q << 118 ionCmd->SetGuidance("[usage] /gun/ion Z A Q"); 137 ionCmd->SetGuidance(" Z:(int) AtomicN 119 ionCmd->SetGuidance(" Z:(int) AtomicNumber"); 138 ionCmd->SetGuidance(" A:(int) AtomicM 120 ionCmd->SetGuidance(" A:(int) AtomicMass"); 139 ionCmd->SetGuidance(" Q:(int) Charge 121 ionCmd->SetGuidance(" Q:(int) Charge of Ion (in unit of e)"); 140 ionCmd->SetGuidance(" E:(double) Exci 122 ionCmd->SetGuidance(" E:(double) Excitation energy (in keV)"); 141 ionCmd->SetGuidance(" flb:(char) Floa << 142 123 143 G4UIparameter* param; 124 G4UIparameter* param; 144 param = new G4UIparameter("Z",'i',false); 125 param = new G4UIparameter("Z",'i',false); >> 126 param->SetDefaultValue("1"); 145 ionCmd->SetParameter(param); 127 ionCmd->SetParameter(param); 146 param = new G4UIparameter("A",'i',false); 128 param = new G4UIparameter("A",'i',false); >> 129 param->SetDefaultValue("1"); 147 ionCmd->SetParameter(param); 130 ionCmd->SetParameter(param); 148 param = new G4UIparameter("Q",'i',true); 131 param = new G4UIparameter("Q",'i',true); 149 param->SetDefaultValue(-1); << 132 param->SetDefaultValue("0"); 150 ionCmd->SetParameter(param); 133 ionCmd->SetParameter(param); 151 param = new G4UIparameter("E",'d',true); 134 param = new G4UIparameter("E",'d',true); 152 param->SetDefaultValue(0.0); << 135 param->SetDefaultValue("0.0"); 153 ionCmd->SetParameter(param); 136 ionCmd->SetParameter(param); 154 param = new G4UIparameter("flb",'c',true); << 137 155 param->SetDefaultValue("noFloat"); << 138 // set initial value to G4ParticleGun 156 param->SetParameterCandidates("noFloat X Y Z << 157 ionCmd->SetParameter(param); << 158 << 159 ionLvlCmd = new G4UIcommand("/gun/ionL",this << 160 ionLvlCmd->SetGuidance("THIS COMMAND IS DEPR << 161 ionLvlCmd->SetGuidance(" Use /gun/ion instea << 162 ionLvlCmd->SetGuidance(" Set properties of i << 163 ionLvlCmd->SetGuidance(" [usage] /gun/ionL Z << 164 ionLvlCmd->SetGuidance(" Z:(int) Atom << 165 ionLvlCmd->SetGuidance(" A:(int) Atom << 166 ionLvlCmd->SetGuidance(" Q:(int) Char << 167 ionLvlCmd->SetGuidance(" I:(int) Leve << 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/check << 182 volChkCmd->SetGuidance("Switch on/off the ch << 183 volChkCmd->SetGuidance("By default the check << 184 volChkCmd->SetGuidance("but the user has to << 185 volChkCmd->SetParameterName("switch",true,tr << 186 << 187 // Set initial value to G4ParticleGun << 188 // << 189 fParticleGun->SetParticleDefinition( G4Geant 139 fParticleGun->SetParticleDefinition( G4Geantino::Geantino() ); 190 fParticleGun->SetParticleMomentumDirection( 140 fParticleGun->SetParticleMomentumDirection( G4ThreeVector(1.0,0.0,0.0) ); 191 fParticleGun->SetParticleEnergy( 1.0*GeV ); 141 fParticleGun->SetParticleEnergy( 1.0*GeV ); >> 142 fParticleGun->SetParticlePosition(G4ThreeVector(0.0*cm, 0.0*cm, 0.0*cm)); 192 fParticleGun->SetParticleTime( 0.0*ns ); 143 fParticleGun->SetParticleTime( 0.0*ns ); 193 } 144 } 194 145 195 G4ParticleGunMessenger::~G4ParticleGunMessenge 146 G4ParticleGunMessenger::~G4ParticleGunMessenger() 196 { 147 { 197 delete listCmd; 148 delete listCmd; 198 delete particleCmd; 149 delete particleCmd; 199 delete directionCmd; 150 delete directionCmd; 200 delete energyCmd; 151 delete energyCmd; 201 delete momCmd; << 202 delete momAmpCmd; << 203 delete positionCmd; 152 delete positionCmd; 204 delete timeCmd; 153 delete timeCmd; 205 delete polCmd; 154 delete polCmd; 206 delete numberCmd; 155 delete numberCmd; 207 delete ionCmd; 156 delete ionCmd; 208 delete ionLvlCmd; << 209 delete volChkCmd; << 210 delete gunDirectory; 157 delete gunDirectory; 211 } 158 } 212 159 213 void G4ParticleGunMessenger:: << 160 void G4ParticleGunMessenger::SetNewValue(G4UIcommand * command,G4String newValues) 214 SetNewValue(G4UIcommand* command, G4String new << 215 { 161 { 216 G4ExceptionDescription ed; << 162 if( command==listCmd ) 217 if (command==listCmd) << 163 { particleTable->DumpTable(); } 218 { << 164 else if( command==particleCmd ) 219 particleTable->DumpTable(); << 220 } << 221 else if (command==particleCmd) << 222 { 165 { 223 if (newValues =="ion") << 166 if (newValues =="ion") { 224 { << 225 fShootIon = true; 167 fShootIon = true; 226 } << 168 } else { 227 else << 228 { << 229 fShootIon = false; 169 fShootIon = false; 230 G4ParticleDefinition* pd = particleTable 170 G4ParticleDefinition* pd = particleTable->FindParticle(newValues); 231 if(pd != nullptr) << 171 if(pd != 0) 232 { << 172 { fParticleGun->SetParticleDefinition( pd ); } 233 fParticleGun->SetParticleDefinition( p << 234 } << 235 else << 236 { << 237 ed << "Particle [" << newValues << "] << 238 command->CommandFailed(ed); << 239 } << 240 } 173 } 241 << 174 } 242 } else if( command==directionCmd ) << 175 else if( command==directionCmd ) 243 { fParticleGun->SetParticleMomentumDirection 176 { fParticleGun->SetParticleMomentumDirection(directionCmd->GetNew3VectorValue(newValues)); } 244 else if( command==energyCmd ) 177 else if( command==energyCmd ) 245 { fParticleGun->SetParticleEnergy(energyCmd- 178 { fParticleGun->SetParticleEnergy(energyCmd->GetNewDoubleValue(newValues)); } 246 else if( command==momCmd ) << 247 { fParticleGun->SetParticleMomentum(momCmd-> << 248 else if( command==momAmpCmd ) << 249 { fParticleGun->SetParticleMomentum(momAmpCm << 250 else if( command==positionCmd ) 179 else if( command==positionCmd ) 251 { fParticleGun->SetParticlePosition(position 180 { fParticleGun->SetParticlePosition(positionCmd->GetNew3VectorValue(newValues)); } 252 else if( command==timeCmd ) 181 else if( command==timeCmd ) 253 { fParticleGun->SetParticleTime(timeCmd->Get 182 { fParticleGun->SetParticleTime(timeCmd->GetNewDoubleValue(newValues)); } 254 else if( command==polCmd ) 183 else if( command==polCmd ) 255 { fParticleGun->SetParticlePolarization(polC 184 { fParticleGun->SetParticlePolarization(polCmd->GetNew3VectorValue(newValues)); } 256 else if( command==numberCmd ) 185 else if( command==numberCmd ) 257 { fParticleGun->SetNumberOfParticles(numberC 186 { fParticleGun->SetNumberOfParticles(numberCmd->GetNewIntValue(newValues)); } 258 else if( command==ionCmd ) << 187 else if( command==ionCmd ) 259 { << 188 { IonCommand(newValues); } 260 if (fShootIon) << 261 { << 262 IonCommand(newValues); << 263 } << 264 else << 265 { << 266 ed << "Set /gun/particle to ion before u << 267 command->CommandFailed(ed); << 268 } << 269 } << 270 else if( command==ionLvlCmd ) << 271 { << 272 G4ExceptionDescription depWarn; << 273 depWarn << "\nCommand /gun/ionL is depreca << 274 << "Use /gun/ion instead.\n"; << 275 G4Exception("G4ParticleGunMessenger::SetNe << 276 JustWarning, depWarn); << 277 << 278 if (fShootIon) << 279 { << 280 IonLevelCommand(newValues); << 281 } << 282 else << 283 { << 284 ed << "Set /gun/particle to ion before u << 285 command->CommandFailed(ed); << 286 } << 287 } << 288 else if( command==volChkCmd ) << 289 { << 290 fParticleGun->CheckInside(volChkCmd->GetNe << 291 } << 292 } 189 } 293 190 294 G4String G4ParticleGunMessenger::GetCurrentVal << 191 G4String G4ParticleGunMessenger::GetCurrentValue(G4UIcommand * command) 295 { 192 { 296 G4String cv; 193 G4String cv; 297 194 298 if( command==directionCmd ) 195 if( command==directionCmd ) 299 { cv = directionCmd->ConvertToString(fPartic 196 { cv = directionCmd->ConvertToString(fParticleGun->GetParticleMomentumDirection()); } 300 else if( command==particleCmd ) 197 else if( command==particleCmd ) 301 { cv = fParticleGun->GetParticleDefinition() 198 { cv = fParticleGun->GetParticleDefinition()->GetParticleName(); } 302 else if( command==energyCmd ) 199 else if( command==energyCmd ) 303 { << 200 { cv = energyCmd->ConvertToString(fParticleGun->GetParticleEnergy(),"GeV"); } 304 G4double ene = fParticleGun->GetParticleEn << 305 if(ene == 0.) << 306 { G4cerr << " G4ParticleGun: was defined << 307 else << 308 { cv = energyCmd->ConvertToString(ene,"GeV << 309 } << 310 else if( command==momCmd || command==momAmpC << 311 { << 312 G4double mom = fParticleGun->GetParticleMo << 313 if(mom == 0.) << 314 { << 315 G4cerr << " G4ParticleGun: was defined << 316 << G4endl; << 317 } << 318 else << 319 { << 320 if( command==momCmd ) << 321 { cv = momCmd->ConvertToString(mom*(fPar << 322 else << 323 { cv = momAmpCmd->ConvertToString(mom,"G << 324 } << 325 } << 326 else if( command==positionCmd ) 201 else if( command==positionCmd ) 327 { cv = positionCmd->ConvertToString(fParticl 202 { cv = positionCmd->ConvertToString(fParticleGun->GetParticlePosition(),"cm"); } 328 else if( command==timeCmd ) 203 else if( command==timeCmd ) 329 { cv = timeCmd->ConvertToString(fParticleGun 204 { cv = timeCmd->ConvertToString(fParticleGun->GetParticleTime(),"ns"); } 330 else if( command==polCmd ) 205 else if( command==polCmd ) 331 { cv = polCmd->ConvertToString(fParticleGun- 206 { cv = polCmd->ConvertToString(fParticleGun->GetParticlePolarization()); } 332 else if( command==numberCmd ) 207 else if( command==numberCmd ) 333 { cv = numberCmd->ConvertToString(fParticleG 208 { cv = numberCmd->ConvertToString(fParticleGun->GetNumberOfParticles()); } 334 else if( command==ionCmd ) 209 else if( command==ionCmd ) 335 { 210 { 336 if (fShootIon) << 211 if (fShootIon) { 337 { << 338 cv = ItoS(fAtomicNumber) + " " + ItoS(fA 212 cv = ItoS(fAtomicNumber) + " " + ItoS(fAtomicMass) + " "; 339 cv += ItoS(fIonCharge); 213 cv += ItoS(fIonCharge); 340 } << 214 } else { 341 else << 342 { << 343 cv = ""; 215 cv = ""; 344 } 216 } 345 } 217 } 346 else if( command==volChkCmd ) << 347 { cv = volChkCmd->ConvertToString(fParticleG << 348 return cv; 218 return cv; 349 } 219 } 350 220 351 void G4ParticleGunMessenger::IonLevelCommand(c << 221 void G4ParticleGunMessenger::IonCommand(G4String newValues) 352 { << 353 G4Tokenizer next( newValues ); << 354 << 355 // Check argument << 356 // << 357 fAtomicNumber = StoI(next()); << 358 fAtomicMass = StoI(next()); << 359 G4String sQ = next(); << 360 if (sQ.empty() || StoI(sQ)<0) << 361 { << 362 fIonCharge = fAtomicNumber; << 363 } << 364 else << 365 { << 366 fIonCharge = StoI(sQ); << 367 } << 368 sQ = next(); << 369 if (sQ.empty()) << 370 { << 371 fIonEnergyLevel = 0; << 372 } << 373 else << 374 { << 375 fIonEnergyLevel = StoI(sQ); << 376 } << 377 G4ParticleDefinition* ion = G4IonTable::GetI << 378 ->GetIon(fAtomicNumber,fAtomicMass,fIonE << 379 if (ion == nullptr) << 380 { << 381 G4ExceptionDescription ed; << 382 ed << "Ion with Z = " << fAtomicNumber << << 383 << ", I = " << fIonEnergyLevel << " is << 384 ionLvlCmd->CommandFailed(ed); << 385 } << 386 else << 387 { << 388 fParticleGun->SetParticleDefinition(ion); << 389 fParticleGun->SetParticleCharge(fIonCharge << 390 } << 391 } << 392 << 393 void G4ParticleGunMessenger::IonCommand(const << 394 { 222 { 395 G4Tokenizer next( newValues ); << 223 if (fShootIon) { 396 << 224 G4Tokenizer next( newValues ); 397 // Check argument << 225 // check argument 398 // << 226 fAtomicNumber = StoI(next()); 399 fAtomicNumber = StoI(next()); << 227 fAtomicMass = StoI(next()); 400 fAtomicMass = StoI(next()); << 228 G4String sQ = next(); 401 fIonCharge = fAtomicNumber; << 229 if (sQ.isNull()) { 402 fIonExciteEnergy = 0.0; << 230 fIonCharge = fAtomicNumber; 403 fIonFloatingLevelBase = '\0'; << 231 } else { 404 G4String sQ = next(); << 232 fIonCharge = StoI(sQ); 405 if (!(sQ.empty())) << 406 { << 407 if (StoI(sQ)>=0) << 408 fIonCharge = StoI(sQ); << 409 << 410 sQ = next(); << 411 if (!(sQ.empty())) << 412 { << 413 fIonExciteEnergy = StoD(sQ) * keV; << 414 << 415 sQ = next(); 233 sQ = next(); 416 if (sQ.empty()||sQ=="noFloat") << 234 if (sQ.isNull()) { 417 { fIonFloatingLevelBase = '\0'; } << 235 fIonExciteEnergy = 0.0; 418 else << 236 } else { 419 { fIonFloatingLevelBase = sQ[(std::size_ << 237 fIonExciteEnergy = StoD(sQ) * keV; >> 238 } 420 } 239 } 421 } << 240 422 G4ParticleDefinition* ion = G4IonTable::GetI << 241 G4ParticleDefinition* ion; 423 ->GetIon(fAtomicNumber,fAtomicMass,fIonExc << 242 ion = particleTable->GetIon( fAtomicNumber, fAtomicMass, fIonExciteEnergy); 424 if (ion==nullptr) << 243 if (ion==0) { 425 { << 244 G4cout << "Ion with Z=" << fAtomicNumber; 426 G4ExceptionDescription ed; << 245 G4cout << " A=" << fAtomicMass << "is not be defined" << G4endl; 427 ed << "Ion with Z=" << fAtomicNumber; << 246 } else { 428 ed << " A=" << fAtomicMass << "is not defi << 247 fParticleGun->SetParticleDefinition(ion); 429 ionCmd->CommandFailed(ed); << 248 fParticleGun->SetParticleCharge(fIonCharge*eplus); 430 } << 249 } 431 else << 250 } else { 432 { << 251 G4cout << "Set /gun/particle to ion before using /gun/ion command"; 433 fParticleGun->SetParticleDefinition(ion); << 252 G4cout << G4endl; 434 fParticleGun->SetParticleCharge(fIonCharge << 435 } 253 } 436 } 254 } >> 255 437 256