| Geant4 Cross Reference |
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: G4FieldTrack.icc 69699 2013-05-13 08:50:30Z gcosmo $
28 //
29 // -------------------------------------------------------------------
30
31 inline void
32 G4FieldTrack::InitialiseSpin( const G4ThreeVector& Spin )
33 {
34 // static G4ThreeVector ZeroVec(0.0, 0.0, 0.0);
35
36 fSpin = Spin;
37 // New Member ?? G4bool fHasSpin;
38 // fHasSpin = (fSpin != ZeroVec);
39 }
40
41 inline
42 G4FieldTrack::G4FieldTrack( const G4FieldTrack& rStVec )
43 : fDistanceAlongCurve( rStVec.fDistanceAlongCurve),
44 fKineticEnergy( rStVec.fKineticEnergy ),
45 fRestMass_c2( rStVec.fRestMass_c2),
46 fLabTimeOfFlight( rStVec.fLabTimeOfFlight ),
47 fProperTimeOfFlight( rStVec.fProperTimeOfFlight ),
48 // fMomentumModulus( rStVec.fMomentumModulus ),
49 fSpin( rStVec.fSpin ),
50 fMomentumDir( rStVec.fMomentumDir ),
51 fChargeState( rStVec.fChargeState )
52 {
53 SixVector[0]= rStVec.SixVector[0];
54 SixVector[1]= rStVec.SixVector[1];
55 SixVector[2]= rStVec.SixVector[2];
56 SixVector[3]= rStVec.SixVector[3];
57 SixVector[4]= rStVec.SixVector[4];
58 SixVector[5]= rStVec.SixVector[5];
59
60 // fpChargeState= new G4ChargeState( *rStVec.fpChargeState );
61 // Can share charge state only when using handles etc
62 // fpChargeState = rStVec.fpChargeState;
63 }
64
65 inline
66 G4FieldTrack::~G4FieldTrack()
67 {
68 // delete fpChargeState;
69 }
70
71 inline G4FieldTrack&
72 G4FieldTrack::SetCurvePnt(const G4ThreeVector& pPosition,
73 const G4ThreeVector& pMomentum,
74 G4double s_curve )
75 {
76 SixVector[0] = pPosition.x();
77 SixVector[1] = pPosition.y();
78 SixVector[2] = pPosition.z();
79
80 SixVector[3] = pMomentum.x();
81 SixVector[4] = pMomentum.y();
82 SixVector[5] = pMomentum.z();
83
84 fMomentumDir = pMomentum.unit();
85
86 fDistanceAlongCurve= s_curve;
87
88 return *this;
89 }
90
91 inline
92 G4ThreeVector G4FieldTrack::GetPosition() const
93 {
94 G4ThreeVector myPosition( SixVector[0], SixVector[1], SixVector[2] );
95 return myPosition;
96 }
97
98 inline
99 void G4FieldTrack::SetPosition( G4ThreeVector pPosition)
100 {
101 SixVector[0] = pPosition.x();
102 SixVector[1] = pPosition.y();
103 SixVector[2] = pPosition.z();
104 }
105
106 inline
107 const G4ThreeVector& G4FieldTrack::GetMomentumDir() const
108 {
109 // G4ThreeVector myMomentum( SixVector[3], SixVector[4], SixVector[5] );
110 // return myVelocity;
111 return fMomentumDir;
112 }
113
114 inline
115 G4ThreeVector G4FieldTrack::GetMomentumDirection() const
116 {
117 return fMomentumDir;
118 }
119
120 inline
121 G4double G4FieldTrack::GetCurveLength() const
122 {
123 return fDistanceAlongCurve;
124 }
125
126 inline
127 void G4FieldTrack::SetCurveLength(G4double nCurve_s)
128 {
129 fDistanceAlongCurve= nCurve_s;
130 }
131
132 inline
133 G4double G4FieldTrack::GetKineticEnergy() const
134 {
135 return fKineticEnergy;
136 }
137
138 inline
139 void G4FieldTrack::SetKineticEnergy(G4double newKinEnergy)
140 {
141 fKineticEnergy=newKinEnergy;
142 }
143
144 inline
145 G4ThreeVector G4FieldTrack::GetSpin() const
146 {
147 return fSpin;
148 }
149
150 inline
151 void G4FieldTrack::SetSpin(G4ThreeVector nSpin)
152 {
153 fSpin=nSpin;
154 }
155
156 inline
157 G4double G4FieldTrack::GetLabTimeOfFlight() const
158 {
159 return fLabTimeOfFlight;
160 }
161
162 inline
163 void G4FieldTrack::SetLabTimeOfFlight(G4double nTOF)
164 {
165 fLabTimeOfFlight=nTOF;
166 }
167
168 inline
169 G4double G4FieldTrack::GetProperTimeOfFlight() const
170 {
171 return fProperTimeOfFlight;
172 }
173
174 inline
175 void G4FieldTrack::SetProperTimeOfFlight(G4double nTOF)
176 {
177 fProperTimeOfFlight=nTOF;
178 }
179
180 inline
181 void G4FieldTrack::SetMomentumDir(G4ThreeVector newMomDir)
182 {
183 fMomentumDir= newMomDir;
184 }
185
186 inline
187 G4ThreeVector G4FieldTrack::GetMomentum() const
188 {
189 return G4ThreeVector( SixVector[3], SixVector[4], SixVector[5] );
190 }
191
192 inline
193 void G4FieldTrack::SetMomentum(G4ThreeVector pMomentum)
194 {
195 SixVector[3] = pMomentum.x();
196 SixVector[4] = pMomentum.y();
197 SixVector[5] = pMomentum.z();
198
199 fMomentumDir = pMomentum.unit();
200 }
201
202 inline
203 G4double G4FieldTrack::GetCharge() const
204 {
205 return fChargeState.GetCharge();
206 }
207
208 // Dump values to array
209 //
210 // note that momentum direction is not saved
211
212 inline
213 void G4FieldTrack::DumpToArray(G4double valArr[ncompSVEC] ) const
214 {
215 valArr[0]=SixVector[0];
216 valArr[1]=SixVector[1];
217 valArr[2]=SixVector[2];
218 valArr[3]=SixVector[3];
219 valArr[4]=SixVector[4];
220 valArr[5]=SixVector[5];
221
222 G4ThreeVector Momentum(valArr[3],valArr[4],valArr[5]);
223
224 // G4double mass_in_Kg;
225 // mass_in_Kg = fEnergy / velocity_mag_sq * (1-velocity_mag_sq/c_squared);
226 // valArr[6]= mass_in_Kg;
227
228 // The following components may or may not be integrated.
229 valArr[6]= fKineticEnergy;
230
231 // valArr[6]=fEnergy; // When it is integrated over, do this ...
232 valArr[7]=fLabTimeOfFlight;
233 valArr[8]=fProperTimeOfFlight;
234 valArr[9]=fSpin.x();
235 valArr[10]=fSpin.y();
236 valArr[11]=fSpin.z();
237 // valArr[13]=fMomentumDir.x();
238 // valArr[14]=fMomentumDir.y();
239 // valArr[15]=fMomentumDir.z();
240 // valArr[]=fDistanceAlongCurve;
241 }
242
243 // Load values from array
244 //
245 // note that momentum direction must-be/is normalised
246
247 inline
248 void G4FieldTrack::LoadFromArray(const G4double valArrIn[ncompSVEC], G4int noVarsIntegrated)
249 {
250 G4int i;
251
252 // Fill the variables not integrated with zero -- so it's clear !!
253 static G4ThreadLocal G4double valArr[ncompSVEC];
254 for( i=0; i<noVarsIntegrated; i++){
255 valArr[i]= valArrIn[i];
256 }
257 for( i=noVarsIntegrated; i<ncompSVEC; i++) {
258 valArr[i]= 0.0;
259 }
260
261 SixVector[0]=valArr[0];
262 SixVector[1]=valArr[1];
263 SixVector[2]=valArr[2];
264 SixVector[3]=valArr[3];
265 SixVector[4]=valArr[4];
266 SixVector[5]=valArr[5];
267
268 G4ThreeVector Momentum(valArr[3],valArr[4],valArr[5]);
269
270 G4double momentum_square= Momentum.mag2();
271 fMomentumDir= Momentum.unit();
272
273 fKineticEnergy = momentum_square /
274 (std::sqrt(momentum_square+fRestMass_c2*fRestMass_c2)
275 + fRestMass_c2 );
276 // The above equation is stable for small and large momenta
277
278 // The following components may or may not be
279 // integrated over -- integration is optional
280 // fKineticEnergy= valArr[6];
281
282 fLabTimeOfFlight=valArr[7];
283 fProperTimeOfFlight=valArr[8];
284 fSpin=G4ThreeVector(valArr[9],valArr[10],valArr[11]);
285 // fMomentumDir=G4ThreeVector(valArr[13],valArr[14],valArr[15]);
286 // fDistanceAlongCurve= valArr[];
287 }
288
289 inline
290 G4FieldTrack & G4FieldTrack::operator = ( const G4FieldTrack& rStVec )
291 {
292 if (&rStVec == this) return *this;
293
294 SixVector[0]= rStVec.SixVector[0];
295 SixVector[1]= rStVec.SixVector[1];
296 SixVector[2]= rStVec.SixVector[2];
297 SixVector[3]= rStVec.SixVector[3];
298 SixVector[4]= rStVec.SixVector[4];
299 SixVector[5]= rStVec.SixVector[5];
300 SetCurveLength( rStVec.GetCurveLength() );
301
302 fKineticEnergy= rStVec.fKineticEnergy;
303 SetLabTimeOfFlight( rStVec.GetLabTimeOfFlight() );
304 SetProperTimeOfFlight( rStVec.GetProperTimeOfFlight() );
305 SetSpin( rStVec.GetSpin() );
306 fMomentumDir= rStVec.fMomentumDir;
307
308 fChargeState= rStVec.fChargeState;
309 // (*fpChargeState)= *(rStVec.fpChargeState);
310 // fpChargeState= rStVec.fpChargeState; // Handles!!
311 return *this;
312 }
313
314 inline void
315 G4FieldTrack::UpdateFourMomentum( G4double kineticEnergy,
316 const G4ThreeVector& momentumDirection )
317 {
318 G4double momentum_mag = std::sqrt(kineticEnergy*kineticEnergy
319 +2.0*fRestMass_c2*kineticEnergy);
320 G4ThreeVector momentumVector= momentum_mag * momentumDirection;
321
322 // SetMomentum( momentumVector ); // Set direction (from unit): used sqrt, div
323 SixVector[3] = momentumVector.x();
324 SixVector[4] = momentumVector.y();
325 SixVector[5] = momentumVector.z();
326
327 fMomentumDir= momentumDirection; // Set directly to avoid inaccuracy.
328 fKineticEnergy= kineticEnergy;
329 }
330
331 inline void G4FieldTrack::UpdateState( const G4ThreeVector& position,
332 G4double laboratoryTimeOfFlight,
333 const G4ThreeVector& momentumDirection,
334 G4double kineticEnergy
335 )
336 {
337 // SetCurvePnt( position, momentumVector, s_curve=0.0);
338 SetPosition( position);
339 fLabTimeOfFlight= laboratoryTimeOfFlight;
340 fDistanceAlongCurve= 0.0;
341
342 UpdateFourMomentum( kineticEnergy, momentumDirection);
343 }
344