Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4DynamicParticle.cc
Go to the documentation of this file.
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: G4DynamicParticle.cc 98352 2016-07-08 08:21:00Z gcosmo $
28 //
29 //
30 // --------------------------------------------------------------
31 // GEANT 4 class implementation file
32 //
33 // History: first implementation, based on object model of
34 // 2nd December 1995, G.Cosmo
35 // ---------------- G4DynamicParticle ----------------
36 // first implementation by Makoto Asai, 29 January 1996
37 // revised by G.Cosmo, 29 February 1996
38 // revised by H.Kurashige 06 May 1996
39 // revised by Hisaya Kurashige, 27 July 1996
40 // modify thePreAssignedDecayProducts
41 // add void SetMomentum(G4ThreeVector &momentum)
42 // add void Set4Momentum(G4LorentzVector &momentum)
43 // add G4DynamicParticle(G4ParticleDefinition * aParticleDefinition,
44 // G4LorentzVector &p4vector)
45 // revised by Hisaya Kurashige, 19 Oct 1996
46 // add theKillProcess
47 // add ProperTime
48 // revised by Hisaya Kurashige, 26 Mar 1997
49 // modify destructor
50 // revised by Hisaya Kurashige, 05 June 1997
51 // modify DumpInfo()
52 // revised by Hisaya Kurashige, 5 June 1998
53 // remove theKillProcess
54 // revised by Hisaya Kurashige, 5 Mar 2001
55 // fixed SetDefinition()
56 // revised by V.Ivanchenko, 12 June 2003
57 // fixed problem of massless particles
58 // revised by V.Ivanchenko, 18 June 2003
59 // take into account the case of virtual photons
60 // revised by M.Kelsey 12 May 2010
61 // ensure that all constructors initialize all data members
62 //--------------------------------------------------------------
63 
64 #include "G4DynamicParticle.hh"
65 #include "G4PhysicalConstants.hh"
66 #include "G4SystemOfUnits.hh"
67 #include "G4DecayProducts.hh"
68 #include "G4LorentzVector.hh"
69 #include "G4ParticleDefinition.hh"
70 #include "G4ParticleTable.hh"
71 #include "G4IonTable.hh"
72 #include "G4PrimaryParticle.hh"
73 
75 
77 
80  theMomentumDirection(0.0,0.0,1.0),
81  theParticleDefinition(0),
82  theKineticEnergy(0.0),
83  theProperTime(0.0),
84  theDynamicalMass(0.0),
85  theDynamicalCharge(0.0),
86  theDynamicalSpin(0.0),
87  theDynamicalMagneticMoment(0.0),
88  theElectronOccupancy(0),
89  thePreAssignedDecayProducts(0),
90  thePreAssignedDecayTime(-1.0),
91  verboseLevel(1),
92  primaryParticle(0),
93  thePDGcode(0)
94 {
95 }
96 
98 // -- constructors ----
101  const G4ThreeVector& aMomentumDirection,
102  G4double aKineticEnergy):
103  theMomentumDirection(aMomentumDirection),
104  theParticleDefinition(aParticleDefinition),
105  theKineticEnergy(aKineticEnergy),
106  theProperTime(0.0),
107  theDynamicalMass(aParticleDefinition->GetPDGMass()),
108  theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
109  theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
110  theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
111  theElectronOccupancy(0),
112  thePreAssignedDecayProducts(0),
113  thePreAssignedDecayTime(-1.0),
114  verboseLevel(1),
115  primaryParticle(0),
116  thePDGcode(0)
117 {
118 }
119 
122  const G4ThreeVector& aMomentumDirection,
123  G4double aKineticEnergy,
124  const G4double dynamicalMass):
125  theMomentumDirection(aMomentumDirection),
126  theParticleDefinition(aParticleDefinition),
127  theKineticEnergy(aKineticEnergy),
128  theProperTime(0.0),
129  theDynamicalMass(aParticleDefinition->GetPDGMass()),
130  theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
131  theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
132  theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
133  theElectronOccupancy(0),
134  thePreAssignedDecayProducts(0),
135  thePreAssignedDecayTime(-1.0),
136  verboseLevel(1),
137  primaryParticle(0),
138  thePDGcode(0)
139 {
140  if (std::abs(theDynamicalMass-dynamicalMass)> EnergyMomentumRelationAllowance) {
141  if (dynamicalMass>EnergyMomentumRelationAllowance) theDynamicalMass= dynamicalMass;
142  else theDynamicalMass= 0.0;
143  }
144 }
145 
148  const G4ThreeVector& aParticleMomentum):
149  theParticleDefinition(aParticleDefinition),
150  theKineticEnergy(0.0),
151  theProperTime(0.0),
152  theDynamicalMass(aParticleDefinition->GetPDGMass()),
153  theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
154  theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
155  theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
156  theElectronOccupancy(0),
157  thePreAssignedDecayProducts(0),
158  thePreAssignedDecayTime(-1.0),
159  verboseLevel(1),
160  primaryParticle(0),
161  thePDGcode(0)
162 {
163  SetMomentum(aParticleMomentum); // 3-dim momentum is given
164 }
165 
166 
169  const G4LorentzVector &aParticleMomentum):
170  theParticleDefinition(aParticleDefinition),
171  theKineticEnergy(0.0),
172  theProperTime(0.0),
173  theDynamicalMass(aParticleDefinition->GetPDGMass()),
174  theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
175  theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
176  theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
177  theElectronOccupancy(0),
178  thePreAssignedDecayProducts(0),
179  thePreAssignedDecayTime(-1.0),
180  verboseLevel(1),
181  primaryParticle(0),
182  thePDGcode(0)
183 {
184  Set4Momentum(aParticleMomentum); // 4-momentum vector (Lorentz vector) is given
185 }
186 
188  G4double totalEnergy,
189  const G4ThreeVector &aParticleMomentum):
190  theParticleDefinition(aParticleDefinition),
191  theKineticEnergy(0.0),
192  theProperTime(0.0),
193  theDynamicalMass(aParticleDefinition->GetPDGMass()),
194  theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
195  theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
196  theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
197  theElectronOccupancy(0),
198  thePreAssignedDecayProducts(0),
199  thePreAssignedDecayTime(-1.0),
200  verboseLevel(1),
201  primaryParticle(0),
202  thePDGcode(0)
203 {
204  // total energy and 3-dim momentum are given
205  G4double pModule2 = aParticleMomentum.mag2();
206  if (pModule2>0.0) {
207  G4double mass2 = totalEnergy*totalEnergy - pModule2;
208  G4double PDGmass2 = (aParticleDefinition->GetPDGMass())*(aParticleDefinition->GetPDGMass());
209  SetMomentumDirection(aParticleMomentum.unit());
211  theDynamicalMass = 0.;
212  SetKineticEnergy(totalEnergy);
213  } else {
214  if (std::abs(PDGmass2-mass2)>EnergyMomentumRelationAllowance*EnergyMomentumRelationAllowance){
215  theDynamicalMass = std::sqrt(mass2);
216  SetKineticEnergy(totalEnergy-theDynamicalMass);
217  } else {
218  SetKineticEnergy(totalEnergy-theDynamicalMass);
219  }
220  }
221  } else {
222  SetMomentumDirection(1.0,0.0,0.0);
223  SetKineticEnergy(0.0);
224  }
225 }
226 
229  theMomentumDirection(right.theMomentumDirection),
230  theParticleDefinition(right.theParticleDefinition),
231  thePolarization(right.thePolarization),
232  theKineticEnergy(right.theKineticEnergy),
233  theProperTime(0.0),
234  theDynamicalMass(right.theDynamicalMass),
235  theDynamicalCharge(right.theDynamicalCharge),
236  theDynamicalSpin(right.theDynamicalSpin),
237  theDynamicalMagneticMoment(right.theDynamicalMagneticMoment),
238  theElectronOccupancy(0),
239  thePreAssignedDecayProducts(0), // Do not copy preassignedDecayProducts
240  thePreAssignedDecayTime(-1.0),
241  verboseLevel(right.verboseLevel),
242  primaryParticle(right.primaryParticle),
243  thePDGcode(right.thePDGcode)
244 {
245  if (right.theElectronOccupancy != 0) {
248  }
249 }
250 
252 // -- destructor ----
255 {
256  // delete thePreAssignedDecayProducts
259 
262 }
263 
264 
266 // -- operators ----
269 {
270  if (this != &right) {
276 
281 
283  if (right.theElectronOccupancy != 0){
286  } else {
288  }
289 
290  // thePreAssignedDecayProducts must not be copied.
293 
294  verboseLevel = right.verboseLevel;
295 
296  // Primary particle information must be preserved
297  //*** primaryParticle = right.primaryParticle;
298 
299  thePDGcode = right.thePDGcode;
300  }
301  return *this;
302 }
303 
306 {
307  // remove preassigned decay
308  if (thePreAssignedDecayProducts != 0) {
309 #ifdef G4VERBOSE
310  if (verboseLevel>0) {
311  G4cout << " G4DynamicParticle::SetDefinition()::"
312  << "!!! Pre-assigned decay products is attached !!!! " << G4endl;
313  G4cout << "!!! New Definition is " << aParticleDefinition->GetParticleName()
314  << " !!! " << G4endl;
315  G4cout << "!!! Pre-assigned decay products will be deleted !!!! " << G4endl;
316  }
317 #endif
319  }
321 
322  theParticleDefinition = aParticleDefinition;
323 
324  // set Dynamic mass/chrge
329 
330  // Set electron orbits
333  //AllocateElectronOccupancy();
334 
335 }
336 
339 {
340  return (this == (G4DynamicParticle *) &right);
341 }
342 
345 {
346  return (this != (G4DynamicParticle *) &right);
347 }
348 
349 
350 
352 // -- AllocateElectronOccupancy --
355 {
356  const G4ParticleDefinition* particle = GetDefinition();
357 
358  if (G4IonTable::IsIon(particle)) {
359  // Only ions can have ElectronOccupancy
361 
362  } else {
364 
365  }
366 }
367 
369 // -- methods for setting Energy/Momentum --
372 {
373  G4double pModule2 = momentum.mag2();
374  if (pModule2>0.0) {
375  G4double mass = theDynamicalMass;
376  SetMomentumDirection(momentum.unit());
377  SetKineticEnergy(std::sqrt(pModule2 + mass*mass)-mass);
378  } else {
379  SetMomentumDirection(1.0,0.0,0.0);
380  SetKineticEnergy(0.0);
381  }
382 }
383 
386 {
387  G4double pModule2 = momentum.vect().mag2();
388  if (pModule2>0.0) {
389  SetMomentumDirection(momentum.vect().unit());
390  G4double totalenergy = momentum.t();
391  G4double mass2 = totalenergy*totalenergy - pModule2;
394  theDynamicalMass = 0.;
395  } else if (std::abs(PDGmass2-mass2)>EnergyMomentumRelationAllowance*EnergyMomentumRelationAllowance){
396  theDynamicalMass = std::sqrt(mass2);
397  }
398  SetKineticEnergy(totalenergy-theDynamicalMass);
399  } else {
400  SetMomentumDirection(1.0,0.0,0.0);
401  SetKineticEnergy(0.0);
402  }
403 }
404 
405 
407 // --- Dump Information --
409 #ifdef G4VERBOSE
410 void G4DynamicParticle::DumpInfo(G4int mode) const
411 {
412  if (theParticleDefinition == 0) {
413  G4cout << " G4DynamicParticle::DumpInfo():: !!!Particle type not defined !!!! " << G4endl;
414  } else {
415  G4cout << " Particle type - " << theParticleDefinition->GetParticleName() << G4endl
416  << " mass: " << GetMass()/GeV << "[GeV]" <<G4endl
417  << " charge: " << GetCharge()/eplus << "[e]" <<G4endl
418  << " Direction x: " << GetMomentumDirection().x() << ", y: "
419  << GetMomentumDirection().y() << ", z: "
420  << GetMomentumDirection().z() << G4endl
421  << " Total Momentum = " << GetTotalMomentum() /GeV << "[GeV]" << G4endl
422  << " Momentum: " << GetMomentum().x() /GeV << "[GeV]" << ", y: "
423  << GetMomentum().y() /GeV << "[GeV]" << ", z: "
424  << GetMomentum().z() /GeV << "[GeV]" << G4endl
425  << " Total Energy = " << GetTotalEnergy()/GeV << "[GeV]" << G4endl
426  << " Kinetic Energy = " << GetKineticEnergy() /GeV << "[GeV]" << G4endl
427  << " MagneticMoment [MeV/T]: " << GetMagneticMoment()/MeV*tesla << G4endl
428  << " ProperTime = " << GetProperTime() /ns << "[ns]" << G4endl;
429 
430  if (mode>0) {
431  if( theElectronOccupancy != 0) {
433  }
434  }
435  }
436 }
437 #else
439 {
440  return;
441 }
442 #endif
443 //
446 {
448  theDynamicalMass = newMass;
449  }
450 }
453 {
454  static G4ThreadLocal G4double electronMass = 0.0;
455 
456  // check if electron exits and get the mass
457  if (electronMass<=0.0) {
459  if (electron == 0) {
460  G4Exception("G4DynamicParticle::GetElectronMass()","PART021",
461  FatalException,"G4DynamicParticle: G4Electron is not defined !!");
462  }
463  electronMass = electron->GetPDGMass();
464  }
465 
466  return electronMass;
467 }
static constexpr double tesla
Definition: G4SIunits.hh:268
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
void SetMomentum(const G4ThreeVector &momentum)
G4double GetKineticEnergy() const
G4double GetTotalEnergy() const
G4double theDynamicalMagneticMoment
double x() const
G4double GetProperTime() const
void DumpInfo(G4int mode=0) const
static G4bool IsIon(const G4ParticleDefinition *)
Definition: G4IonTable.cc:1147
void SetMomentumDirection(const G4ThreeVector &aDirection)
G4ParticleDefinition * GetDefinition() const
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
G4ThreeVector theMomentumDirection
const G4String & GetParticleName() const
double z() const
G4double GetTotalMomentum() const
Hep3Vector vect() const
G4GLOB_DLL std::ostream G4cout
static const G4double EnergyMomentumRelationAllowance
G4double GetMass() const
const G4ThreeVector & GetMomentumDirection() const
G4double GetCharge() const
static constexpr double eplus
Definition: G4SIunits.hh:199
void SetKineticEnergy(G4double aEnergy)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void Set4Momentum(const G4LorentzVector &momentum)
G4DecayProducts * thePreAssignedDecayProducts
G4int operator!=(const G4DynamicParticle &right) const
G4double GetPDGMass() const
G4ElectronOccupancy * theElectronOccupancy
static G4ParticleTable * GetParticleTable()
G4int operator==(const G4DynamicParticle &right) const
Hep3Vector unit() const
double y() const
static constexpr double GeV
Definition: G4SIunits.hh:217
double mag2() const
G4double thePreAssignedDecayTime
G4double GetPDGSpin() const
G4ThreeVector thePolarization
#define G4endl
Definition: G4ios.hh:61
static constexpr double MeV
Definition: G4SIunits.hh:214
G4ThreadLocal G4Allocator< G4DynamicParticle > * pDynamicParticleAllocator
G4double GetPDGMagneticMoment() const
double G4double
Definition: G4Types.hh:76
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
const G4ParticleDefinition * theParticleDefinition
G4double GetPDGCharge() const
static constexpr double keV
Definition: G4SIunits.hh:216
#define ns
Definition: xmlparse.cc:614
G4double GetMagneticMoment() const
void SetMass(G4double mass)
G4DynamicParticle & operator=(const G4DynamicParticle &right)
G4ThreeVector GetMomentum() const
G4double GetElectronMass() const