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 // ********************************************************************
27 // $Id: G4DynamicParticle.icc 98352 2016-07-08 08:21:00Z gcosmo $
30 // ------------------------------------------------------------
31 // GEANT 4 class header file
33 // History: first implementation, based on object model of
34 // 17 AUg. 1999 H.Kurashige
35 // ------------------------------------------------------------
36 extern G4PART_DLL G4ThreadLocal G4Allocator<G4DynamicParticle> *pDynamicParticleAllocator;
38 // ------------------------
40 // ------------------------
42 inline void * G4DynamicParticle::operator new(size_t)
44 if (!pDynamicParticleAllocator) pDynamicParticleAllocator =
45 new G4Allocator<G4DynamicParticle>;
46 return pDynamicParticleAllocator->MallocSingle();
49 inline void G4DynamicParticle::operator delete(void * aDynamicParticle)
51 pDynamicParticleAllocator->FreeSingle((G4DynamicParticle *) aDynamicParticle);
54 // ------------------------
56 // ------------------------
58 inline const G4ElectronOccupancy* G4DynamicParticle::GetElectronOccupancy() const
60 return theElectronOccupancy;
63 inline G4int G4DynamicParticle::GetTotalOccupancy() const
66 if ( theElectronOccupancy != 0) {
67 value = theElectronOccupancy->GetTotalOccupancy();
72 inline G4int G4DynamicParticle::GetOccupancy(G4int orbit) const
75 if ( theElectronOccupancy != 0) {
76 value = theElectronOccupancy->GetOccupancy(orbit);
81 inline void G4DynamicParticle::AddElectron(G4int orbit, G4int number )
83 if ( theElectronOccupancy == 0) AllocateElectronOccupancy();
84 if ( theElectronOccupancy != 0) {
85 G4int n = theElectronOccupancy->AddElectron(orbit, number );
86 theDynamicalCharge -= CLHEP::eplus * n;
87 theDynamicalMass += GetElectronMass() * n;
91 inline void G4DynamicParticle::RemoveElectron(G4int orbit, G4int number)
93 if ( theElectronOccupancy == 0) AllocateElectronOccupancy();
94 if ( theElectronOccupancy != 0) {
95 G4int n = theElectronOccupancy->RemoveElectron(orbit, number );
96 theDynamicalCharge += CLHEP::eplus * n;
97 theDynamicalMass -= GetElectronMass() * n;
101 inline G4double G4DynamicParticle::GetCharge() const
103 return theDynamicalCharge;
106 inline void G4DynamicParticle::SetCharge(G4double newCharge)
108 theDynamicalCharge = newCharge;
111 inline void G4DynamicParticle::SetCharge(G4int newCharge)
113 theDynamicalCharge = newCharge*CLHEP::eplus;
116 inline G4double G4DynamicParticle::GetMass() const
118 return theDynamicalMass;
122 inline G4double G4DynamicParticle::GetSpin() const
124 return theDynamicalSpin;
127 inline void G4DynamicParticle::SetSpin(G4double spin)
129 theDynamicalSpin = spin;
132 inline void G4DynamicParticle::SetSpin(G4int spinInUnitOfHalfInteger)
134 theDynamicalSpin = spinInUnitOfHalfInteger * 0.5;
137 inline G4double G4DynamicParticle::GetMagneticMoment() const
139 return theDynamicalMagneticMoment;
142 inline void G4DynamicParticle::SetMagneticMoment(G4double magneticMoment)
144 theDynamicalMagneticMoment = magneticMoment;
147 inline const G4ThreeVector& G4DynamicParticle::GetMomentumDirection() const
149 return theMomentumDirection;
152 inline G4ThreeVector G4DynamicParticle::GetMomentum() const
154 G4double pModule = std::sqrt(theKineticEnergy*theKineticEnergy +
155 2*theKineticEnergy*theDynamicalMass);
156 G4ThreeVector pMomentum(theMomentumDirection.x()*pModule,
157 theMomentumDirection.y()*pModule,
158 theMomentumDirection.z()*pModule);
162 inline G4LorentzVector G4DynamicParticle::Get4Momentum() const
164 G4double mass = theDynamicalMass;
165 G4double energy = theKineticEnergy;
166 G4double momentum = std::sqrt(energy*energy+2.0*mass*energy);
167 G4LorentzVector p4( theMomentumDirection.x()*momentum,
168 theMomentumDirection.y()*momentum,
169 theMomentumDirection.z()*momentum,
174 inline G4double G4DynamicParticle::GetTotalMomentum() const
176 // The momentum is returned in energy equivalent.
177 return std::sqrt((theKineticEnergy + 2.*theDynamicalMass)* theKineticEnergy);
180 inline G4ParticleDefinition* G4DynamicParticle::GetDefinition() const
182 return const_cast<G4ParticleDefinition*>(theParticleDefinition);
185 inline const G4ParticleDefinition* G4DynamicParticle::GetParticleDefinition() const
187 return const_cast<G4ParticleDefinition*>(theParticleDefinition);
190 inline const G4ThreeVector& G4DynamicParticle::GetPolarization() const
192 return thePolarization;
195 inline G4double G4DynamicParticle::GetProperTime() const
197 return theProperTime;
200 inline G4double G4DynamicParticle::GetTotalEnergy() const
202 return (theKineticEnergy+theDynamicalMass);
205 inline G4double G4DynamicParticle::GetKineticEnergy() const
207 return theKineticEnergy;
210 inline void G4DynamicParticle::SetMomentumDirection(const G4ThreeVector &aDirection)
212 theMomentumDirection = aDirection;
215 inline void G4DynamicParticle::SetMomentumDirection(G4double px, G4double py, G4double pz)
217 theMomentumDirection.setX(px);
218 theMomentumDirection.setY(py);
219 theMomentumDirection.setZ(pz);
223 inline void G4DynamicParticle::SetPolarization(G4double polX, G4double polY, G4double polZ)
225 thePolarization.setX(polX);
226 thePolarization.setY(polY);
227 thePolarization.setZ(polZ);
230 inline void G4DynamicParticle::SetKineticEnergy(G4double aEnergy)
232 theKineticEnergy = aEnergy;
235 inline void G4DynamicParticle::SetProperTime(G4double atime)
237 theProperTime = atime;
240 inline const G4DecayProducts* G4DynamicParticle::GetPreAssignedDecayProducts() const
242 return thePreAssignedDecayProducts;
245 inline void G4DynamicParticle::SetPreAssignedDecayProducts(G4DecayProducts* aDecayProducts)
247 thePreAssignedDecayProducts = aDecayProducts;
250 inline G4double G4DynamicParticle::GetPreAssignedDecayProperTime() const
252 return thePreAssignedDecayTime;
255 inline void G4DynamicParticle::SetPreAssignedDecayProperTime(G4double aTime)
257 thePreAssignedDecayTime = aTime;
261 void G4DynamicParticle::SetVerboseLevel(G4int value)
263 verboseLevel = value;
267 G4int G4DynamicParticle::GetVerboseLevel() const
273 void G4DynamicParticle::SetPrimaryParticle(G4PrimaryParticle* p)
279 G4PrimaryParticle* G4DynamicParticle::GetPrimaryParticle() const
281 return primaryParticle;
285 G4int G4DynamicParticle::GetPDGcode() const
287 G4int code = theParticleDefinition->GetPDGEncoding();
288 if(code==0) code = thePDGcode;
293 void G4DynamicParticle::SetPDGcode(G4int c)