source: trunk/source/geometry/magneticfield/include/G4FieldTrack.icc @ 1202

Last change on this file since 1202 was 921, checked in by garnier, 15 years ago

en test de gl2ps. Problemes de libraries

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