Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* << 3 // * License and Disclaimer << 4 // * << 5 // * The Geant4 software is copyright of th << 6 // * the Geant4 Collaboration. It is provided << 7 // * conditions of the Geant4 Software License << 8 // * LICENSE and available at http://cern.ch/ << 9 // * include a list of copyright holders. << 10 // * << 11 // * Neither the authors of this software syst << 12 // * institutes,nor the agencies providing fin << 13 // * work make any representation or warran << 14 // * regarding this software system or assum << 15 // * use. Please see the license in the file << 16 // * for the full disclaimer and the limitatio << 17 // * << 18 // * This code implementation is the result << 19 // * technical work of the GEANT4 collaboratio << 20 // * By using, copying, modifying or distri << 21 // * any work based on the software) you ag << 22 // * use in resulting scientific publicati << 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* << 25 // 2 // 26 // G4Mag_SpinEqRhs implementation << 3 // This is the standard right-hand side for equation of motion. >> 4 // This version of the right-hand side includes >> 5 // the three components of the particle's spin. >> 6 // >> 7 // J. Apostolakis, February 8th, 1999 >> 8 // P. Gumplinger, February 8th, 1999 27 // 9 // 28 // Created: J.Apostolakis, P.Gumplinger - 08.0 << 29 // ------------------------------------------- << 30 << 31 #include "G4Mag_SpinEqRhs.hh" 10 #include "G4Mag_SpinEqRhs.hh" 32 #include "G4PhysicalConstants.hh" << 33 #include "G4SystemOfUnits.hh" << 34 #include "G4MagneticField.hh" << 35 #include "G4ThreeVector.hh" 11 #include "G4ThreeVector.hh" 36 << 12 #include "globals.hh" 37 G4Mag_SpinEqRhs::G4Mag_SpinEqRhs( G4MagneticFi << 38 : G4Mag_EqRhs( MagField ) << 39 { << 40 } << 41 << 42 G4Mag_SpinEqRhs::~G4Mag_SpinEqRhs() = default; << 43 13 44 void 14 void 45 G4Mag_SpinEqRhs::SetChargeMomentumMass(G4Charg << 15 G4Mag_SpinEqRhs::SetChargeMomentumMass(const G4double particleCharge, // in e+ units 46 G4doubl << 16 const G4double MomentumXc, 47 G4doubl << 17 const G4double mass) 48 { 18 { 49 G4Mag_EqRhs::SetChargeMomentumMass( particl << 19 // To set fCof_val 50 << 20 G4Mag_EqRhs::SetChargeMomentumMass(particleCharge, MomentumXc, mass); 51 charge = particleCharge.GetCharge(); << 52 mass = particleMass; << 53 magMoment = particleCharge.GetMagneticDipol << 54 spin = particleCharge.GetSpin(); << 55 << 56 omegac = (eplus/mass)*c_light; << 57 << 58 G4double muB = 0.5*eplus*hbar_Planck/(mass/ << 59 21 60 G4double g_BMT; << 22 omegac = 0.105658387*GeV/mass * 2.837374841e-3*(rad/cm/kilogauss); 61 if ( spin != 0. ) << 23 anomaly = 1.165923e-3; 62 { << 24 ParticleCharge = particleCharge; 63 g_BMT = (std::abs(magMoment)/muB)/spin; << 64 } << 65 else << 66 { << 67 g_BMT = 2.; << 68 } << 69 << 70 anomaly = (g_BMT - 2.)/2.; << 71 25 72 G4double E = std::sqrt(sqr(MomentumXc)+sqr( << 26 // for testing only 73 beta = MomentumXc/E; << 27 anomaly = 0.0; 74 gamma = E/mass; << 75 } 28 } 76 29 77 void 30 void 78 G4Mag_SpinEqRhs::EvaluateRhsGivenB( const G4do 31 G4Mag_SpinEqRhs::EvaluateRhsGivenB( const G4double y[], 79 const G4do << 32 const G4double B[3], 80 G4do << 33 G4double dydx[] ) const 81 { 34 { 82 G4double momentum_mag_square = sqr(y[3]) + << 35 G4double velocity_mag_square = sqr(y[3]) + sqr(y[4]) + sqr(y[5]); 83 G4double inv_momentum_magnitude = 1.0 / std << 36 G4double inv_velocity_magnitude = 1.0 / sqrt( velocity_mag_square ); 84 G4double cof = FCof()*inv_momentum_magnitud << 85 << 86 dydx[0] = y[3] * inv_momentum_magnitude; << 87 dydx[1] = y[4] * inv_momentum_magnitude; << 88 dydx[2] = y[5] * inv_momentum_magnitude; << 89 << 90 if (charge == 0.) << 91 { << 92 dydx[3] = 0.; << 93 dydx[4] = 0.; << 94 dydx[5] = 0.; << 95 } << 96 else << 97 { << 98 dydx[3] = cof*(y[4]*B[2] - y[5]*B[1]) ; << 99 dydx[4] = cof*(y[5]*B[0] - y[3]*B[2]) ; << 100 dydx[5] = cof*(y[3]*B[1] - y[4]*B[0]) ; << 101 } << 102 37 103 G4ThreeVector u(y[3], y[4], y[5]); << 38 dydx[0] = y[3] * inv_velocity_magnitude; // (d/ds)x = Vx/V 104 u *= inv_momentum_magnitude; << 39 dydx[1] = y[4] * inv_velocity_magnitude; // (d/ds)y = Vy/V >> 40 dydx[2] = y[5] * inv_velocity_magnitude; // (d/ds)z = Vz/V >> 41 dydx[3] = FCof()*(y[4]*B[2] - y[5]*B[1]) ; // Ax = a*(Vy*Bz - Vz*By) >> 42 dydx[4] = FCof()*(y[5]*B[0] - y[3]*B[2]) ; // Ay = a*(Vz*Bx - Vx*Bz) >> 43 dydx[5] = FCof()*(y[3]*B[1] - y[4]*B[0]) ; // Az = a*(Vx*By - Vy*Bx) >> 44 >> 45 G4double beta_squared = velocity_mag_square/c_squared; >> 46 G4double beta = sqrt(beta_squared); >> 47 >> 48 G4double gamma; >> 49 >> 50 if (beta < 1.0){ >> 51 gamma = 1. / sqrt( 1. - beta_squared); >> 52 } else { >> 53 beta = 1.0; >> 54 gamma = DBL_MAX; >> 55 } >> 56 >> 57 G4ThreeVector u; >> 58 u.setX(inv_velocity_magnitude*y[3]); >> 59 u.setY(inv_velocity_magnitude*y[4]); >> 60 u.setZ(inv_velocity_magnitude*y[5]); 105 61 106 G4ThreeVector BField(B[0],B[1],B[2]); 62 G4ThreeVector BField(B[0],B[1],B[2]); 107 63 108 G4double udb = anomaly*beta*gamma/(1.+gamma 64 G4double udb = anomaly*beta*gamma/(1.+gamma) * (BField * u); 109 G4double ucb = (anomaly+1./gamma)/beta; 65 G4double ucb = (anomaly+1./gamma)/beta; 110 66 111 // Initialise the values of dydx that we do << 112 dydx[6] = dydx[7] = dydx[8] = 0.0; << 113 << 114 G4ThreeVector Spin(y[9],y[10],y[11]); 67 G4ThreeVector Spin(y[9],y[10],y[11]); 115 68 116 G4double pcharge; << 69 G4ThreeVector dSpin; 117 if (charge == 0.) << 118 { << 119 pcharge = 1.; << 120 } << 121 else << 122 { << 123 pcharge = charge; << 124 } << 125 70 126 G4ThreeVector dSpin(0.,0.,0.); << 71 dSpin = ParticleCharge*omegac*(ucb*(Spin.cross(BField))-udb*(Spin.cross(u))); 127 if (Spin.mag2() != 0.) << 128 { << 129 dSpin = pcharge*omegac*(ucb*(Spin.cross(B << 130 } << 131 72 132 dydx[9] = dSpin.x(); << 73 dydx[ 9] = dSpin.x(); 133 dydx[10] = dSpin.y(); 74 dydx[10] = dSpin.y(); 134 dydx[11] = dSpin.z(); 75 dydx[11] = dSpin.z(); 135 76 136 return; << 77 return ; 137 } 78 } 138 79