2// ********************************************************************
3// * License and Disclaimer *
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. *
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. *
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// ********************************************************************
26// G4DynamicParticle inline implementation
28// 17.08.1999 - H.Kurashige
29// --------------------------------------------------------------------
31extern G4PART_DLL G4Allocator<G4DynamicParticle>*& pDynamicParticleAllocator();
33// ------------------------
35// ------------------------
37inline void * G4DynamicParticle::operator new(size_t)
39 if (pDynamicParticleAllocator() == nullptr)
40 pDynamicParticleAllocator() = new G4Allocator<G4DynamicParticle>;
41 return pDynamicParticleAllocator()->MallocSingle();
44inline void G4DynamicParticle::operator delete(void * aDynamicParticle)
46 pDynamicParticleAllocator()
47 ->FreeSingle((G4DynamicParticle *) aDynamicParticle);
50// ------------------------
52// ------------------------
54inline const G4ElectronOccupancy*
55G4DynamicParticle::GetElectronOccupancy() const
57 return theElectronOccupancy;
60inline G4int G4DynamicParticle::GetTotalOccupancy() const
62 return (theElectronOccupancy) ? theElectronOccupancy->GetTotalOccupancy() : 0;
65inline G4int G4DynamicParticle::GetOccupancy(G4int orbit) const
67 return (theElectronOccupancy) ? theElectronOccupancy->GetOccupancy(orbit) : 0;
70inline void G4DynamicParticle::AddElectron(G4int orbit, G4int number)
72 if (theElectronOccupancy == nullptr) { AllocateElectronOccupancy(); }
73 if (theElectronOccupancy != nullptr)
75 G4int n = theElectronOccupancy->AddElectron(orbit, number);
76 theDynamicalCharge -= CLHEP::eplus * n;
77 theDynamicalMass += CLHEP::electron_mass_c2 * n;
81inline void G4DynamicParticle::RemoveElectron(G4int orbit, G4int number)
83 if (theElectronOccupancy == nullptr) { AllocateElectronOccupancy(); }
84 if (theElectronOccupancy != nullptr)
86 G4int n = theElectronOccupancy->RemoveElectron(orbit, number);
87 theDynamicalCharge += CLHEP::eplus * n;
88 theDynamicalMass -= CLHEP::electron_mass_c2 * n;
92inline G4double G4DynamicParticle::GetCharge() const
94 return theDynamicalCharge;
97inline void G4DynamicParticle::SetCharge(G4double newCharge)
99 theDynamicalCharge = newCharge;
102inline void G4DynamicParticle::SetCharge(G4int newCharge)
104 theDynamicalCharge = newCharge*CLHEP::eplus;
107inline G4double G4DynamicParticle::GetMass() const
109 return theDynamicalMass;
112inline void G4DynamicParticle::SetMass(G4double newMass)
114 if(theDynamicalMass != newMass)
116 theDynamicalMass = std::max(newMass, 0.0);
121inline G4double G4DynamicParticle::GetSpin() const
123 return theDynamicalSpin;
126inline void G4DynamicParticle::SetSpin(G4double spin)
128 theDynamicalSpin = spin;
131inline void G4DynamicParticle::SetSpin(G4int spinInUnitOfHalfInteger)
133 theDynamicalSpin = spinInUnitOfHalfInteger * 0.5;
136inline G4double G4DynamicParticle::GetMagneticMoment() const
138 return theDynamicalMagneticMoment;
141inline void G4DynamicParticle::SetMagneticMoment(G4double magneticMoment)
143 theDynamicalMagneticMoment = magneticMoment;
146inline const G4ThreeVector& G4DynamicParticle::GetMomentumDirection() const
148 return theMomentumDirection;
151inline G4ThreeVector G4DynamicParticle::GetMomentum() const
153 G4double pModule = std::sqrt(theKineticEnergy*theKineticEnergy
154 + 2*theKineticEnergy*theDynamicalMass);
155 G4ThreeVector pMomentum(theMomentumDirection.x()*pModule,
156 theMomentumDirection.y()*pModule,
157 theMomentumDirection.z()*pModule);
161inline G4LorentzVector G4DynamicParticle::Get4Momentum() const
163 const G4double mass = theDynamicalMass;
164 const G4double energy = theKineticEnergy;
165 const G4double momentum = std::sqrt(energy*energy+2.0*mass*energy);
166 G4LorentzVector p4( theMomentumDirection.x()*momentum,
167 theMomentumDirection.y()*momentum,
168 theMomentumDirection.z()*momentum,
173inline G4double G4DynamicParticle::GetTotalMomentum() const
175 // The momentum is returned in energy equivalent
177 return std::sqrt((theKineticEnergy + 2.*theDynamicalMass)* theKineticEnergy);
180inline G4ParticleDefinition* G4DynamicParticle::GetDefinition() const
182 return const_cast<G4ParticleDefinition*>(theParticleDefinition);
185inline const G4ParticleDefinition*
186G4DynamicParticle::GetParticleDefinition() const
188 return theParticleDefinition;
191inline const G4ThreeVector& G4DynamicParticle::GetPolarization() const
193 return thePolarization;
196inline G4double G4DynamicParticle::GetProperTime() const
198 return theProperTime;
201inline G4double G4DynamicParticle::GetTotalEnergy() const
203 return (theKineticEnergy+theDynamicalMass);
206inline G4double G4DynamicParticle::GetKineticEnergy() const
208 return theKineticEnergy;
211inline G4double G4DynamicParticle::GetLogKineticEnergy() const
213 if (theLogKineticEnergy == DBL_MAX)
215 theLogKineticEnergy = (theKineticEnergy > 0.)
216 ? G4Log(theKineticEnergy) : LOG_EKIN_MIN;
218 return theLogKineticEnergy;
222G4DynamicParticle::SetMomentumDirection(const G4ThreeVector& aDirection)
224 theMomentumDirection = aDirection;
228G4DynamicParticle::SetMomentumDirection(G4double px, G4double py, G4double pz)
230 theMomentumDirection.setX(px);
231 theMomentumDirection.setY(py);
232 theMomentumDirection.setZ(pz);
235inline void G4DynamicParticle::SetPolarization(const G4ThreeVector& vp)
237 thePolarization = vp;
241G4DynamicParticle::SetPolarization(G4double polX, G4double polY, G4double polZ)
243 thePolarization.setX(polX);
244 thePolarization.setY(polY);
245 thePolarization.setZ(polZ);
248inline void G4DynamicParticle::SetKineticEnergy(G4double aEnergy)
250 if(aEnergy != theKineticEnergy) {
251 theLogKineticEnergy = DBL_MAX;
252 theKineticEnergy = aEnergy;
257inline void G4DynamicParticle::SetProperTime(G4double atime)
259 theProperTime = atime;
262inline const G4DecayProducts*
263G4DynamicParticle::GetPreAssignedDecayProducts() const
265 return thePreAssignedDecayProducts;
269G4DynamicParticle::SetPreAssignedDecayProducts(G4DecayProducts* aDecayProducts)
271 thePreAssignedDecayProducts = aDecayProducts;
274inline G4double G4DynamicParticle::GetPreAssignedDecayProperTime() const
276 return thePreAssignedDecayTime;
279inline void G4DynamicParticle::SetPreAssignedDecayProperTime(G4double aTime)
281 thePreAssignedDecayTime = aTime;
284inline void G4DynamicParticle::SetVerboseLevel(G4int value)
286 verboseLevel = value;
289inline G4int G4DynamicParticle::GetVerboseLevel() const
294inline void G4DynamicParticle::SetPrimaryParticle(G4PrimaryParticle* p)
299inline G4PrimaryParticle* G4DynamicParticle::GetPrimaryParticle() const
301 return primaryParticle;
304inline G4int G4DynamicParticle::GetPDGcode() const
306 G4int code = theParticleDefinition->GetPDGEncoding();
307 return (code == 0) ? thePDGcode : code;
310inline void G4DynamicParticle::SetPDGcode(G4int c)
315inline void G4DynamicParticle::ComputeBeta() const
317 // ultra relativistic particles and particles with mass zero
321 if(theDynamicalMass > 0.0 && theKineticEnergy < 1000*theDynamicalMass)
323 const G4double T = theKineticEnergy/theDynamicalMass;
324 theBeta = std::sqrt(T*(T+2.))/(T+1.0);
328inline G4double G4DynamicParticle::GetBeta() const
330 if(theBeta < 0.0) { ComputeBeta(); }