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: G4FieldTrack.icc 69699 2013-05-13 08:50:30Z gcosmo $
29 // -------------------------------------------------------------------
32 G4FieldTrack::InitialiseSpin( const G4ThreeVector& Spin )
34 // static G4ThreeVector ZeroVec(0.0, 0.0, 0.0);
37 // New Member ?? G4bool fHasSpin;
38 // fHasSpin = (fSpin != ZeroVec);
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 )
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];
60 // fpChargeState= new G4ChargeState( *rStVec.fpChargeState );
61 // Can share charge state only when using handles etc
62 // fpChargeState = rStVec.fpChargeState;
66 G4FieldTrack::~G4FieldTrack()
68 // delete fpChargeState;
72 G4FieldTrack::SetCurvePnt(const G4ThreeVector& pPosition,
73 const G4ThreeVector& pMomentum,
76 SixVector[0] = pPosition.x();
77 SixVector[1] = pPosition.y();
78 SixVector[2] = pPosition.z();
80 SixVector[3] = pMomentum.x();
81 SixVector[4] = pMomentum.y();
82 SixVector[5] = pMomentum.z();
84 fMomentumDir = pMomentum.unit();
86 fDistanceAlongCurve= s_curve;
92 G4ThreeVector G4FieldTrack::GetPosition() const
94 G4ThreeVector myPosition( SixVector[0], SixVector[1], SixVector[2] );
99 void G4FieldTrack::SetPosition( G4ThreeVector pPosition)
101 SixVector[0] = pPosition.x();
102 SixVector[1] = pPosition.y();
103 SixVector[2] = pPosition.z();
107 const G4ThreeVector& G4FieldTrack::GetMomentumDir() const
109 // G4ThreeVector myMomentum( SixVector[3], SixVector[4], SixVector[5] );
110 // return myVelocity;
115 G4ThreeVector G4FieldTrack::GetMomentumDirection() const
121 G4double G4FieldTrack::GetCurveLength() const
123 return fDistanceAlongCurve;
127 void G4FieldTrack::SetCurveLength(G4double nCurve_s)
129 fDistanceAlongCurve= nCurve_s;
133 G4double G4FieldTrack::GetKineticEnergy() const
135 return fKineticEnergy;
139 void G4FieldTrack::SetKineticEnergy(G4double newKinEnergy)
141 fKineticEnergy=newKinEnergy;
145 G4ThreeVector G4FieldTrack::GetSpin() const
151 void G4FieldTrack::SetSpin(G4ThreeVector nSpin)
157 G4double G4FieldTrack::GetLabTimeOfFlight() const
159 return fLabTimeOfFlight;
163 void G4FieldTrack::SetLabTimeOfFlight(G4double nTOF)
165 fLabTimeOfFlight=nTOF;
169 G4double G4FieldTrack::GetProperTimeOfFlight() const
171 return fProperTimeOfFlight;
175 void G4FieldTrack::SetProperTimeOfFlight(G4double nTOF)
177 fProperTimeOfFlight=nTOF;
181 void G4FieldTrack::SetMomentumDir(G4ThreeVector newMomDir)
183 fMomentumDir= newMomDir;
187 G4ThreeVector G4FieldTrack::GetMomentum() const
189 return G4ThreeVector( SixVector[3], SixVector[4], SixVector[5] );
193 void G4FieldTrack::SetMomentum(G4ThreeVector pMomentum)
195 SixVector[3] = pMomentum.x();
196 SixVector[4] = pMomentum.y();
197 SixVector[5] = pMomentum.z();
199 fMomentumDir = pMomentum.unit();
203 G4double G4FieldTrack::GetCharge() const
205 return fChargeState.GetCharge();
208 // Dump values to array
210 // note that momentum direction is not saved
213 void G4FieldTrack::DumpToArray(G4double valArr[ncompSVEC] ) const
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];
222 G4ThreeVector Momentum(valArr[3],valArr[4],valArr[5]);
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;
228 // The following components may or may not be integrated.
229 valArr[6]= fKineticEnergy;
231 // valArr[6]=fEnergy; // When it is integrated over, do this ...
232 valArr[7]=fLabTimeOfFlight;
233 valArr[8]=fProperTimeOfFlight;
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;
243 // Load values from array
245 // note that momentum direction must-be/is normalised
248 void G4FieldTrack::LoadFromArray(const G4double valArrIn[ncompSVEC], G4int noVarsIntegrated)
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];
257 for( i=noVarsIntegrated; i<ncompSVEC; i++) {
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];
268 G4ThreeVector Momentum(valArr[3],valArr[4],valArr[5]);
270 G4double momentum_square= Momentum.mag2();
271 fMomentumDir= Momentum.unit();
273 fKineticEnergy = momentum_square /
274 (std::sqrt(momentum_square+fRestMass_c2*fRestMass_c2)
276 // The above equation is stable for small and large momenta
278 // The following components may or may not be
279 // integrated over -- integration is optional
280 // fKineticEnergy= valArr[6];
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[];
290 G4FieldTrack & G4FieldTrack::operator = ( const G4FieldTrack& rStVec )
292 if (&rStVec == this) return *this;
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() );
302 fKineticEnergy= rStVec.fKineticEnergy;
303 SetLabTimeOfFlight( rStVec.GetLabTimeOfFlight() );
304 SetProperTimeOfFlight( rStVec.GetProperTimeOfFlight() );
305 SetSpin( rStVec.GetSpin() );
306 fMomentumDir= rStVec.fMomentumDir;
308 fChargeState= rStVec.fChargeState;
309 // (*fpChargeState)= *(rStVec.fpChargeState);
310 // fpChargeState= rStVec.fpChargeState; // Handles!!
315 G4FieldTrack::UpdateFourMomentum( G4double kineticEnergy,
316 const G4ThreeVector& momentumDirection )
318 G4double momentum_mag = std::sqrt(kineticEnergy*kineticEnergy
319 +2.0*fRestMass_c2*kineticEnergy);
320 G4ThreeVector momentumVector= momentum_mag * momentumDirection;
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();
327 fMomentumDir= momentumDirection; // Set directly to avoid inaccuracy.
328 fKineticEnergy= kineticEnergy;
331 inline void G4FieldTrack::UpdateState( const G4ThreeVector& position,
332 G4double laboratoryTimeOfFlight,
333 const G4ThreeVector& momentumDirection,
334 G4double kineticEnergy
337 // SetCurvePnt( position, momentumVector, s_curve=0.0);
338 SetPosition( position);
339 fLabTimeOfFlight= laboratoryTimeOfFlight;
340 fDistanceAlongCurve= 0.0;
342 UpdateFourMomentum( kineticEnergy, momentumDirection);