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// ********************************************************************
26// G4FieldTrack inline methods implementation
28// Author: John Apostolakis, CERN - First version, 14.10.1996
29// -------------------------------------------------------------------
32G4FieldTrack::G4FieldTrack( const G4FieldTrack& rStVec )
33 : fDistanceAlongCurve( rStVec.fDistanceAlongCurve),
34 fKineticEnergy( rStVec.fKineticEnergy ),
35 fRestMass_c2( rStVec.fRestMass_c2),
36 fLabTimeOfFlight( rStVec.fLabTimeOfFlight ),
37 fProperTimeOfFlight( rStVec.fProperTimeOfFlight ),
38 // fMomentumModulus( rStVec.fMomentumModulus ),
39 fPolarization( rStVec.fPolarization ),
40 fMomentumDir( rStVec.fMomentumDir ),
41 fChargeState( rStVec.fChargeState )
43 SixVector[0]= rStVec.SixVector[0];
44 SixVector[1]= rStVec.SixVector[1];
45 SixVector[2]= rStVec.SixVector[2];
46 SixVector[3]= rStVec.SixVector[3];
47 SixVector[4]= rStVec.SixVector[4];
48 SixVector[5]= rStVec.SixVector[5];
50 // fpChargeState= new G4ChargeState( *rStVec.fpChargeState );
51 // Can share charge state only when using handles etc
52 // fpChargeState = rStVec.fpChargeState;
56G4FieldTrack& G4FieldTrack::operator= ( const G4FieldTrack& rStVec )
58 if (&rStVec == this) return *this;
60 SixVector[0]= rStVec.SixVector[0];
61 SixVector[1]= rStVec.SixVector[1];
62 SixVector[2]= rStVec.SixVector[2];
63 SixVector[3]= rStVec.SixVector[3];
64 SixVector[4]= rStVec.SixVector[4];
65 SixVector[5]= rStVec.SixVector[5];
66 SetCurveLength( rStVec.GetCurveLength() );
68 fKineticEnergy= rStVec.fKineticEnergy;
69 fRestMass_c2= rStVec.fRestMass_c2;
70 SetLabTimeOfFlight( rStVec.GetLabTimeOfFlight() );
71 SetProperTimeOfFlight( rStVec.GetProperTimeOfFlight() );
72 SetPolarization( rStVec.GetPolarization() );
73 fMomentumDir= rStVec.fMomentumDir;
75 fChargeState= rStVec.fChargeState;
76 // (*fpChargeState)= *(rStVec.fpChargeState);
77 // fpChargeState= rStVec.fpChargeState; // Handles!!
82G4FieldTrack::G4FieldTrack(G4FieldTrack&& from)
83 : fDistanceAlongCurve( from.fDistanceAlongCurve),
84 fKineticEnergy( from.fKineticEnergy ),
85 fRestMass_c2( from.fRestMass_c2),
86 fLabTimeOfFlight( from.fLabTimeOfFlight ),
87 fProperTimeOfFlight( from.fProperTimeOfFlight ),
88 fChargeState( from.fChargeState )
90 SixVector[0]= from.SixVector[0];
91 SixVector[1]= from.SixVector[1];
92 SixVector[2]= from.SixVector[2];
93 SixVector[3]= from.SixVector[3];
94 SixVector[4]= from.SixVector[4];
95 SixVector[5]= from.SixVector[5];
97 fPolarization = std::move( from.fPolarization );
98 fMomentumDir = std::move( from.fMomentumDir );
102G4FieldTrack& G4FieldTrack::operator=(G4FieldTrack&& from)
104 if (&from == this) return *this;
106 SixVector[0]= from.SixVector[0];
107 SixVector[1]= from.SixVector[1];
108 SixVector[2]= from.SixVector[2];
109 SixVector[3]= from.SixVector[3];
110 SixVector[4]= from.SixVector[4];
111 SixVector[5]= from.SixVector[5];
113 fDistanceAlongCurve = from.fDistanceAlongCurve;
114 fKineticEnergy = from.fKineticEnergy;
115 fRestMass_c2 = from.fRestMass_c2;
116 fLabTimeOfFlight = from.fLabTimeOfFlight;
117 fProperTimeOfFlight = from.fProperTimeOfFlight;
118 fChargeState = from.fChargeState;
120 fPolarization = std::move( from.fPolarization );
121 fMomentumDir = std::move( from.fMomentumDir );
127G4FieldTrack::~G4FieldTrack()
129 // delete fpChargeState;
133G4FieldTrack::SetCurvePnt(const G4ThreeVector& pPosition,
134 const G4ThreeVector& pMomentum,
137 SixVector[0] = pPosition.x();
138 SixVector[1] = pPosition.y();
139 SixVector[2] = pPosition.z();
141 SixVector[3] = pMomentum.x();
142 SixVector[4] = pMomentum.y();
143 SixVector[5] = pMomentum.z();
145 fMomentumDir = (pMomentum.mag2() > 0.0)
146 ? pMomentum.unit() : G4ThreeVector( 0.0, 0.0, 0.0 );
148 fDistanceAlongCurve = s_curve;
154void G4FieldTrack::SetPDGSpin(G4double pdgSpin)
156 fChargeState.SetPDGSpin(pdgSpin);
160G4double G4FieldTrack::GetPDGSpin()
162 return fChargeState.GetPDGSpin();
166G4ThreeVector G4FieldTrack::GetPosition() const
168 G4ThreeVector myPosition( SixVector[0], SixVector[1], SixVector[2] );
173void G4FieldTrack::SetPosition( G4ThreeVector pPosition)
175 SixVector[0] = pPosition.x();
176 SixVector[1] = pPosition.y();
177 SixVector[2] = pPosition.z();
181const G4ThreeVector& G4FieldTrack::GetMomentumDir() const
183 // G4ThreeVector myMomentum( SixVector[3], SixVector[4], SixVector[5] );
184 // return myVelocity;
189G4ThreeVector G4FieldTrack::GetMomentumDirection() const
195G4double G4FieldTrack::GetCurveLength() const
197 return fDistanceAlongCurve;
201void G4FieldTrack::SetCurveLength(G4double nCurve_s)
203 fDistanceAlongCurve = nCurve_s;
207G4double G4FieldTrack::GetKineticEnergy() const
209 return fKineticEnergy;
213void G4FieldTrack::SetKineticEnergy(G4double newKinEnergy)
215 fKineticEnergy = newKinEnergy;
219G4ThreeVector G4FieldTrack::GetPolarization() const
221 return fPolarization;
225void G4FieldTrack::SetPolarization(const G4ThreeVector& vecPlz)
227 fPolarization = vecPlz;
231const G4ChargeState* G4FieldTrack::GetChargeState() const
233 return &fChargeState;
237G4double G4FieldTrack::GetLabTimeOfFlight() const
239 return fLabTimeOfFlight;
243void G4FieldTrack::SetLabTimeOfFlight(G4double nTOF)
245 fLabTimeOfFlight = nTOF;
249G4double G4FieldTrack::GetProperTimeOfFlight() const
251 return fProperTimeOfFlight;
255void G4FieldTrack::SetProperTimeOfFlight(G4double nTOF)
257 fProperTimeOfFlight = nTOF;
261void G4FieldTrack::SetMomentumDir(G4ThreeVector newMomDir)
263 fMomentumDir = newMomDir;
267G4ThreeVector G4FieldTrack::GetMomentum() const
269 return G4ThreeVector( SixVector[3], SixVector[4], SixVector[5] );
273void G4FieldTrack::SetMomentum(G4ThreeVector pMomentum)
275 SixVector[3] = pMomentum.x();
276 SixVector[4] = pMomentum.y();
277 SixVector[5] = pMomentum.z();
279 if( pMomentum.mag2() > 0.0 )
280 fMomentumDir = pMomentum.unit();
282 fMomentumDir = G4ThreeVector( 0.0, 0.0, 0.0 );
286G4double G4FieldTrack::GetCharge() const
288 return fChargeState.GetCharge();
292G4double G4FieldTrack::GetRestMass() const
298void G4FieldTrack::SetRestMass(G4double Mass_c2)
300 fRestMass_c2 = Mass_c2;
303// Dump values to array
305// Note that momentum direction is not saved
308void G4FieldTrack::DumpToArray(G4double valArr[ncompSVEC] ) const
310 valArr[0]=SixVector[0];
311 valArr[1]=SixVector[1];
312 valArr[2]=SixVector[2];
313 valArr[3]=SixVector[3];
314 valArr[4]=SixVector[4];
315 valArr[5]=SixVector[5];
317 G4ThreeVector Momentum(valArr[3],valArr[4],valArr[5]);
319 // G4double mass_in_Kg;
320 // mass_in_Kg = fEnergy / velocity_mag_sq * (1-velocity_mag_sq/c_squared);
321 // valArr[6]= mass_in_Kg;
323 // The following components may or may not be integrated.
325 valArr[6]= fKineticEnergy;
327 // valArr[6]=fEnergy; // When it is integrated over, do this ...
328 valArr[7]=fLabTimeOfFlight;
329 valArr[8]=fProperTimeOfFlight;
330 valArr[9]=fPolarization.x();
331 valArr[10]=fPolarization.y();
332 valArr[11]=fPolarization.z();
333 // valArr[13]=fMomentumDir.x();
334 // valArr[14]=fMomentumDir.y();
335 // valArr[15]=fMomentumDir.z();
336 // valArr[]=fDistanceAlongCurve;
340void G4FieldTrack::UpdateFourMomentum( G4double kineticEnergy,
341 const G4ThreeVector& momentumDirection )
343 G4double momentum_mag = std::sqrt(kineticEnergy*kineticEnergy
344 +2.0*fRestMass_c2*kineticEnergy);
345 G4ThreeVector momentumVector = momentum_mag * momentumDirection;
347 // SetMomentum( momentumVector );
348 // Set direction (from unit): used sqrt, div
349 SixVector[3] = momentumVector.x();
350 SixVector[4] = momentumVector.y();
351 SixVector[5] = momentumVector.z();
353 fMomentumDir= momentumDirection; // Set directly to avoid inaccuracy.
354 fKineticEnergy= kineticEnergy;
358void G4FieldTrack::UpdateState( const G4ThreeVector& position,
359 G4double laboratoryTimeOfFlight,
360 const G4ThreeVector& momentumDirection,
361 G4double kineticEnergy )
363 // SetCurvePnt( position, momentumVector, s_curve=0.0);
364 SetPosition( position);
365 fLabTimeOfFlight = laboratoryTimeOfFlight;
366 fDistanceAlongCurve = 0.0;
368 UpdateFourMomentum( kineticEnergy, momentumDirection);
372void G4FieldTrack::InitialiseSpin( const G4ThreeVector& vecPolarization )
374 SetPolarization( vecPolarization );
377inline G4ThreeVector G4FieldTrack::GetSpin() const
379 return GetPolarization();
383void G4FieldTrack::SetSpin(G4ThreeVector vSpin)
385 SetPolarization(vSpin);