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