Geant4  10.03
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 //
27 // $Id: G4DynamicParticle.icc 98352 2016-07-08 08:21:00Z gcosmo $
28 //
29 //
30 // ------------------------------------------------------------
31 // GEANT 4 class header file
32 //
33 // History: first implementation, based on object model of
34 // 17 AUg. 1999 H.Kurashige
35 // ------------------------------------------------------------
36 extern G4PART_DLL G4ThreadLocal G4Allocator<G4DynamicParticle> *pDynamicParticleAllocator;
37 
38 // ------------------------
39 // Inlined operators
40 // ------------------------
41 
42 inline void * G4DynamicParticle::operator new(size_t)
43 {
44  if (!pDynamicParticleAllocator) pDynamicParticleAllocator =
45  new G4Allocator<G4DynamicParticle>;
46  return pDynamicParticleAllocator->MallocSingle();
47 }
48 
49 inline void G4DynamicParticle::operator delete(void * aDynamicParticle)
50 {
51  pDynamicParticleAllocator->FreeSingle((G4DynamicParticle *) aDynamicParticle);
52 }
53 
54 // ------------------------
55 // Inlined functions
56 // ------------------------
57 
58 inline const G4ElectronOccupancy* G4DynamicParticle::GetElectronOccupancy() const
59 {
60  return theElectronOccupancy;
61 }
62 
63 inline G4int G4DynamicParticle::GetTotalOccupancy() const
64 {
65  G4int value = 0;
66  if ( theElectronOccupancy != 0) {
67  value = theElectronOccupancy->GetTotalOccupancy();
68  }
69  return value;
70 }
71 
72 inline G4int G4DynamicParticle::GetOccupancy(G4int orbit) const
73 {
74  G4int value = 0;
75  if ( theElectronOccupancy != 0) {
76  value = theElectronOccupancy->GetOccupancy(orbit);
77  }
78  return value;
79 }
80 
81 inline void G4DynamicParticle::AddElectron(G4int orbit, G4int number )
82 {
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;
88  }
89 }
90 
91 inline void G4DynamicParticle::RemoveElectron(G4int orbit, G4int number)
92 {
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;
98  }
99 }
100 
101 inline G4double G4DynamicParticle::GetCharge() const
102 {
103  return theDynamicalCharge;
104 }
105 
106 inline void G4DynamicParticle::SetCharge(G4double newCharge)
107 {
108  theDynamicalCharge = newCharge;
109 }
110 
111 inline void G4DynamicParticle::SetCharge(G4int newCharge)
112 {
113  theDynamicalCharge = newCharge*CLHEP::eplus;
114 }
115 
116 inline G4double G4DynamicParticle::GetMass() const
117 {
118  return theDynamicalMass;
119 }
120 
121 
122 inline G4double G4DynamicParticle::GetSpin() const
123 {
124  return theDynamicalSpin;
125 }
126 
127 inline void G4DynamicParticle::SetSpin(G4double spin)
128 {
129  theDynamicalSpin = spin;
130 }
131 
132 inline void G4DynamicParticle::SetSpin(G4int spinInUnitOfHalfInteger)
133 {
134  theDynamicalSpin = spinInUnitOfHalfInteger * 0.5;
135 }
136 
137 inline G4double G4DynamicParticle::GetMagneticMoment() const
138 {
139  return theDynamicalMagneticMoment;
140 }
141 
142 inline void G4DynamicParticle::SetMagneticMoment(G4double magneticMoment)
143 {
144  theDynamicalMagneticMoment = magneticMoment;
145 }
146 
147 inline const G4ThreeVector& G4DynamicParticle::GetMomentumDirection() const
148 {
149  return theMomentumDirection;
150 }
151 
152 inline G4ThreeVector G4DynamicParticle::GetMomentum() const
153 {
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);
159  return pMomentum;
160 }
161 
162 inline G4LorentzVector G4DynamicParticle::Get4Momentum() const
163 {
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,
170  energy+mass);
171  return p4;
172 }
173 
174 inline G4double G4DynamicParticle::GetTotalMomentum() const
175 {
176  // The momentum is returned in energy equivalent.
177  return std::sqrt((theKineticEnergy + 2.*theDynamicalMass)* theKineticEnergy);
178 }
179 
180 inline G4ParticleDefinition* G4DynamicParticle::GetDefinition() const
181 {
182  return const_cast<G4ParticleDefinition*>(theParticleDefinition);
183 }
184 
185 inline const G4ParticleDefinition* G4DynamicParticle::GetParticleDefinition() const
186 {
187  return const_cast<G4ParticleDefinition*>(theParticleDefinition);
188 }
189 
190 inline const G4ThreeVector& G4DynamicParticle::GetPolarization() const
191 {
192  return thePolarization;
193 }
194 
195 inline G4double G4DynamicParticle::GetProperTime() const
196 {
197  return theProperTime;
198 }
199 
200 inline G4double G4DynamicParticle::GetTotalEnergy() const
201 {
202  return (theKineticEnergy+theDynamicalMass);
203 }
204 
205 inline G4double G4DynamicParticle::GetKineticEnergy() const
206 {
207  return theKineticEnergy;
208 }
209 
210 inline void G4DynamicParticle::SetMomentumDirection(const G4ThreeVector &aDirection)
211 {
212  theMomentumDirection = aDirection;
213 }
214 
215 inline void G4DynamicParticle::SetMomentumDirection(G4double px, G4double py, G4double pz)
216 {
217  theMomentumDirection.setX(px);
218  theMomentumDirection.setY(py);
219  theMomentumDirection.setZ(pz);
220 }
221 
222 
223 inline void G4DynamicParticle::SetPolarization(G4double polX, G4double polY, G4double polZ)
224 {
225  thePolarization.setX(polX);
226  thePolarization.setY(polY);
227  thePolarization.setZ(polZ);
228 }
229 
230 inline void G4DynamicParticle::SetKineticEnergy(G4double aEnergy)
231 {
232  theKineticEnergy = aEnergy;
233 }
234 
235 inline void G4DynamicParticle::SetProperTime(G4double atime)
236 {
237  theProperTime = atime;
238 }
239 
240 inline const G4DecayProducts* G4DynamicParticle::GetPreAssignedDecayProducts() const
241 {
242  return thePreAssignedDecayProducts;
243 }
244 
245 inline void G4DynamicParticle::SetPreAssignedDecayProducts(G4DecayProducts* aDecayProducts)
246 {
247  thePreAssignedDecayProducts = aDecayProducts;
248 }
249 
250 inline G4double G4DynamicParticle::GetPreAssignedDecayProperTime() const
251 {
252  return thePreAssignedDecayTime;
253 }
254 
255 inline void G4DynamicParticle::SetPreAssignedDecayProperTime(G4double aTime)
256 {
257  thePreAssignedDecayTime = aTime;
258 }
259 
260 inline
261 void G4DynamicParticle::SetVerboseLevel(G4int value)
262 {
263  verboseLevel = value;
264 }
265 
266 inline
267 G4int G4DynamicParticle::GetVerboseLevel() const
268 {
269  return verboseLevel;
270 }
271 
272 inline
273 void G4DynamicParticle::SetPrimaryParticle(G4PrimaryParticle* p)
274 {
275  primaryParticle=p;
276 }
277 
278 inline
279 G4PrimaryParticle* G4DynamicParticle::GetPrimaryParticle() const
280 {
281  return primaryParticle;
282 }
283 
284 inline
285 G4int G4DynamicParticle::GetPDGcode() const
286 {
287  G4int code = theParticleDefinition->GetPDGEncoding();
288  if(code==0) code = thePDGcode;
289  return code;
290 }
291 
292 inline
293 void G4DynamicParticle::SetPDGcode(G4int c)
294 {
295  thePDGcode = c;
296 }