Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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$
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"
66#include "G4SystemOfUnits.hh"
67#include "G4DecayProducts.hh"
68#include "G4LorentzVector.hh"
70#include "G4ParticleTable.hh"
71#include "G4IonTable.hh"
72#include "G4PrimaryParticle.hh"
73
75
76static const G4double EnergyMomentumRelationAllowance = keV;
77
78////////////////////
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// -- constructors ----
97////////////////////
99 const G4ThreeVector& aMomentumDirection,
100 G4double aKineticEnergy):
101 theMomentumDirection(aMomentumDirection),
102 theParticleDefinition(aParticleDefinition),
103 theKineticEnergy(aKineticEnergy),
104 theProperTime(0.0),
105 theDynamicalMass(aParticleDefinition->GetPDGMass()),
106 theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
107 theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
108 theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
109 theElectronOccupancy(0),
110 thePreAssignedDecayProducts(0),
111 thePreAssignedDecayTime(-1.0),
112 verboseLevel(1),
113 primaryParticle(0),
114 thePDGcode(0) {}
115
116////////////////////
118 const G4ThreeVector& aParticleMomentum):
119 theParticleDefinition(aParticleDefinition),
120 theKineticEnergy(0.0),
121 theProperTime(0.0),
122 theDynamicalMass(aParticleDefinition->GetPDGMass()),
123 theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
124 theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
125 theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
126 theElectronOccupancy(0),
127 thePreAssignedDecayProducts(0),
128 thePreAssignedDecayTime(-1.0),
129 verboseLevel(1),
130 primaryParticle(0),
131 thePDGcode(0)
132{
133 // 3-dim momentum is given
134 SetMomentum(aParticleMomentum);
135}
136
137////////////////////
139 const G4LorentzVector &aParticleMomentum):
140 theParticleDefinition(aParticleDefinition),
141 theKineticEnergy(0.0),
142 theProperTime(0.0),
143 theDynamicalMass(aParticleDefinition->GetPDGMass()),
144 theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
145 theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
146 theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
147 theElectronOccupancy(0),
148 thePreAssignedDecayProducts(0),
149 thePreAssignedDecayTime(-1.0),
150 verboseLevel(1),
151 primaryParticle(0),
152 thePDGcode(0)
153{
154 // 4-momentum vector (Lorentz vecotr) is given
155 Set4Momentum(aParticleMomentum);
156}
157
159 G4double totalEnergy,
160 const G4ThreeVector &aParticleMomentum):
161 theParticleDefinition(aParticleDefinition),
162 theKineticEnergy(0.0),
163 theProperTime(0.0),
164 theDynamicalMass(aParticleDefinition->GetPDGMass()),
165 theDynamicalCharge(aParticleDefinition->GetPDGCharge()),
166 theDynamicalSpin(aParticleDefinition->GetPDGSpin()),
167 theDynamicalMagneticMoment(aParticleDefinition->GetPDGMagneticMoment()),
168 theElectronOccupancy(0),
169 thePreAssignedDecayProducts(0),
170 thePreAssignedDecayTime(-1.0),
171 verboseLevel(1),
172 primaryParticle(0),
173 thePDGcode(0)
174{
175 // total energy and 3-dim momentum are given
176 G4double pModule2 = aParticleMomentum.mag2();
177 if (pModule2>0.0) {
178 G4double mass2 = totalEnergy*totalEnergy - pModule2;
179 if(mass2 < EnergyMomentumRelationAllowance*EnergyMomentumRelationAllowance) {
180 theDynamicalMass = 0.;
181 SetMomentumDirection(aParticleMomentum.unit());
182 SetKineticEnergy(totalEnergy);
183 } else {
184 theDynamicalMass = std::sqrt(mass2);
185 SetMomentum(aParticleMomentum);
186 }
187 } else {
188 SetMomentumDirection(1.0,0.0,0.0);
189 SetKineticEnergy(0.0);
190 }
191}
192
193////////////////////
195 theMomentumDirection(right.theMomentumDirection),
196 theParticleDefinition(right.theParticleDefinition),
197 thePolarization(right.thePolarization),
198 theKineticEnergy(right.theKineticEnergy),
199 theProperTime(0.0),
200 theDynamicalMass(right.theDynamicalMass),
201 theDynamicalCharge(right.theDynamicalCharge),
202 theDynamicalSpin(right.theDynamicalSpin),
203 theDynamicalMagneticMoment(right.theDynamicalMagneticMoment),
204 theElectronOccupancy(0),
205 thePreAssignedDecayProducts(0), // Do not copy preassignedDecayProducts
206 thePreAssignedDecayTime(-1.0),
207 verboseLevel(right.verboseLevel),
208 primaryParticle(right.primaryParticle),
209 thePDGcode(right.thePDGcode)
210{
211 if (right.theElectronOccupancy != 0) {
214 }
215}
216
217////////////////////
218// -- destructor ----
219////////////////////
221
222 // delete thePreAssignedDecayProducts
225
228}
229
230
231////////////////////
232// -- operators ----
233////////////////////
235{
236 if (this != &right) {
242
247
249 if (right.theElectronOccupancy != 0){
252 } else {
254 }
255
256 // thePreAssignedDecayProducts must not be copied.
259
261
262 // Primary particle information must be preserved
263 //*** primaryParticle = right.primaryParticle;
264
265 thePDGcode = right.thePDGcode;
266 }
267 return *this;
268}
269
270////////////////////
272{
273 // remove preassigned decay
275#ifdef G4VERBOSE
276 if (verboseLevel>0) {
277 G4cerr << " G4DynamicParticle::SetDefinition()::"
278 << "!!! Pre-assigned decay products is attached !!!! " << G4endl;
279 G4cerr << "!!! New Definition is " << aParticleDefinition->GetParticleName()
280 << " !!! " << G4endl;
281 G4cerr << "!!! Pre-assigned decay products will be deleted !!!! " << G4endl;
282 }
283#endif
285 }
287
288 theParticleDefinition = aParticleDefinition;
289
290 // set Dynamic mass/chrge
295
296 // Set electron orbits
299 //AllocateElectronOccupancy();
300
301}
302
303////////////////////
305{
306 return (this == (G4DynamicParticle *) &right);
307}
308
309////////////////////
311{
312 return (this != (G4DynamicParticle *) &right);
313}
314
315
316
317////////////////////
318// -- AllocateElectronOccupancy --
319////////////////////
321{
322 const G4ParticleDefinition* particle = GetDefinition();
323
324 if (G4IonTable::IsIon(particle)) {
325 // Only ions can have ElectronOccupancy
327
328 } else {
330
331 }
332}
333
334////////////////////
335// -- methods for setting Energy/Momentum --
336////////////////////
338{
339 G4double pModule2 = momentum.mag2();
340 if (pModule2>0.0) {
342 SetMomentumDirection(momentum.unit());
343 SetKineticEnergy(std::sqrt(pModule2 + mass*mass)-mass);
344 } else {
345 SetMomentumDirection(1.0,0.0,0.0);
346 SetKineticEnergy(0.0);
347 }
348}
349
350////////////////////
352{
353 G4double pModule2 = momentum.vect().mag2();
354 if (pModule2>0.0) {
355 SetMomentumDirection(momentum.vect().unit());
356 G4double totalenergy = momentum.t();
357 G4double mass2 = totalenergy*totalenergy - pModule2;
358 if(mass2 < EnergyMomentumRelationAllowance*EnergyMomentumRelationAllowance) {
359 theDynamicalMass = 0.;
360 SetKineticEnergy(totalenergy);
361 } else {
362 theDynamicalMass = std::sqrt(mass2);
364 }
365 } else {
366 SetMomentumDirection(1.0,0.0,0.0);
367 SetKineticEnergy(0.0);
368 }
369}
370
371
372////////////////////
373// --- Dump Information --
374////////////////////
375#ifdef G4VERBOSE
376void G4DynamicParticle::DumpInfo(G4int mode) const
377{
378 if (theParticleDefinition == 0) {
379 G4cout << " G4DynamicParticle::DumpInfo():: !!!Particle type not defined !!!! " << G4endl;
380 } else {
381 G4cout << " Particle type - " << theParticleDefinition->GetParticleName() << G4endl
382 << " mass: " << GetMass()/GeV << "[GeV]" <<G4endl
383 << " charge: " << GetCharge()/eplus << "[e]" <<G4endl
384 << " Direction x: " << GetMomentumDirection().x() << ", y: "
385 << GetMomentumDirection().y() << ", z: "
387 << " Total Momentum = " << GetTotalMomentum() /GeV << "[GeV]" << G4endl
388 << " Momentum: " << GetMomentum().x() /GeV << "[GeV]" << ", y: "
389 << GetMomentum().y() /GeV << "[GeV]" << ", z: "
390 << GetMomentum().z() /GeV << "[GeV]" << G4endl
391 << " Total Energy = " << GetTotalEnergy()/GeV << "[GeV]" << G4endl
392 << " Kinetic Energy = " << GetKineticEnergy() /GeV << "[GeV]" << G4endl
393 << " MagneticMoment [MeV/T]: " << GetMagneticMoment()/MeV*tesla << G4endl
394 << " ProperTime = " << GetProperTime() /ns << "[ns]" << G4endl;
395
396 if (mode>0) {
397 if( theElectronOccupancy != 0) {
399 }
400 }
401 }
402}
403#else
405{
406 return;
407}
408#endif
409
410////////////////////////
412{
413 static G4double electronMass = 0.0;
414
415 // check if electron exits and get the mass
416 if (electronMass<=0.0) {
418 if (electron == 0) {
419 G4Exception("G4DynamicParticle::GetElectronMass()","PART021",
420 FatalException,"G4DynamicParticle: G4Electron is not defined !!");
421 }
422 electronMass = electron->GetPDGMass();
423 }
424
425 return electronMass;
426}
G4Allocator< G4DynamicParticle > aDynamicParticleAllocator
@ FatalException
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
double z() const
Hep3Vector unit() const
double x() const
double mag2() const
double y() const
Hep3Vector vect() const
G4double GetMass() const
G4double thePreAssignedDecayTime
G4ThreeVector thePolarization
void SetMomentumDirection(const G4ThreeVector &aDirection)
void DumpInfo(G4int mode=0) const
const G4ThreeVector & GetMomentumDirection() const
G4double GetCharge() const
void SetDefinition(const G4ParticleDefinition *aParticleDefinition)
const G4ParticleDefinition * theParticleDefinition
G4int operator==(const G4DynamicParticle &right) const
G4int operator!=(const G4DynamicParticle &right) const
G4ParticleDefinition * GetDefinition() const
G4double GetKineticEnergy() const
G4double GetTotalEnergy() const
G4ElectronOccupancy * theElectronOccupancy
void Set4Momentum(const G4LorentzVector &momentum)
void SetMomentum(const G4ThreeVector &momentum)
G4DecayProducts * thePreAssignedDecayProducts
G4double GetProperTime() const
G4double theDynamicalMagneticMoment
G4ThreeVector theMomentumDirection
G4ThreeVector GetMomentum() const
G4DynamicParticle & operator=(const G4DynamicParticle &right)
G4double GetMagneticMoment() const
G4double GetTotalMomentum() const
G4double GetElectronMass() const
void SetKineticEnergy(G4double aEnergy)
static G4bool IsIon(const G4ParticleDefinition *)
Definition: G4IonTable.cc:594
G4double GetPDGMagneticMoment() const
G4double GetPDGCharge() const
const G4String & GetParticleName() const
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define ns
Definition: xmlparse.cc:597