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