Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RepleteEofM.cc
Go to the documentation of this file.
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// G4RepleteEofM implementation
27//
28// Author: Peter Gumplinger (TRIUMF), 08.04.2013
29// -------------------------------------------------------------------
30
31#include "G4RepleteEofM.hh"
32#include "G4Field.hh"
33#include "G4ThreeVector.hh"
34#include "globals.hh"
35
37#include "G4SystemOfUnits.hh"
38
39
41 : G4EquationOfMotion( field ), fNvar(nvar)
42{
43 fGfield = field->IsGravityActive();
44}
45
46void
48 G4double MomentumXc,
49 G4double particleMass)
50{
51 charge = particleCharge.GetCharge();
52 mass = particleMass;
53 magMoment = particleCharge.GetMagneticDipoleMoment();
54 spin = particleCharge.GetSpin();
55
56 ElectroMagCof = eplus*charge*c_light;
57 omegac = (eplus/mass)*c_light;
58
59 G4double muB = 0.5*eplus*hbar_Planck/(mass/c_squared);
60
61 G4double g_BMT;
62 if ( spin != 0. )
63 {
64 g_BMT = (std::abs(magMoment)/muB)/spin;
65 }
66 else
67 {
68 g_BMT = 2.;
69 }
70
71 anomaly = (g_BMT - 2.)/2.;
72
73 G4double E = std::sqrt(sqr(MomentumXc)+sqr(mass));
74 beta = MomentumXc/E;
75 gamma = E/mass;
76}
77
78void
80 const G4double Field[],
81 G4double dydx[] ) const
82{
83
84 // Components of y:
85 // 0-2 dr/ds,
86 // 3-5 dp/ds - momentum derivatives
87 // 9-11 dSpin/ds = (1/beta) dSpin/dt - spin derivatives
88 //
89 // The BMT equation, following J.D.Jackson, Classical
90 // Electrodynamics, Second Edition,
91 // dS/dt = (e/mc) S \cross
92 // [ (g/2-1 +1/\gamma) B
93 // -(g/2-1)\gamma/(\gamma+1) (\beta \cdot B)\beta
94 // -(g/2-\gamma/(\gamma+1) \beta \cross E ]
95 // where
96 // S = \vec{s}, where S^2 = 1
97 // B = \vec{B}
98 // \beta = \vec{\beta} = \beta \vec{u} with u^2 = 1
99 // E = \vec{E}
100 //
101 // Field[0,1,2] are the magnetic field components
102 // Field[3,4,5] are the electric field components
103 // Field[6,7,8] are the gravity field components
104 // The Field[] array may trivially be extended to 18 components
105 // Field[ 9] == dB_x/dx; Field[10] == dB_y/dx; Field[11] == dB_z/dx
106 // Field[12] == dB_x/dy; Field[13] == dB_y/dy; Field[14] == dB_z/dy
107 // Field[15] == dB_x/dz; Field[16] == dB_y/dz; Field[17] == dB_z/dz
108
109 G4double momentum_mag_square = y[3]*y[3] + y[4]*y[4] + y[5]*y[5];
110 G4double inv_momentum_magnitude = 1.0 / std::sqrt( momentum_mag_square );
111
112 G4double Energy = std::sqrt(momentum_mag_square + mass*mass);
113 G4double inverse_velocity = Energy*inv_momentum_magnitude/c_light;
114
115 G4double cof1 = ElectroMagCof*inv_momentum_magnitude;
116 G4double cof2 = Energy/c_light;
117 G4double cof3 = inv_momentum_magnitude*mass;
118
119 dydx[0] = y[3]*inv_momentum_magnitude; // (d/ds)x = Vx/V
120 dydx[1] = y[4]*inv_momentum_magnitude; // (d/ds)y = Vy/V
121 dydx[2] = y[5]*inv_momentum_magnitude; // (d/ds)z = Vz/V
122
123 dydx[3] = 0.;
124 dydx[4] = 0.;
125 dydx[5] = 0.;
126
127 G4double field[18] = {0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
128
129 field[0] = Field[0];
130 field[1] = Field[1];
131 field[2] = Field[2];
132
133 // Force due to B field - Field[0,1,2]
134
135 if (fBfield)
136 {
137 if (charge != 0.)
138 {
139 dydx[3] += cof1*(y[4]*field[2] - y[5]*field[1]);
140 dydx[4] += cof1*(y[5]*field[0] - y[3]*field[2]);
141 dydx[5] += cof1*(y[3]*field[1] - y[4]*field[0]);
142 }
143 }
144
145 // add force due to E field - Field[3,4,5]
146
147 if (!fBfield)
148 {
149 field[3] = Field[0];
150 field[4] = Field[1];
151 field[5] = Field[2];
152 }
153 else
154 {
155 field[3] = Field[3];
156 field[4] = Field[4];
157 field[5] = Field[5];
158 }
159
160 if (fEfield)
161 {
162 if (charge != 0.)
163 {
164 dydx[3] += cof1*cof2*field[3];
165 dydx[4] += cof1*cof2*field[4];
166 dydx[5] += cof1*cof2*field[5];
167 }
168 }
169
170 // add force due to gravity field - Field[6,7,8]
171
172 if (!fBfield && !fEfield)
173 {
174 field[6] = Field[0];
175 field[7] = Field[1];
176 field[8] = Field[2];
177 }
178 else
179 {
180 field[6] = Field[6];
181 field[7] = Field[7];
182 field[8] = Field[8];
183 }
184
185 if (fGfield)
186 {
187 if (mass > 0.)
188 {
189 dydx[3] += field[6]*cof2*cof3/c_light;
190 dydx[4] += field[7]*cof2*cof3/c_light;
191 dydx[5] += field[8]*cof2*cof3/c_light;
192 }
193 }
194
195 // add force
196
197 if (!fBfield && !fEfield && !fGfield)
198 {
199 field[9] = Field[0];
200 field[10] = Field[1];
201 field[11] = Field[2];
202 field[12] = Field[3];
203 field[13] = Field[4];
204 field[14] = Field[5];
205 field[15] = Field[6];
206 field[16] = Field[7];
207 field[17] = Field[8];
208 }
209 else
210 {
211 field[9] = Field[9];
212 field[10] = Field[10];
213 field[11] = Field[11];
214 field[12] = Field[12];
215 field[13] = Field[13];
216 field[14] = Field[14];
217 field[15] = Field[15];
218 field[16] = Field[16];
219 field[17] = Field[17];
220 }
221
222 if (fgradB)
223 {
224 if (magMoment != 0.)
225 {
226 dydx[3] += magMoment*(y[9]*field[ 9]+y[10]*field[10]+y[11]*field[11])
227 *inv_momentum_magnitude*Energy;
228 dydx[4] += magMoment*(y[9]*field[12]+y[10]*field[13]+y[11]*field[14])
229 *inv_momentum_magnitude*Energy;
230 dydx[5] += magMoment*(y[9]*field[15]+y[10]*field[16]+y[11]*field[17])
231 *inv_momentum_magnitude*Energy;
232 }
233 }
234
235 dydx[6] = 0.; // not used
236
237 // Lab Time of flight
238 //
239 dydx[7] = inverse_velocity;
240
241 if (fNvar == 12)
242 {
243 dydx[ 8] = 0.; //not used
244
245 dydx[ 9] = 0.;
246 dydx[10] = 0.;
247 dydx[11] = 0.;
248 }
249
250 if (fSpin)
251 {
252 G4ThreeVector BField(0.,0.,0.);
253 if (fBfield)
254 {
255 G4ThreeVector F(field[0],field[1],field[2]);
256 BField = F;
257 }
258
259 G4ThreeVector EField(0.,0.,0.);
260 if (fEfield)
261 {
262 G4ThreeVector F(field[3],field[4],field[5]);
263 EField = F;
264 }
265
266 EField /= c_light;
267
268 G4ThreeVector u(y[3], y[4], y[5]);
269 u *= inv_momentum_magnitude;
270
271 G4double udb = anomaly*beta*gamma/(1.+gamma) * (BField * u);
272 G4double ucb = (anomaly+1./gamma)/beta;
273 G4double uce = anomaly + 1./(gamma+1.);
274
275 G4ThreeVector Spin(y[9],y[10],y[11]);
276
277 G4double pcharge;
278 if (charge == 0.)
279 {
280 pcharge = 1.;
281 }
282 else
283 {
284 pcharge = charge;
285 }
286
287 G4ThreeVector dSpin(0.,0.,0);
288 if (Spin.mag2() != 0.)
289 {
290 if (fBfield)
291 {
292 dSpin =
293 pcharge*omegac*( ucb*(Spin.cross(BField))-udb*(Spin.cross(u)) );
294 }
295 if (fEfield)
296 {
297 dSpin -= pcharge*omegac*( uce*(u*(Spin*EField) - EField*(Spin*u)) );
298 // from Jackson
299 // -uce*Spin.cross(u.cross(EField)) );
300 // but this form has one less operation
301 }
302 }
303
304 dydx[ 9] = dSpin.x();
305 dydx[10] = dSpin.y();
306 dydx[11] = dSpin.z();
307 }
308
309 return;
310}
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
double z() const
double x() const
double y() const
G4ChargeState is a container for magnetic charge and moments.
G4double GetCharge() const
G4double GetMagneticDipoleMoment() const
G4double GetSpin() const
G4EquationOfMotion(G4Field *Field)
G4Field is the abstract class for any kind of field. It allows any kind of field (vector,...
Definition G4Field.hh:67
G4bool IsGravityActive() const
Definition G4Field.hh:121
void EvaluateRhsGivenB(const G4double y[], const G4double Field[], G4double dydx[]) const override
G4RepleteEofM(G4Field *field, G4int nvar=8)
void SetChargeMomentumMass(G4ChargeState particleCharge, G4double MomentumXc, G4double mass) override
T sqr(const T &x)
Definition templates.hh:128