Geant4-11
G4DynamicParticle.icc
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// G4DynamicParticle inline implementation
27//
28// 17.08.1999 - H.Kurashige
29// --------------------------------------------------------------------
30
31extern G4PART_DLL G4Allocator<G4DynamicParticle>*& pDynamicParticleAllocator();
32
33// ------------------------
34// Inlined operators
35// ------------------------
36
37inline void * G4DynamicParticle::operator new(size_t)
38{
39 if (pDynamicParticleAllocator() == nullptr)
40 pDynamicParticleAllocator() = new G4Allocator<G4DynamicParticle>;
41 return pDynamicParticleAllocator()->MallocSingle();
42}
43
44inline void G4DynamicParticle::operator delete(void * aDynamicParticle)
45{
46 pDynamicParticleAllocator()
47 ->FreeSingle((G4DynamicParticle *) aDynamicParticle);
48}
49
50// ------------------------
51// Inlined functions
52// ------------------------
53
54inline const G4ElectronOccupancy*
55G4DynamicParticle::GetElectronOccupancy() const
56{
57 return theElectronOccupancy;
58}
59
60inline G4int G4DynamicParticle::GetTotalOccupancy() const
61{
62 return (theElectronOccupancy) ? theElectronOccupancy->GetTotalOccupancy() : 0;
63}
64
65inline G4int G4DynamicParticle::GetOccupancy(G4int orbit) const
66{
67 return (theElectronOccupancy) ? theElectronOccupancy->GetOccupancy(orbit) : 0;
68}
69
70inline void G4DynamicParticle::AddElectron(G4int orbit, G4int number)
71{
72 if (theElectronOccupancy == nullptr) { AllocateElectronOccupancy(); }
73 if (theElectronOccupancy != nullptr)
74 {
75 G4int n = theElectronOccupancy->AddElectron(orbit, number);
76 theDynamicalCharge -= CLHEP::eplus * n;
77 theDynamicalMass += CLHEP::electron_mass_c2 * n;
78 }
79}
80
81inline void G4DynamicParticle::RemoveElectron(G4int orbit, G4int number)
82{
83 if (theElectronOccupancy == nullptr) { AllocateElectronOccupancy(); }
84 if (theElectronOccupancy != nullptr)
85 {
86 G4int n = theElectronOccupancy->RemoveElectron(orbit, number);
87 theDynamicalCharge += CLHEP::eplus * n;
88 theDynamicalMass -= CLHEP::electron_mass_c2 * n;
89 }
90}
91
92inline G4double G4DynamicParticle::GetCharge() const
93{
94 return theDynamicalCharge;
95}
96
97inline void G4DynamicParticle::SetCharge(G4double newCharge)
98{
99 theDynamicalCharge = newCharge;
100}
101
102inline void G4DynamicParticle::SetCharge(G4int newCharge)
103{
104 theDynamicalCharge = newCharge*CLHEP::eplus;
105}
106
107inline G4double G4DynamicParticle::GetMass() const
108{
109 return theDynamicalMass;
110}
111
112inline void G4DynamicParticle::SetMass(G4double newMass)
113{
114 if(theDynamicalMass != newMass)
115 {
116 theDynamicalMass = std::max(newMass, 0.0);
117 theBeta = -1.0;
118 }
119}
120
121inline G4double G4DynamicParticle::GetSpin() const
122{
123 return theDynamicalSpin;
124}
125
126inline void G4DynamicParticle::SetSpin(G4double spin)
127{
128 theDynamicalSpin = spin;
129}
130
131inline void G4DynamicParticle::SetSpin(G4int spinInUnitOfHalfInteger)
132{
133 theDynamicalSpin = spinInUnitOfHalfInteger * 0.5;
134}
135
136inline G4double G4DynamicParticle::GetMagneticMoment() const
137{
138 return theDynamicalMagneticMoment;
139}
140
141inline void G4DynamicParticle::SetMagneticMoment(G4double magneticMoment)
142{
143 theDynamicalMagneticMoment = magneticMoment;
144}
145
146inline const G4ThreeVector& G4DynamicParticle::GetMomentumDirection() const
147{
148 return theMomentumDirection;
149}
150
151inline G4ThreeVector G4DynamicParticle::GetMomentum() const
152{
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);
158 return pMomentum;
159}
160
161inline G4LorentzVector G4DynamicParticle::Get4Momentum() const
162{
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,
169 energy+mass );
170 return p4;
171}
172
173inline G4double G4DynamicParticle::GetTotalMomentum() const
174{
175 // The momentum is returned in energy equivalent
176 //
177 return std::sqrt((theKineticEnergy + 2.*theDynamicalMass)* theKineticEnergy);
178}
179
180inline G4ParticleDefinition* G4DynamicParticle::GetDefinition() const
181{
182 return const_cast<G4ParticleDefinition*>(theParticleDefinition);
183}
184
185inline const G4ParticleDefinition*
186G4DynamicParticle::GetParticleDefinition() const
187{
188 return theParticleDefinition;
189}
190
191inline const G4ThreeVector& G4DynamicParticle::GetPolarization() const
192{
193 return thePolarization;
194}
195
196inline G4double G4DynamicParticle::GetProperTime() const
197{
198 return theProperTime;
199}
200
201inline G4double G4DynamicParticle::GetTotalEnergy() const
202{
203 return (theKineticEnergy+theDynamicalMass);
204}
205
206inline G4double G4DynamicParticle::GetKineticEnergy() const
207{
208 return theKineticEnergy;
209}
210
211inline G4double G4DynamicParticle::GetLogKineticEnergy() const
212{
213 if (theLogKineticEnergy == DBL_MAX)
214 {
215 theLogKineticEnergy = (theKineticEnergy > 0.)
216 ? G4Log(theKineticEnergy) : LOG_EKIN_MIN;
217 }
218 return theLogKineticEnergy;
219}
220
221inline void
222G4DynamicParticle::SetMomentumDirection(const G4ThreeVector& aDirection)
223{
224 theMomentumDirection = aDirection;
225}
226
227inline void
228G4DynamicParticle::SetMomentumDirection(G4double px, G4double py, G4double pz)
229{
230 theMomentumDirection.setX(px);
231 theMomentumDirection.setY(py);
232 theMomentumDirection.setZ(pz);
233}
234
235inline void G4DynamicParticle::SetPolarization(const G4ThreeVector& vp)
236{
237 thePolarization = vp;
238}
239
240inline void
241G4DynamicParticle::SetPolarization(G4double polX, G4double polY, G4double polZ)
242{
243 thePolarization.setX(polX);
244 thePolarization.setY(polY);
245 thePolarization.setZ(polZ);
246}
247
248inline void G4DynamicParticle::SetKineticEnergy(G4double aEnergy)
249{
250 if(aEnergy != theKineticEnergy) {
251 theLogKineticEnergy = DBL_MAX;
252 theKineticEnergy = aEnergy;
253 theBeta = -1.0;
254 }
255}
256
257inline void G4DynamicParticle::SetProperTime(G4double atime)
258{
259 theProperTime = atime;
260}
261
262inline const G4DecayProducts*
263G4DynamicParticle::GetPreAssignedDecayProducts() const
264{
265 return thePreAssignedDecayProducts;
266}
267
268inline void
269G4DynamicParticle::SetPreAssignedDecayProducts(G4DecayProducts* aDecayProducts)
270{
271 thePreAssignedDecayProducts = aDecayProducts;
272}
273
274inline G4double G4DynamicParticle::GetPreAssignedDecayProperTime() const
275{
276 return thePreAssignedDecayTime;
277}
278
279inline void G4DynamicParticle::SetPreAssignedDecayProperTime(G4double aTime)
280{
281 thePreAssignedDecayTime = aTime;
282}
283
284inline void G4DynamicParticle::SetVerboseLevel(G4int value)
285{
286 verboseLevel = value;
287}
288
289inline G4int G4DynamicParticle::GetVerboseLevel() const
290{
291 return verboseLevel;
292}
293
294inline void G4DynamicParticle::SetPrimaryParticle(G4PrimaryParticle* p)
295{
296 primaryParticle = p;
297}
298
299inline G4PrimaryParticle* G4DynamicParticle::GetPrimaryParticle() const
300{
301 return primaryParticle;
302}
303
304inline G4int G4DynamicParticle::GetPDGcode() const
305{
306 G4int code = theParticleDefinition->GetPDGEncoding();
307 return (code == 0) ? thePDGcode : code;
308}
309
310inline void G4DynamicParticle::SetPDGcode(G4int c)
311{
312 thePDGcode = c;
313}
314
315inline void G4DynamicParticle::ComputeBeta() const
316{
317 // ultra relativistic particles and particles with mass zero
318 theBeta = 1.0;
319
320 // other particles
321 if(theDynamicalMass > 0.0 && theKineticEnergy < 1000*theDynamicalMass)
322 {
323 const G4double T = theKineticEnergy/theDynamicalMass;
324 theBeta = std::sqrt(T*(T+2.))/(T+1.0);
325 }
326}
327
328inline G4double G4DynamicParticle::GetBeta() const
329{
330 if(theBeta < 0.0) { ComputeBeta(); }
331 return theBeta;
332}