- Timestamp:
- Jun 18, 2010, 11:42:07 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/particles/management/src/G4DynamicParticle.cc
r1196 r1315 25 25 // 26 26 // 27 // $Id: G4DynamicParticle.cc,v 1.2 6 2009/08/17 14:52:19kurasige Exp $28 // GEANT4 tag $Name: geant4-09-0 3-cand-01 $27 // $Id: G4DynamicParticle.cc,v 1.29 2010/05/20 01:01:07 kurasige Exp $ 28 // GEANT4 tag $Name: geant4-09-04-beta-cand-01 $ 29 29 // 30 30 // … … 59 59 // revised by V.Ivanchenko, 18 June 2003 60 60 // take into account the case of virtual photons 61 // 61 // revised by M.Kelsey 12 May 2010 62 // ensure that all constructors initialize all data members 62 63 //-------------------------------------------------------------- 63 64 … … 75 76 //////////////////// 76 77 G4DynamicParticle::G4DynamicParticle(): 77 theMomentumDirection( G4ThreeVector(0.0,0.0,1.0)),78 theMomentumDirection(0.0,0.0,1.0), 78 79 theParticleDefinition(0), 79 80 theKineticEnergy(0.0), 80 81 theProperTime(0.0), 82 theDynamicalMass(0.0), 83 theDynamicalCharge(0.0), 84 theDynamicalSpin(0.0), 85 theDynamicalMagneticMoment(0.0), 86 theElectronOccupancy(0), 81 87 thePreAssignedDecayProducts(0), 82 88 thePreAssignedDecayTime(-1.0), 83 89 verboseLevel(1), 84 90 primaryParticle(0), 85 thePDGcode(0) 86 { 87 theDynamicalMass = 0.0; 88 theDynamicalCharge= 0.0; 89 theElectronOccupancy = 0; 90 } 91 thePDGcode(0) {} 91 92 92 93 //////////////////// … … 100 101 theKineticEnergy(aKineticEnergy), 101 102 theProperTime(0.0), 103 theDynamicalMass(aParticleDefinition->GetPDGMass()), 104 theDynamicalCharge(aParticleDefinition->GetPDGCharge()), 105 theDynamicalSpin(aParticleDefinition->GetPDGSpin()), 106 theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()), 107 theElectronOccupancy(0), 108 thePreAssignedDecayProducts(0), 109 thePreAssignedDecayTime(-1.0), 110 verboseLevel(1), 111 primaryParticle(0), 112 thePDGcode(0) {} 113 114 //////////////////// 115 G4DynamicParticle::G4DynamicParticle(G4ParticleDefinition * aParticleDefinition, 116 const G4ThreeVector& aParticleMomentum): 117 theParticleDefinition(aParticleDefinition), 118 theKineticEnergy(0.0), 119 theProperTime(0.0), 120 theDynamicalMass(aParticleDefinition->GetPDGMass()), 121 theDynamicalCharge(aParticleDefinition->GetPDGCharge()), 122 theDynamicalSpin(aParticleDefinition->GetPDGSpin()), 123 theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()), 124 theElectronOccupancy(0), 102 125 thePreAssignedDecayProducts(0), 103 126 thePreAssignedDecayTime(-1.0), … … 106 129 thePDGcode(0) 107 130 { 108 // set dynamic charge/mass 109 theDynamicalMass = aParticleDefinition->GetPDGMass(); 110 theDynamicalCharge = aParticleDefinition->GetPDGCharge(); 111 theDynamicalMagneticMoment = aParticleDefinition->GetPDGMagneticMoment(); 112 AllocateElectronOccupancy(); 131 // 3-dim momentum is given 132 SetMomentum(aParticleMomentum); 113 133 } 114 134 115 135 //////////////////// 116 136 G4DynamicParticle::G4DynamicParticle(G4ParticleDefinition * aParticleDefinition, 117 const G4ThreeVector&aParticleMomentum):137 const G4LorentzVector &aParticleMomentum): 118 138 theParticleDefinition(aParticleDefinition), 119 theProperTime(0.0), 139 theKineticEnergy(0.0), 140 theProperTime(0.0), 141 theDynamicalMass(aParticleDefinition->GetPDGMass()), 142 theDynamicalCharge(aParticleDefinition->GetPDGCharge()), 143 theDynamicalSpin(aParticleDefinition->GetPDGSpin()), 144 theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()), 145 theElectronOccupancy(0), 120 146 thePreAssignedDecayProducts(0), 121 147 thePreAssignedDecayTime(-1.0), … … 124 150 thePDGcode(0) 125 151 { 126 // set dynamic charge/mass 127 theDynamicalMass = aParticleDefinition->GetPDGMass(); 128 theDynamicalCharge = aParticleDefinition->GetPDGCharge(); 129 theDynamicalMagneticMoment = aParticleDefinition->GetPDGMagneticMoment(); 130 AllocateElectronOccupancy(); 131 132 // 3-dim momentum is given 133 G4double pModule2 = aParticleMomentum.mag2(); 134 if (pModule2>0.0) { 135 G4double mass = theDynamicalMass; 136 SetKineticEnergy(std::sqrt(pModule2+mass*mass)-mass); 137 G4double pModule = std::sqrt(pModule2); 138 SetMomentumDirection(aParticleMomentum.x()/pModule, 139 aParticleMomentum.y()/pModule, 140 aParticleMomentum.z()/pModule); 141 } else { 142 SetMomentumDirection(1.0,0.0,0.0); 143 SetKineticEnergy(0.0); 144 } 145 } 146 147 //////////////////// 152 // 4-momentum vector (Lorentz vecotr) is given 153 Set4Momentum(aParticleMomentum); 154 } 155 148 156 G4DynamicParticle::G4DynamicParticle(G4ParticleDefinition * aParticleDefinition, 149 const G4LorentzVector &aParticleMomentum): 150 theParticleDefinition(aParticleDefinition), 151 theProperTime(0.0), 157 G4double totalEnergy, 158 const G4ThreeVector &aParticleMomentum): 159 theParticleDefinition(aParticleDefinition), 160 theKineticEnergy(0.0), 161 theProperTime(0.0), 162 theDynamicalMass(aParticleDefinition->GetPDGMass()), 163 theDynamicalCharge(aParticleDefinition->GetPDGCharge()), 164 theDynamicalSpin(aParticleDefinition->GetPDGSpin()), 165 theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()), 166 theElectronOccupancy(0), 152 167 thePreAssignedDecayProducts(0), 153 168 thePreAssignedDecayTime(-1.0), … … 156 171 thePDGcode(0) 157 172 { 158 // set dynamic charge/mass 159 theDynamicalMass = aParticleDefinition->GetPDGMass(); 160 theDynamicalCharge = aParticleDefinition->GetPDGCharge(); 161 theDynamicalMagneticMoment = aParticleDefinition->GetPDGMagneticMoment(); 162 AllocateElectronOccupancy(); 163 164 // 4-momentum vector (Lorentz vecotr) is given 165 G4double pModule2 = aParticleMomentum.x()*aParticleMomentum.x() 166 + aParticleMomentum.y()*aParticleMomentum.y() 167 + aParticleMomentum.z()*aParticleMomentum.z(); 173 // total energy and 3-dim momentum are given 174 G4double pModule2 = aParticleMomentum.mag2(); 168 175 if (pModule2>0.0) { 169 G4double pModule = std::sqrt(pModule2); 170 SetMomentumDirection(aParticleMomentum.x()/pModule, 171 aParticleMomentum.y()/pModule, 172 aParticleMomentum.z()/pModule); 173 G4double totalenergy = aParticleMomentum.t(); 176 G4double mass2 = totalEnergy*totalEnergy - pModule2; 177 if(mass2 < EnergyMomentumRelationAllowance*EnergyMomentumRelationAllowance) { 178 theDynamicalMass = 0.; 179 SetMomentumDirection(aParticleMomentum.unit()); 180 SetKineticEnergy(totalEnergy); 181 } else { 182 theDynamicalMass = std::sqrt(mass2); 183 SetMomentum(aParticleMomentum); 184 } 185 } else { 186 SetMomentumDirection(1.0,0.0,0.0); 187 SetKineticEnergy(0.0); 188 } 189 } 190 191 //////////////////// 192 G4DynamicParticle::G4DynamicParticle(const G4DynamicParticle &right): 193 theMomentumDirection(right.theMomentumDirection), 194 theParticleDefinition(right.theParticleDefinition), 195 thePolarization(right.thePolarization), 196 theKineticEnergy(right.theKineticEnergy), 197 theProperTime(0.0), 198 theDynamicalMass(right.theDynamicalMass), 199 theDynamicalCharge(right.theDynamicalCharge), 200 theDynamicalSpin(right.theDynamicalSpin), 201 theDynamicalMagneticMoment(right.theDynamicalMagneticMoment), 202 theElectronOccupancy(0), 203 thePreAssignedDecayProducts(0), // Do not copy preassignedDecayProducts 204 thePreAssignedDecayTime(-1.0), 205 verboseLevel(right.verboseLevel), 206 primaryParticle(right.primaryParticle), 207 thePDGcode(right.thePDGcode) 208 { 209 if (right.theElectronOccupancy != 0) { 210 theElectronOccupancy = 211 new G4ElectronOccupancy(*right.theElectronOccupancy); 212 } 213 } 214 215 //////////////////// 216 // -- destructor ---- 217 //////////////////// 218 G4DynamicParticle::~G4DynamicParticle() { 219 220 // delete thePreAssignedDecayProducts 221 if (thePreAssignedDecayProducts != 0) delete thePreAssignedDecayProducts; 222 thePreAssignedDecayProducts = 0; 223 224 if (theElectronOccupancy != 0) delete theElectronOccupancy; 225 theElectronOccupancy =0; 226 } 227 228 229 //////////////////// 230 // -- operators ---- 231 //////////////////// 232 G4DynamicParticle & G4DynamicParticle::operator=(const G4DynamicParticle &right) 233 { 234 if (this != &right) { 235 theMomentumDirection = right.theMomentumDirection; 236 theParticleDefinition = right.theParticleDefinition; 237 thePolarization = right.thePolarization; 238 theKineticEnergy = right.theKineticEnergy; 239 theProperTime = right.theProperTime; 240 241 theDynamicalMass = right.theDynamicalMass; 242 theDynamicalCharge = right.theDynamicalCharge; 243 theDynamicalSpin = right.theDynamicalSpin; 244 theDynamicalMagneticMoment = right.theDynamicalMagneticMoment; 245 246 if (theElectronOccupancy != 0) delete theElectronOccupancy; 247 if (right.theElectronOccupancy != 0){ 248 theElectronOccupancy = 249 new G4ElectronOccupancy(*right.theElectronOccupancy); 250 } else { 251 theElectronOccupancy = 0; 252 } 253 254 // thePreAssignedDecayProducts must not be copied. 255 thePreAssignedDecayProducts = 0; 256 thePreAssignedDecayTime = -1.0; 257 258 verboseLevel = right.verboseLevel; 259 260 // Primary particle information must be preserved 261 //*** primaryParticle = right.primaryParticle; 262 263 thePDGcode = right.thePDGcode; 264 } 265 return *this; 266 } 267 268 //////////////////// 269 void G4DynamicParticle::SetDefinition(G4ParticleDefinition * aParticleDefinition) 270 { 271 // remove preassigned decay 272 if (thePreAssignedDecayProducts != 0) { 273 #ifdef G4VERBOSE 274 if (verboseLevel>0) { 275 G4cerr << " G4DynamicParticle::SetDefinition()::" 276 << "!!! Pre-assigned decay products is attached !!!! " << G4endl; 277 G4cerr << "!!! New Definition is " << aParticleDefinition->GetParticleName() 278 << " !!! " << G4endl; 279 G4cerr << "!!! Pre-assigned decay products will be deleted !!!! " << G4endl; 280 } 281 #endif 282 delete thePreAssignedDecayProducts; 283 } 284 thePreAssignedDecayProducts = 0; 285 286 theParticleDefinition = aParticleDefinition; 287 288 // set Dynamic mass/chrge 289 theDynamicalMass = theParticleDefinition->GetPDGMass(); 290 theDynamicalCharge = theParticleDefinition->GetPDGCharge(); 291 theDynamicalSpin = theParticleDefinition->GetPDGSpin(); 292 theDynamicalMagneticMoment = theParticleDefinition->GetPDGMagneticMoment(); 293 294 // Set electron orbits 295 if (theElectronOccupancy != 0) delete theElectronOccupancy; 296 theElectronOccupancy =0; 297 //AllocateElectronOccupancy(); 298 299 } 300 301 //////////////////// 302 G4int G4DynamicParticle::operator==(const G4DynamicParticle &right) const 303 { 304 return (this == (G4DynamicParticle *) &right); 305 } 306 307 //////////////////// 308 G4int G4DynamicParticle::operator!=(const G4DynamicParticle &right) const 309 { 310 return (this != (G4DynamicParticle *) &right); 311 } 312 313 314 315 //////////////////// 316 // -- AllocateElectronOccupancy -- 317 //////////////////// 318 void G4DynamicParticle::AllocateElectronOccupancy() 319 { 320 G4ParticleDefinition* particle = GetDefinition(); 321 322 if (G4IonTable::IsIon(particle)) { 323 // Only ions can have ElectronOccupancy 324 theElectronOccupancy = new G4ElectronOccupancy(); 325 326 } else { 327 theElectronOccupancy = 0; 328 329 } 330 } 331 332 //////////////////// 333 // -- methods for setting Energy/Momentum -- 334 //////////////////// 335 void G4DynamicParticle::SetMomentum(const G4ThreeVector &momentum) 336 { 337 G4double pModule2 = momentum.mag2(); 338 if (pModule2>0.0) { 339 G4double mass = theDynamicalMass; 340 SetMomentumDirection(momentum.unit()); 341 SetKineticEnergy(std::sqrt(pModule2 + mass*mass)-mass); 342 } else { 343 SetMomentumDirection(1.0,0.0,0.0); 344 SetKineticEnergy(0.0); 345 } 346 } 347 348 //////////////////// 349 void G4DynamicParticle::Set4Momentum(const G4LorentzVector &momentum ) 350 { 351 G4double pModule2 = momentum.vect().mag2(); 352 if (pModule2>0.0) { 353 SetMomentumDirection(momentum.vect().unit()); 354 G4double totalenergy = momentum.t(); 174 355 G4double mass2 = totalenergy*totalenergy - pModule2; 175 356 if(mass2 < EnergyMomentumRelationAllowance*EnergyMomentumRelationAllowance) { … … 180 361 SetKineticEnergy(totalenergy-theDynamicalMass); 181 362 } 182 183 } else {184 SetMomentumDirection(1.0,0.0,0.0);185 SetKineticEnergy(0.0);186 }187 }188 189 G4DynamicParticle::G4DynamicParticle(G4ParticleDefinition * aParticleDefinition,190 G4double totalEnergy,191 const G4ThreeVector &aParticleMomentum):192 theParticleDefinition(aParticleDefinition),193 theProperTime(0.0),194 thePreAssignedDecayProducts(0),195 thePreAssignedDecayTime(-1.0),196 verboseLevel(1),197 primaryParticle(0),198 thePDGcode(0)199 {200 // set dynamic charge/mass201 theDynamicalMass = aParticleDefinition->GetPDGMass();202 theDynamicalCharge = aParticleDefinition->GetPDGCharge();203 theDynamicalMagneticMoment = aParticleDefinition->GetPDGMagneticMoment();204 AllocateElectronOccupancy();205 206 // total energy and momentum direction are given207 G4double pModule2 = aParticleMomentum.mag2();208 if (pModule2>0.0) {209 G4double pModule = std::sqrt(pModule2);210 SetMomentumDirection(aParticleMomentum.x()/pModule,211 aParticleMomentum.y()/pModule,212 aParticleMomentum.z()/pModule);213 214 G4double mass2 = totalEnergy*totalEnergy - pModule2;215 if(mass2 < EnergyMomentumRelationAllowance*EnergyMomentumRelationAllowance) {216 theDynamicalMass = 0.;217 SetKineticEnergy(totalEnergy);218 } else {219 theDynamicalMass = std::sqrt(mass2);220 SetKineticEnergy(totalEnergy-theDynamicalMass);221 }222 } else {223 SetMomentumDirection(1.0,0.0,0.0);224 SetKineticEnergy(0.0);225 }226 }227 228 ////////////////////229 G4DynamicParticle::G4DynamicParticle(const G4DynamicParticle &right)230 {231 theDynamicalMass = right.theDynamicalMass;232 theDynamicalCharge = right.theDynamicalCharge;233 theDynamicalMagneticMoment = right.theDynamicalMagneticMoment;234 235 if (right.theElectronOccupancy != 0){236 theElectronOccupancy =237 new G4ElectronOccupancy(*right.theElectronOccupancy);238 } else {239 theElectronOccupancy = 0;240 }241 242 theParticleDefinition = right.theParticleDefinition;243 theMomentumDirection = right.theMomentumDirection;244 theKineticEnergy = right.theKineticEnergy;245 thePolarization = right.thePolarization;246 verboseLevel = right.verboseLevel;247 248 // proper time is set to zero249 theProperTime = 0.0;250 251 // thePreAssignedDecayProducts/Time must not be copied.252 thePreAssignedDecayProducts = 0;253 thePreAssignedDecayTime = -1.0;254 255 primaryParticle = right.primaryParticle;256 thePDGcode = right.thePDGcode;257 }258 259 ////////////////////260 // -- destructor ----261 ////////////////////262 G4DynamicParticle::~G4DynamicParticle() {263 264 // delete thePreAssignedDecayProducts265 if (thePreAssignedDecayProducts != 0) delete thePreAssignedDecayProducts;266 thePreAssignedDecayProducts = 0;267 268 if (theElectronOccupancy != 0) delete theElectronOccupancy;269 theElectronOccupancy =0;270 }271 272 273 ////////////////////274 // -- operators ----275 ////////////////////276 G4DynamicParticle & G4DynamicParticle::operator=(const G4DynamicParticle &right)277 {278 if (this != &right) {279 theDynamicalMass = right.theDynamicalMass;280 theDynamicalCharge = right.theDynamicalCharge;281 theDynamicalMagneticMoment = right.theDynamicalMagneticMoment;282 283 if (theElectronOccupancy != 0) delete theElectronOccupancy;284 if (right.theElectronOccupancy != 0){285 theElectronOccupancy =286 new G4ElectronOccupancy(*right.theElectronOccupancy);287 } else {288 theElectronOccupancy = 0;289 }290 291 theParticleDefinition = right.theParticleDefinition;292 theMomentumDirection = right.theMomentumDirection;293 theKineticEnergy = right.theKineticEnergy;294 thePolarization = right.thePolarization;295 theProperTime = right.theProperTime;296 verboseLevel = right.verboseLevel;297 298 // thePreAssignedDecayProducts must not be copied.299 thePreAssignedDecayProducts = 0;300 thePreAssignedDecayTime = -1.0;301 302 }303 return *this;304 }305 306 ////////////////////307 void G4DynamicParticle::SetDefinition(G4ParticleDefinition * aParticleDefinition)308 {309 // remove preassigned decay310 if (thePreAssignedDecayProducts != 0) {311 #ifdef G4VERBOSE312 if (verboseLevel>0) {313 G4cout << " G4DynamicParticle::SetDefinition()::";314 G4cout << "!!! Pre-assigned decay products is attached !!!! " << G4endl;315 DumpInfo(0);316 G4cout << "!!! New Definition is " << aParticleDefinition->GetParticleName()317 << " !!! " << G4endl;318 G4cout << "!!! Pre-assigned decay products will be deleted !!!! " << G4endl;319 }320 #endif321 delete thePreAssignedDecayProducts;322 }323 thePreAssignedDecayProducts = 0;324 325 theParticleDefinition = aParticleDefinition;326 // set Dynamic mass/chrge327 theDynamicalMass = theParticleDefinition->GetPDGMass();328 theDynamicalCharge = theParticleDefinition->GetPDGCharge();329 theDynamicalMagneticMoment = theParticleDefinition->GetPDGMagneticMoment();330 331 // Set electron orbits332 if (theElectronOccupancy != 0) delete theElectronOccupancy;333 theElectronOccupancy =0;334 AllocateElectronOccupancy();335 336 }337 338 ////////////////////339 G4int G4DynamicParticle::operator==(const G4DynamicParticle &right) const340 {341 return (this == (G4DynamicParticle *) &right);342 }343 344 ////////////////////345 G4int G4DynamicParticle::operator!=(const G4DynamicParticle &right) const346 {347 return (this != (G4DynamicParticle *) &right);348 }349 350 351 352 ////////////////////353 // -- AllocateElectronOccupancy --354 ////////////////////355 void G4DynamicParticle::AllocateElectronOccupancy()356 {357 G4ParticleDefinition* particle = GetDefinition();358 359 if (G4IonTable::IsIon(particle)) {360 // Only ions can have ElectronOccupancy361 theElectronOccupancy = new G4ElectronOccupancy();362 363 } else {364 theElectronOccupancy = 0;365 366 }367 }368 369 ////////////////////370 // -- methods for setting Energy/Momentum --371 ////////////////////372 void G4DynamicParticle::SetMomentum(const G4ThreeVector &momentum)373 {374 G4double pModule2 = momentum.mag2();375 if (pModule2>0.0) {376 G4double mass = theDynamicalMass;377 G4double pModule = std::sqrt(pModule2);378 SetMomentumDirection(momentum.x()/pModule,379 momentum.y()/pModule,380 momentum.z()/pModule);381 SetKineticEnergy(std::sqrt(pModule2 + mass*mass)-mass);382 } else {383 SetMomentumDirection(1.0,0.0,0.0);384 SetKineticEnergy(0.0);385 }386 }387 388 ////////////////////389 void G4DynamicParticle::Set4Momentum(const G4LorentzVector &momentum )390 {391 G4double pModule2 = momentum.x()*momentum.x()392 + momentum.y()*momentum.y()393 + momentum.z()*momentum.z();394 if (pModule2>0.0) {395 G4double pModule = std::sqrt(pModule2);396 SetMomentumDirection(momentum.x()/pModule,397 momentum.y()/pModule,398 momentum.z()/pModule);399 G4double totalenergy = momentum.t();400 G4double mass2 = totalenergy*totalenergy - pModule2;401 if(mass2 < 0.0001*MeV*MeV) {402 theDynamicalMass = 0.;403 SetKineticEnergy(totalenergy);404 } else {405 theDynamicalMass = std::sqrt(mass2);406 SetKineticEnergy(totalenergy-theDynamicalMass);407 }408 409 363 } else { 410 364 SetMomentumDirection(1.0,0.0,0.0);
Note: See TracChangeset
for help on using the changeset viewer.