Geant4  10.00.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 72152 2013-07-11 12:49:58Z 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& aParticleMomentum):
123  theParticleDefinition(aParticleDefinition),
124  theKineticEnergy(0.0),
125  theProperTime(0.0),
126  theDynamicalMass(aParticleDefinition->GetPDGMass()),
127  theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
128  theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
129  theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
130  theElectronOccupancy(0),
131  thePreAssignedDecayProducts(0),
132  thePreAssignedDecayTime(-1.0),
133  verboseLevel(1),
134  primaryParticle(0),
135  thePDGcode(0)
136 {
137  SetMomentum(aParticleMomentum); // 3-dim momentum is given
138 }
139 
142  const G4LorentzVector &aParticleMomentum):
143  theParticleDefinition(aParticleDefinition),
144  theKineticEnergy(0.0),
145  theProperTime(0.0),
146  theDynamicalMass(aParticleDefinition->GetPDGMass()),
147  theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
148  theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
149  theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
150  theElectronOccupancy(0),
151  thePreAssignedDecayProducts(0),
152  thePreAssignedDecayTime(-1.0),
153  verboseLevel(1),
154  primaryParticle(0),
155  thePDGcode(0)
156 {
157  Set4Momentum(aParticleMomentum); // 4-momentum vector (Lorentz vector) is given
158 }
159 
161  G4double totalEnergy,
162  const G4ThreeVector &aParticleMomentum):
163  theParticleDefinition(aParticleDefinition),
164  theKineticEnergy(0.0),
165  theProperTime(0.0),
166  theDynamicalMass(aParticleDefinition->GetPDGMass()),
167  theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
168  theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
169  theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
170  theElectronOccupancy(0),
171  thePreAssignedDecayProducts(0),
172  thePreAssignedDecayTime(-1.0),
173  verboseLevel(1),
174  primaryParticle(0),
175  thePDGcode(0)
176 {
177  // total energy and 3-dim momentum are given
178  G4double pModule2 = aParticleMomentum.mag2();
179  if (pModule2>0.0) {
180  G4double mass2 = totalEnergy*totalEnergy - pModule2;
182  theDynamicalMass = 0.;
183  SetMomentumDirection(aParticleMomentum.unit());
184  SetKineticEnergy(totalEnergy);
185  } else {
186  theDynamicalMass = std::sqrt(mass2);
187  SetMomentum(aParticleMomentum);
188  }
189  } else {
190  SetMomentumDirection(1.0,0.0,0.0);
191  SetKineticEnergy(0.0);
192  }
193 }
194 
197  theMomentumDirection(right.theMomentumDirection),
198  theParticleDefinition(right.theParticleDefinition),
199  thePolarization(right.thePolarization),
200  theKineticEnergy(right.theKineticEnergy),
201  theProperTime(0.0),
202  theDynamicalMass(right.theDynamicalMass),
203  theDynamicalCharge(right.theDynamicalCharge),
204  theDynamicalSpin(right.theDynamicalSpin),
205  theDynamicalMagneticMoment(right.theDynamicalMagneticMoment),
206  theElectronOccupancy(0),
207  thePreAssignedDecayProducts(0), // Do not copy preassignedDecayProducts
208  thePreAssignedDecayTime(-1.0),
209  verboseLevel(right.verboseLevel),
210  primaryParticle(right.primaryParticle),
211  thePDGcode(right.thePDGcode)
212 {
213  if (right.theElectronOccupancy != 0) {
216  }
217 }
218 
220 // -- destructor ----
223 {
224  // delete thePreAssignedDecayProducts
227 
230 }
231 
232 
234 // -- operators ----
237 {
238  if (this != &right) {
244 
249 
251  if (right.theElectronOccupancy != 0){
254  } else {
256  }
257 
258  // thePreAssignedDecayProducts must not be copied.
261 
262  verboseLevel = right.verboseLevel;
263 
264  // Primary particle information must be preserved
265  //*** primaryParticle = right.primaryParticle;
266 
267  thePDGcode = right.thePDGcode;
268  }
269  return *this;
270 }
271 
274 {
275  // remove preassigned decay
276  if (thePreAssignedDecayProducts != 0) {
277 #ifdef G4VERBOSE
278  if (verboseLevel>0) {
279  G4cout << " G4DynamicParticle::SetDefinition()::"
280  << "!!! Pre-assigned decay products is attached !!!! " << G4endl;
281  G4cout << "!!! New Definition is " << aParticleDefinition->GetParticleName()
282  << " !!! " << G4endl;
283  G4cout << "!!! Pre-assigned decay products will be deleted !!!! " << G4endl;
284  }
285 #endif
287  }
289 
290  theParticleDefinition = aParticleDefinition;
291 
292  // set Dynamic mass/chrge
297 
298  // Set electron orbits
301  //AllocateElectronOccupancy();
302 
303 }
304 
307 {
308  return (this == (G4DynamicParticle *) &right);
309 }
310 
313 {
314  return (this != (G4DynamicParticle *) &right);
315 }
316 
317 
318 
320 // -- AllocateElectronOccupancy --
323 {
324  const G4ParticleDefinition* particle = GetDefinition();
325 
326  if (G4IonTable::IsIon(particle)) {
327  // Only ions can have ElectronOccupancy
329 
330  } else {
332 
333  }
334 }
335 
337 // -- methods for setting Energy/Momentum --
340 {
341  G4double pModule2 = momentum.mag2();
342  if (pModule2>0.0) {
343  G4double mass = theDynamicalMass;
344  SetMomentumDirection(momentum.unit());
345  SetKineticEnergy(std::sqrt(pModule2 + mass*mass)-mass);
346  } else {
347  SetMomentumDirection(1.0,0.0,0.0);
348  SetKineticEnergy(0.0);
349  }
350 }
351 
354 {
355  G4double pModule2 = momentum.vect().mag2();
356  if (pModule2>0.0) {
357  SetMomentumDirection(momentum.vect().unit());
358  G4double totalenergy = momentum.t();
359  G4double mass2 = totalenergy*totalenergy - pModule2;
361  theDynamicalMass = 0.;
362  SetKineticEnergy(totalenergy);
363  } else {
364  theDynamicalMass = std::sqrt(mass2);
365  SetKineticEnergy(totalenergy-theDynamicalMass);
366  }
367  } else {
368  SetMomentumDirection(1.0,0.0,0.0);
369  SetKineticEnergy(0.0);
370  }
371 }
372 
373 
375 // --- Dump Information --
377 #ifdef G4VERBOSE
378 void G4DynamicParticle::DumpInfo(G4int mode) const
379 {
380  if (theParticleDefinition == 0) {
381  G4cout << " G4DynamicParticle::DumpInfo():: !!!Particle type not defined !!!! " << G4endl;
382  } else {
383  G4cout << " Particle type - " << theParticleDefinition->GetParticleName() << G4endl
384  << " mass: " << GetMass()/GeV << "[GeV]" <<G4endl
385  << " charge: " << GetCharge()/eplus << "[e]" <<G4endl
386  << " Direction x: " << GetMomentumDirection().x() << ", y: "
387  << GetMomentumDirection().y() << ", z: "
388  << GetMomentumDirection().z() << G4endl
389  << " Total Momentum = " << GetTotalMomentum() /GeV << "[GeV]" << G4endl
390  << " Momentum: " << GetMomentum().x() /GeV << "[GeV]" << ", y: "
391  << GetMomentum().y() /GeV << "[GeV]" << ", z: "
392  << GetMomentum().z() /GeV << "[GeV]" << G4endl
393  << " Total Energy = " << GetTotalEnergy()/GeV << "[GeV]" << G4endl
394  << " Kinetic Energy = " << GetKineticEnergy() /GeV << "[GeV]" << G4endl
395  << " MagneticMoment [MeV/T]: " << GetMagneticMoment()/MeV*tesla << G4endl
396  << " ProperTime = " << GetProperTime() /ns << "[ns]" << G4endl;
397 
398  if (mode>0) {
399  if( theElectronOccupancy != 0) {
401  }
402  }
403  }
404 }
405 #else
407 {
408  return;
409 }
410 #endif
411 
414 {
415  static G4ThreadLocal G4double electronMass = 0.0;
416 
417  // check if electron exits and get the mass
418  if (electronMass<=0.0) {
420  if (electron == 0) {
421  G4Exception("G4DynamicParticle::GetElectronMass()","PART021",
422  FatalException,"G4DynamicParticle: G4Electron is not defined !!");
423  }
424  electronMass = electron->GetPDGMass();
425  }
426 
427  return electronMass;
428 }
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:1044
void SetMomentumDirection(const G4ThreeVector &aDirection)
G4ParticleDefinition * GetDefinition() const
#define G4ThreadLocal
Definition: tls.hh:52
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