G4FieldTrack.icc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4FieldTrack.icc 69786 2013-05-15 09:38:51Z gcosmo $
00028 //
00029 // -------------------------------------------------------------------
00030 
00031 // Implementation methods for the embedded class G4ChargeState
00032 //                                ----------------------------
00033 inline G4FieldTrack::
00034 G4ChargeState::G4ChargeState(G4double charge,
00035                              G4double magnetic_dipole_moment,  
00036                              G4double electric_dipole_moment,  
00037                              G4double magnetic_charge)
00038 {
00039    fCharge= charge;
00040    fMagn_dipole= magnetic_dipole_moment;
00041    fElec_dipole= electric_dipole_moment;
00042    fMagneticCharge= magnetic_charge;    
00043 }  
00044 
00045 inline G4FieldTrack::
00046 G4ChargeState::G4ChargeState( 
00047   const G4FieldTrack::G4ChargeState& right )
00048 { 
00049   fCharge= right.fCharge;
00050   fMagn_dipole= right.fMagn_dipole; 
00051   fElec_dipole= right.fElec_dipole;
00052   fMagneticCharge= right.fMagneticCharge;
00053 }
00054 
00055 inline G4FieldTrack::G4ChargeState& G4FieldTrack::
00056 G4ChargeState::operator = ( const G4FieldTrack::G4ChargeState& right )
00057 { 
00058   if (&right == this) return *this;
00059 
00060   fCharge= right.fCharge;
00061   fMagn_dipole= right.fMagn_dipole; 
00062   fElec_dipole= right.fElec_dipole;
00063   fMagneticCharge= right.fMagneticCharge;
00064 
00065   return *this;
00066 }
00067 
00068 inline void
00069 G4FieldTrack::InitialiseSpin( const G4ThreeVector& Spin )
00070 {
00071   // static G4ThreeVector ZeroVec(0.0, 0.0, 0.0); 
00072 
00073   fSpin = Spin;
00074   // New Member ??  G4bool fHasSpin; 
00075   // fHasSpin = (fSpin != ZeroVec); 
00076 }
00077 
00078 inline void G4FieldTrack::
00079 G4ChargeState::SetChargeAndMoments(G4double charge, 
00080                                    G4double magnetic_dipole_moment,  
00081                                    G4double electric_dipole_moment,
00082                                    G4double magnetic_charge )
00083    //  Revise the charge and potentially all moments.
00084    //   By default do not change mdm, edm, mag charge. 
00085 {
00086    fCharge= charge;
00087    if( magnetic_dipole_moment < DBL_MAX) fMagn_dipole= magnetic_dipole_moment;
00088    if( electric_dipole_moment < DBL_MAX) fElec_dipole= electric_dipole_moment;
00089    if( magnetic_charge < DBL_MAX)        fMagneticCharge= magnetic_charge;    
00090 }
00091 
00092 inline
00093 G4FieldTrack::G4FieldTrack( const G4FieldTrack&  rStVec  )
00094  : fDistanceAlongCurve( rStVec.fDistanceAlongCurve),
00095    fKineticEnergy( rStVec.fKineticEnergy ),
00096    fRestMass_c2( rStVec.fRestMass_c2),
00097    fLabTimeOfFlight( rStVec.fLabTimeOfFlight ), 
00098    fProperTimeOfFlight( rStVec.fProperTimeOfFlight ), 
00099    // fMomentumModulus( rStVec.fMomentumModulus ),
00100    fSpin( rStVec.fSpin ), 
00101    fMomentumDir( rStVec.fMomentumDir ),
00102    fChargeState( rStVec.fChargeState )
00103 {
00104   SixVector[0]= rStVec.SixVector[0];
00105   SixVector[1]= rStVec.SixVector[1];
00106   SixVector[2]= rStVec.SixVector[2];
00107   SixVector[3]= rStVec.SixVector[3];
00108   SixVector[4]= rStVec.SixVector[4];
00109   SixVector[5]= rStVec.SixVector[5];
00110 
00111   // fpChargeState= new G4ChargeState( *rStVec.fpChargeState );
00112   // Can share charge state only when using handles etc
00113   //   fpChargeState = rStVec.fpChargeState;  
00114 }
00115 
00116 inline
00117 G4FieldTrack::~G4FieldTrack()
00118 {
00119   // delete fpChargeState; 
00120 }
00121 
00122 inline G4FieldTrack& 
00123 G4FieldTrack::SetCurvePnt(const G4ThreeVector& pPosition, 
00124                           const G4ThreeVector& pMomentum,  
00125                                 G4double       s_curve )
00126 {
00127   SixVector[0] = pPosition.x(); 
00128   SixVector[1] = pPosition.y(); 
00129   SixVector[2] = pPosition.z(); 
00130 
00131   SixVector[3] = pMomentum.x(); 
00132   SixVector[4] = pMomentum.y(); 
00133   SixVector[5] = pMomentum.z(); 
00134 
00135   fMomentumDir = pMomentum.unit();
00136 
00137   fDistanceAlongCurve= s_curve;
00138 
00139   return *this;
00140 } 
00141 
00142 inline
00143 G4ThreeVector G4FieldTrack::GetPosition() const
00144 {
00145    G4ThreeVector myPosition( SixVector[0], SixVector[1], SixVector[2] );
00146    return myPosition;
00147 } 
00148 
00149 inline
00150 void G4FieldTrack::SetPosition( G4ThreeVector pPosition) 
00151 {
00152    SixVector[0] = pPosition.x(); 
00153    SixVector[1] = pPosition.y(); 
00154    SixVector[2] = pPosition.z(); 
00155 } 
00156 
00157 inline
00158 const G4ThreeVector& G4FieldTrack::GetMomentumDir() const 
00159 {
00160    // G4ThreeVector myMomentum( SixVector[3], SixVector[4], SixVector[5] );
00161    // return myVelocity;
00162    return fMomentumDir;
00163 } 
00164 
00165 inline
00166 G4ThreeVector G4FieldTrack::GetMomentumDirection() const 
00167 {
00168    return fMomentumDir;
00169 } 
00170 
00171 inline
00172 G4double  G4FieldTrack::GetCurveLength() const 
00173 {
00174      return  fDistanceAlongCurve;  
00175 }
00176 
00177 inline
00178 void G4FieldTrack::SetCurveLength(G4double nCurve_s)
00179 {
00180      fDistanceAlongCurve= nCurve_s;  
00181 }
00182 
00183 inline
00184 G4double  G4FieldTrack::GetKineticEnergy() const
00185 {
00186    return fKineticEnergy;
00187 }
00188 
00189 inline
00190 void G4FieldTrack::SetKineticEnergy(G4double newKinEnergy)
00191 {
00192    fKineticEnergy=newKinEnergy;
00193 }
00194 
00195 inline
00196 G4ThreeVector G4FieldTrack::GetSpin() const
00197 {
00198    return fSpin;
00199 }
00200 
00201 inline
00202 void G4FieldTrack::SetSpin(G4ThreeVector nSpin)
00203 {
00204    fSpin=nSpin;
00205 }
00206 
00207 inline
00208 G4double G4FieldTrack::GetLabTimeOfFlight() const
00209 {
00210    return fLabTimeOfFlight;
00211 }
00212 
00213 inline
00214 void G4FieldTrack::SetLabTimeOfFlight(G4double nTOF)
00215 {
00216    fLabTimeOfFlight=nTOF;
00217 }
00218 
00219 inline
00220 G4double  G4FieldTrack::GetProperTimeOfFlight() const
00221 {
00222    return fProperTimeOfFlight;
00223 }
00224 
00225 inline
00226 void G4FieldTrack::SetProperTimeOfFlight(G4double nTOF)
00227 {
00228    fProperTimeOfFlight=nTOF;
00229 }
00230 
00231 inline
00232 void G4FieldTrack::SetMomentumDir(G4ThreeVector newMomDir)
00233 {
00234    fMomentumDir= newMomDir;
00235 }
00236 
00237 inline
00238 G4ThreeVector G4FieldTrack::GetMomentum() const 
00239 {
00240    return G4ThreeVector( SixVector[3], SixVector[4], SixVector[5] );
00241 } 
00242 
00243 inline
00244 void G4FieldTrack::SetMomentum(G4ThreeVector pMomentum)
00245 {
00246   SixVector[3] = pMomentum.x(); 
00247   SixVector[4] = pMomentum.y(); 
00248   SixVector[5] = pMomentum.z(); 
00249 
00250   fMomentumDir = pMomentum.unit(); 
00251 }
00252 
00253 inline
00254 G4double G4FieldTrack::GetCharge() const
00255 {
00256   return fChargeState.GetCharge();
00257 }
00258 
00259 // Dump values to array
00260 //  
00261 //   note that momentum direction is not saved 
00262 
00263 inline
00264 void G4FieldTrack::DumpToArray(G4double valArr[ncompSVEC] ) const
00265 {
00266   valArr[0]=SixVector[0];
00267   valArr[1]=SixVector[1];
00268   valArr[2]=SixVector[2];
00269   valArr[3]=SixVector[3];
00270   valArr[4]=SixVector[4];
00271   valArr[5]=SixVector[5];
00272 
00273   G4ThreeVector Momentum(valArr[3],valArr[4],valArr[5]);
00274 
00275   // G4double mass_in_Kg;
00276   // mass_in_Kg = fEnergy / velocity_mag_sq * (1-velocity_mag_sq/c_squared);
00277   // valArr[6]= mass_in_Kg;
00278 
00279   // The following components may or may not be integrated.
00280   valArr[6]= fKineticEnergy; 
00281 
00282   // valArr[6]=fEnergy;  // When it is integrated over, do this ...
00283   valArr[7]=fLabTimeOfFlight;
00284   valArr[8]=fProperTimeOfFlight;
00285   valArr[9]=fSpin.x();
00286   valArr[10]=fSpin.y();
00287   valArr[11]=fSpin.z();
00288   // valArr[13]=fMomentumDir.x(); 
00289   // valArr[14]=fMomentumDir.y();
00290   // valArr[15]=fMomentumDir.z();
00291   // valArr[]=fDistanceAlongCurve; 
00292 }
00293 
00294 // Load values from array
00295 //  
00296 //   note that momentum direction must-be/is normalised
00297 
00298 inline
00299 void G4FieldTrack::LoadFromArray(const G4double valArrIn[ncompSVEC], G4int noVarsIntegrated)
00300 {
00301   G4int i;
00302 
00303   // Fill the variables not integrated with zero -- so it's clear !!
00304   static G4double valArr[ncompSVEC];
00305   for( i=0; i<noVarsIntegrated; i++){
00306      valArr[i]= valArrIn[i];
00307   }
00308   for( i=noVarsIntegrated; i<ncompSVEC; i++) {
00309      valArr[i]= 0.0; 
00310   }
00311 
00312   SixVector[0]=valArr[0];
00313   SixVector[1]=valArr[1];
00314   SixVector[2]=valArr[2];
00315   SixVector[3]=valArr[3];
00316   SixVector[4]=valArr[4];
00317   SixVector[5]=valArr[5];
00318 
00319   G4ThreeVector Momentum(valArr[3],valArr[4],valArr[5]);
00320 
00321   G4double momentum_square= Momentum.mag2();
00322   fMomentumDir= Momentum.unit();
00323 
00324   fKineticEnergy = momentum_square / 
00325                    (std::sqrt(momentum_square+fRestMass_c2*fRestMass_c2)
00326                      + fRestMass_c2 ); 
00327   // The above equation is stable for small and large momenta
00328 
00329   // The following components may or may not be
00330   //    integrated over -- integration is optional
00331   // fKineticEnergy= valArr[6];
00332 
00333   fLabTimeOfFlight=valArr[7];
00334   fProperTimeOfFlight=valArr[8];
00335   fSpin=G4ThreeVector(valArr[9],valArr[10],valArr[11]);
00336   // fMomentumDir=G4ThreeVector(valArr[13],valArr[14],valArr[15]);
00337   // fDistanceAlongCurve= valArr[]; 
00338 }
00339   
00340 inline
00341 G4FieldTrack & G4FieldTrack::operator = ( const G4FieldTrack& rStVec )
00342 {
00343   if (&rStVec == this) return *this;
00344 
00345   SixVector[0]= rStVec.SixVector[0];
00346   SixVector[1]= rStVec.SixVector[1];
00347   SixVector[2]= rStVec.SixVector[2];
00348   SixVector[3]= rStVec.SixVector[3];
00349   SixVector[4]= rStVec.SixVector[4];
00350   SixVector[5]= rStVec.SixVector[5];
00351   SetCurveLength( rStVec.GetCurveLength() );
00352 
00353   fKineticEnergy= rStVec.fKineticEnergy;
00354   SetLabTimeOfFlight( rStVec.GetLabTimeOfFlight()  ); 
00355   SetProperTimeOfFlight( rStVec.GetProperTimeOfFlight()  ); 
00356   SetSpin( rStVec.GetSpin() );
00357   fMomentumDir= rStVec.fMomentumDir;
00358 
00359   fChargeState= rStVec.fChargeState;
00360   // (*fpChargeState)= *(rStVec.fpChargeState);
00361   // fpChargeState= rStVec.fpChargeState; // Handles!!
00362   return *this;
00363 }
00364 
00365 inline void 
00366 G4FieldTrack::UpdateFourMomentum( G4double             kineticEnergy, 
00367                                   const G4ThreeVector& momentumDirection )
00368 {
00369   G4double momentum_mag  = std::sqrt(kineticEnergy*kineticEnergy
00370                             +2.0*fRestMass_c2*kineticEnergy);
00371   G4ThreeVector momentumVector= momentum_mag * momentumDirection; 
00372 
00373   // SetMomentum( momentumVector );  // Set direction (from unit): used sqrt, div
00374   SixVector[3] = momentumVector.x(); 
00375   SixVector[4] = momentumVector.y(); 
00376   SixVector[5] = momentumVector.z(); 
00377 
00378   fMomentumDir=   momentumDirection; // Set directly to avoid inaccuracy.
00379   fKineticEnergy= kineticEnergy;
00380 }
00381 
00382 inline void G4FieldTrack::UpdateState( const G4ThreeVector& position, 
00383                                 G4double             laboratoryTimeOfFlight,
00384                                 const G4ThreeVector& momentumDirection,
00385                                 G4double             kineticEnergy
00386                               )
00387 { 
00388   // SetCurvePnt( position, momentumVector, s_curve=0.0);     
00389   SetPosition( position); 
00390   fLabTimeOfFlight= laboratoryTimeOfFlight;
00391   fDistanceAlongCurve= 0.0;
00392 
00393   UpdateFourMomentum( kineticEnergy, momentumDirection); 
00394 }

Generated on Mon May 27 17:48:16 2013 for Geant4 by  doxygen 1.4.7