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 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

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