Geant4  10.01.p01
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 81373 2014-05-27 13:06:32Z 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(dynamicalMass),
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 }
141 
144  const G4ThreeVector& aParticleMomentum):
145  theParticleDefinition(aParticleDefinition),
146  theKineticEnergy(0.0),
147  theProperTime(0.0),
148  theDynamicalMass(aParticleDefinition->GetPDGMass()),
149  theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
150  theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
151  theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
152  theElectronOccupancy(0),
153  thePreAssignedDecayProducts(0),
154  thePreAssignedDecayTime(-1.0),
155  verboseLevel(1),
156  primaryParticle(0),
157  thePDGcode(0)
158 {
159  SetMomentum(aParticleMomentum); // 3-dim momentum is given
160 }
161 
162 
165  const G4LorentzVector &aParticleMomentum):
166  theParticleDefinition(aParticleDefinition),
167  theKineticEnergy(0.0),
168  theProperTime(0.0),
169  theDynamicalMass(aParticleDefinition->GetPDGMass()),
170  theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
171  theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
172  theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
173  theElectronOccupancy(0),
174  thePreAssignedDecayProducts(0),
175  thePreAssignedDecayTime(-1.0),
176  verboseLevel(1),
177  primaryParticle(0),
178  thePDGcode(0)
179 {
180  Set4Momentum(aParticleMomentum); // 4-momentum vector (Lorentz vector) is given
181 }
182 
184  G4double totalEnergy,
185  const G4ThreeVector &aParticleMomentum):
186  theParticleDefinition(aParticleDefinition),
187  theKineticEnergy(0.0),
188  theProperTime(0.0),
189  theDynamicalMass(aParticleDefinition->GetPDGMass()),
190  theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
191  theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
192  theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
193  theElectronOccupancy(0),
194  thePreAssignedDecayProducts(0),
195  thePreAssignedDecayTime(-1.0),
196  verboseLevel(1),
197  primaryParticle(0),
198  thePDGcode(0)
199 {
200  // total energy and 3-dim momentum are given
201  G4double pModule2 = aParticleMomentum.mag2();
202  if (pModule2>0.0) {
203  G4double mass2 = totalEnergy*totalEnergy - pModule2;
205  theDynamicalMass = 0.;
206  SetMomentumDirection(aParticleMomentum.unit());
207  SetKineticEnergy(totalEnergy);
208  } else {
209  theDynamicalMass = std::sqrt(mass2);
210  SetMomentum(aParticleMomentum);
211  }
212  } else {
213  SetMomentumDirection(1.0,0.0,0.0);
214  SetKineticEnergy(0.0);
215  }
216 }
217 
220  theMomentumDirection(right.theMomentumDirection),
221  theParticleDefinition(right.theParticleDefinition),
222  thePolarization(right.thePolarization),
223  theKineticEnergy(right.theKineticEnergy),
224  theProperTime(0.0),
225  theDynamicalMass(right.theDynamicalMass),
226  theDynamicalCharge(right.theDynamicalCharge),
227  theDynamicalSpin(right.theDynamicalSpin),
228  theDynamicalMagneticMoment(right.theDynamicalMagneticMoment),
229  theElectronOccupancy(0),
230  thePreAssignedDecayProducts(0), // Do not copy preassignedDecayProducts
231  thePreAssignedDecayTime(-1.0),
232  verboseLevel(right.verboseLevel),
233  primaryParticle(right.primaryParticle),
234  thePDGcode(right.thePDGcode)
235 {
236  if (right.theElectronOccupancy != 0) {
239  }
240 }
241 
243 // -- destructor ----
246 {
247  // delete thePreAssignedDecayProducts
250 
253 }
254 
255 
257 // -- operators ----
260 {
261  if (this != &right) {
267 
272 
274  if (right.theElectronOccupancy != 0){
277  } else {
279  }
280 
281  // thePreAssignedDecayProducts must not be copied.
284 
285  verboseLevel = right.verboseLevel;
286 
287  // Primary particle information must be preserved
288  //*** primaryParticle = right.primaryParticle;
289 
290  thePDGcode = right.thePDGcode;
291  }
292  return *this;
293 }
294 
297 {
298  // remove preassigned decay
299  if (thePreAssignedDecayProducts != 0) {
300 #ifdef G4VERBOSE
301  if (verboseLevel>0) {
302  G4cout << " G4DynamicParticle::SetDefinition()::"
303  << "!!! Pre-assigned decay products is attached !!!! " << G4endl;
304  G4cout << "!!! New Definition is " << aParticleDefinition->GetParticleName()
305  << " !!! " << G4endl;
306  G4cout << "!!! Pre-assigned decay products will be deleted !!!! " << G4endl;
307  }
308 #endif
310  }
312 
313  theParticleDefinition = aParticleDefinition;
314 
315  // set Dynamic mass/chrge
320 
321  // Set electron orbits
324  //AllocateElectronOccupancy();
325 
326 }
327 
330 {
331  return (this == (G4DynamicParticle *) &right);
332 }
333 
336 {
337  return (this != (G4DynamicParticle *) &right);
338 }
339 
340 
341 
343 // -- AllocateElectronOccupancy --
346 {
347  const G4ParticleDefinition* particle = GetDefinition();
348 
349  if (G4IonTable::IsIon(particle)) {
350  // Only ions can have ElectronOccupancy
352 
353  } else {
355 
356  }
357 }
358 
360 // -- methods for setting Energy/Momentum --
363 {
364  G4double pModule2 = momentum.mag2();
365  if (pModule2>0.0) {
366  G4double mass = theDynamicalMass;
367  SetMomentumDirection(momentum.unit());
368  SetKineticEnergy(std::sqrt(pModule2 + mass*mass)-mass);
369  } else {
370  SetMomentumDirection(1.0,0.0,0.0);
371  SetKineticEnergy(0.0);
372  }
373 }
374 
377 {
378  G4double pModule2 = momentum.vect().mag2();
379  if (pModule2>0.0) {
380  SetMomentumDirection(momentum.vect().unit());
381  G4double totalenergy = momentum.t();
382  G4double mass2 = totalenergy*totalenergy - pModule2;
384  theDynamicalMass = 0.;
385  SetKineticEnergy(totalenergy);
386  } else {
387  theDynamicalMass = std::sqrt(mass2);
388  SetKineticEnergy(totalenergy-theDynamicalMass);
389  }
390  } else {
391  SetMomentumDirection(1.0,0.0,0.0);
392  SetKineticEnergy(0.0);
393  }
394 }
395 
396 
398 // --- Dump Information --
400 #ifdef G4VERBOSE
401 void G4DynamicParticle::DumpInfo(G4int mode) const
402 {
403  if (theParticleDefinition == 0) {
404  G4cout << " G4DynamicParticle::DumpInfo():: !!!Particle type not defined !!!! " << G4endl;
405  } else {
406  G4cout << " Particle type - " << theParticleDefinition->GetParticleName() << G4endl
407  << " mass: " << GetMass()/GeV << "[GeV]" <<G4endl
408  << " charge: " << GetCharge()/eplus << "[e]" <<G4endl
409  << " Direction x: " << GetMomentumDirection().x() << ", y: "
410  << GetMomentumDirection().y() << ", z: "
411  << GetMomentumDirection().z() << G4endl
412  << " Total Momentum = " << GetTotalMomentum() /GeV << "[GeV]" << G4endl
413  << " Momentum: " << GetMomentum().x() /GeV << "[GeV]" << ", y: "
414  << GetMomentum().y() /GeV << "[GeV]" << ", z: "
415  << GetMomentum().z() /GeV << "[GeV]" << G4endl
416  << " Total Energy = " << GetTotalEnergy()/GeV << "[GeV]" << G4endl
417  << " Kinetic Energy = " << GetKineticEnergy() /GeV << "[GeV]" << G4endl
418  << " MagneticMoment [MeV/T]: " << GetMagneticMoment()/MeV*tesla << G4endl
419  << " ProperTime = " << GetProperTime() /ns << "[ns]" << G4endl;
420 
421  if (mode>0) {
422  if( theElectronOccupancy != 0) {
424  }
425  }
426  }
427 }
428 #else
430 {
431  return;
432 }
433 #endif
434 
437 {
438  static G4ThreadLocal G4double electronMass = 0.0;
439 
440  // check if electron exits and get the mass
441  if (electronMass<=0.0) {
443  if (electron == 0) {
444  G4Exception("G4DynamicParticle::GetElectronMass()","PART021",
445  FatalException,"G4DynamicParticle: G4Electron is not defined !!");
446  }
447  electronMass = electron->GetPDGMass();
448  }
449 
450  return electronMass;
451 }
static const double MeV
Definition: G4SIunits.hh:193
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
void SetMomentum(const G4ThreeVector &momentum)
G4double GetKineticEnergy() const
CLHEP::Hep3Vector G4ThreeVector
G4double GetTotalEnergy() const
G4double theDynamicalMagneticMoment
G4double GetProperTime() const
void DumpInfo(G4int mode=0) const
static G4bool IsIon(const G4ParticleDefinition *)
Definition: G4IonTable.cc:1061
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
G4double GetTotalMomentum() const
G4GLOB_DLL std::ostream G4cout
static const G4double EnergyMomentumRelationAllowance
G4double GetMass() const
const G4ThreeVector & GetMomentumDirection() const
G4double GetCharge() const
static const double GeV
Definition: G4SIunits.hh:196
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
G4double thePreAssignedDecayTime
G4double GetPDGSpin() const
G4ThreeVector thePolarization
#define G4endl
Definition: G4ios.hh:61
G4ThreadLocal G4Allocator< G4DynamicParticle > * pDynamicParticleAllocator
static const double keV
Definition: G4SIunits.hh:195
static const double tesla
Definition: G4SIunits.hh:247
G4double GetPDGMagneticMoment() const
double G4double
Definition: G4Types.hh:76
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
const G4ParticleDefinition * theParticleDefinition
static const double eplus
Definition: G4SIunits.hh:178
G4double GetPDGCharge() const
#define ns
Definition: xmlparse.cc:597
G4double GetMagneticMoment() const
G4DynamicParticle & operator=(const G4DynamicParticle &right)
G4ThreeVector GetMomentum() const
G4double GetElectronMass() const
CLHEP::HepLorentzVector G4LorentzVector