G4Mag_SpinEqRhs.cc

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: G4Mag_SpinEqRhs.cc 69970 2013-05-21 10:14:30Z gcosmo $
00028 //
00029 // This is the standard right-hand side for equation of motion.
00030 // This version of the right-hand side includes the three components
00031 // of the particle's spin.
00032 //
00033 //            J. Apostolakis, February 8th, 1999
00034 //            P. Gumplinger,  February 8th, 1999
00035 //            D. Cote-Ahern, P. Gumplinger,  April 11th, 2001
00036 //
00037 // --------------------------------------------------------------------
00038 
00039 #include "G4Mag_SpinEqRhs.hh"
00040 #include "G4PhysicalConstants.hh"
00041 #include "G4SystemOfUnits.hh"
00042 #include "G4MagneticField.hh"
00043 #include "G4ThreeVector.hh"
00044 
00045 G4Mag_SpinEqRhs::G4Mag_SpinEqRhs( G4MagneticField* MagField )
00046   : G4Mag_EqRhs( MagField ), omegac(0.), anomaly(0.0011659208),
00047     pcharge(0.), E(0.), gamma(0.), beta(0.)
00048 {
00049 }
00050 
00051 G4Mag_SpinEqRhs::~G4Mag_SpinEqRhs()
00052 {
00053 }
00054 
00055 void
00056 G4Mag_SpinEqRhs::SetChargeMomentumMass(G4double particleCharge, // in e+ units
00057                                        G4double MomentumXc,
00058                                        G4double particleMass)
00059 {
00060    //  To set fCof_val 
00061    G4Mag_EqRhs::SetChargeMomentumMass(particleCharge, MomentumXc, particleMass);
00062 
00063    omegac = (eplus/particleMass)*c_light;
00064 
00065    pcharge = particleCharge;
00066 
00067    E = std::sqrt(sqr(MomentumXc)+sqr(particleMass));
00068    beta  = MomentumXc/E;
00069    gamma = E/particleMass;
00070 
00071    G4double neutronAnomaly = -2.9156797;
00072    if (pcharge==0.) SetAnomaly(neutronAnomaly);
00073 }
00074 
00075 void
00076 G4Mag_SpinEqRhs::EvaluateRhsGivenB( const G4double y[],
00077                                     const G4double B[3],
00078                                           G4double dydx[] ) const
00079 {
00080    G4double momentum_mag_square = sqr(y[3]) + sqr(y[4]) + sqr(y[5]);
00081    G4double inv_momentum_magnitude = 1.0 / std::sqrt( momentum_mag_square );
00082    G4double cof = FCof()*inv_momentum_magnitude;
00083 
00084    dydx[0] = y[3] * inv_momentum_magnitude;       //  (d/ds)x = Vx/V
00085    dydx[1] = y[4] * inv_momentum_magnitude;       //  (d/ds)y = Vy/V
00086    dydx[2] = y[5] * inv_momentum_magnitude;       //  (d/ds)z = Vz/V
00087 
00088    if (pcharge == 0.) {
00089       dydx[3] = 0.;
00090       dydx[4] = 0.;
00091       dydx[5] = 0.;
00092    } else {
00093       dydx[3] = cof*(y[4]*B[2] - y[5]*B[1]) ;   // Ax = a*(Vy*Bz - Vz*By)
00094       dydx[4] = cof*(y[5]*B[0] - y[3]*B[2]) ;   // Ay = a*(Vz*Bx - Vx*Bz)
00095       dydx[5] = cof*(y[3]*B[1] - y[4]*B[0]) ;   // Az = a*(Vx*By - Vy*Bx)
00096    }
00097 
00098    G4ThreeVector u(y[3], y[4], y[5]);
00099    u *= inv_momentum_magnitude; 
00100 
00101    G4ThreeVector BField(B[0],B[1],B[2]);
00102 
00103    G4double udb = anomaly*beta*gamma/(1.+gamma) * (BField * u); 
00104    G4double ucb = (anomaly+1./gamma)/beta;
00105 
00106    // Initialise the values of dydx that we do not update.
00107    dydx[6] = dydx[7] = dydx[8] = 0.0;
00108 
00109    G4ThreeVector Spin(y[9],y[10],y[11]);
00110 
00111    G4ThreeVector dSpin;
00112 
00113    if (pcharge == 0.) {
00114       // dSpin = (3.8260837/2.)*omegac*(Spin.cross(BField));
00115       dSpin = omegac*(ucb*(Spin.cross(BField))-udb*(Spin.cross(u)));
00116    } else {
00117       dSpin = pcharge*omegac*(ucb*(Spin.cross(BField))-udb*(Spin.cross(u)));
00118    }
00119 
00120    dydx[ 9] = dSpin.x();
00121    dydx[10] = dSpin.y();
00122    dydx[11] = dSpin.z();
00123 
00124    return ;
00125 }

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