84{
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111 G4double momentum_mag_square = y[3]*y[3] + y[4]*y[4] + y[5]*y[5];
112 G4double inv_momentum_magnitude = 1.0 / std::sqrt( momentum_mag_square );
113
114 G4double Energy = std::sqrt(momentum_mag_square + mass*mass);
115 G4double inverse_velocity = Energy*inv_momentum_magnitude/c_light;
116
117 G4double cof1 = ElectroMagCof*inv_momentum_magnitude;
119 G4double cof3 = inv_momentum_magnitude*mass;
120
121 dydx[0] = y[3]*inv_momentum_magnitude;
122 dydx[1] = y[4]*inv_momentum_magnitude;
123 dydx[2] = y[5]*inv_momentum_magnitude;
124
125 dydx[3] = 0.;
126 dydx[4] = 0.;
127 dydx[5] = 0.;
128
129 G4double field[18] = {0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.};
130
131 field[0] = Field[0];
132 field[1] = Field[1];
133 field[2] = Field[2];
134
135
136
137 if (fBfield)
138 {
139 if (charge != 0.)
140 {
141 dydx[3] += cof1*(y[4]*field[2] - y[5]*field[1]);
142 dydx[4] += cof1*(y[5]*field[0] - y[3]*field[2]);
143 dydx[5] += cof1*(y[3]*field[1] - y[4]*field[0]);
144 }
145 }
146
147
148
149 if (!fBfield)
150 {
151 field[3] = Field[0];
152 field[4] = Field[1];
153 field[5] = Field[2];
154 }
155 else
156 {
157 field[3] = Field[3];
158 field[4] = Field[4];
159 field[5] = Field[5];
160 }
161
162 if (fEfield)
163 {
164 if (charge != 0.)
165 {
166 dydx[3] += cof1*cof2*field[3];
167 dydx[4] += cof1*cof2*field[4];
168 dydx[5] += cof1*cof2*field[5];
169 }
170 }
171
172
173
174 if (!fBfield && !fEfield)
175 {
176 field[6] = Field[0];
177 field[7] = Field[1];
178 field[8] = Field[2];
179 }
180 else
181 {
182 field[6] = Field[6];
183 field[7] = Field[7];
184 field[8] = Field[8];
185 }
186
187 if (fGfield)
188 {
189 if (mass > 0.)
190 {
191 dydx[3] += field[6]*cof2*cof3/c_light;
192 dydx[4] += field[7]*cof2*cof3/c_light;
193 dydx[5] += field[8]*cof2*cof3/c_light;
194 }
195 }
196
197
198
199 if (!fBfield && !fEfield && !fGfield)
200 {
201 field[9] = Field[0];
202 field[10] = Field[1];
203 field[11] = Field[2];
204 field[12] = Field[3];
205 field[13] = Field[4];
206 field[14] = Field[5];
207 field[15] = Field[6];
208 field[16] = Field[7];
209 field[17] = Field[8];
210 }
211 else
212 {
213 field[9] = Field[9];
214 field[10] = Field[10];
215 field[11] = Field[11];
216 field[12] = Field[12];
217 field[13] = Field[13];
218 field[14] = Field[14];
219 field[15] = Field[15];
220 field[16] = Field[16];
221 field[17] = Field[17];
222 }
223
224 if (fgradB)
225 {
226 if (magMoment != 0.)
227 {
228 dydx[3] += magMoment*(y[9]*field[ 9]+y[10]*field[10]+y[11]*field[11])
229 *inv_momentum_magnitude*Energy;
230 dydx[4] += magMoment*(y[9]*field[12]+y[10]*field[13]+y[11]*field[14])
231 *inv_momentum_magnitude*Energy;
232 dydx[5] += magMoment*(y[9]*field[15]+y[10]*field[16]+y[11]*field[17])
233 *inv_momentum_magnitude*Energy;
234 }
235 }
236
237 dydx[6] = 0.;
238
239
240
241 dydx[7] = inverse_velocity;
242
243 if (fNvar == 12)
244 {
245 dydx[ 8] = 0.;
246
247 dydx[ 9] = 0.;
248 dydx[10] = 0.;
249 dydx[11] = 0.;
250 }
251
252 if (fSpin)
253 {
255 if (fBfield)
256 {
258 BField = F;
259 }
260
262 if (fEfield)
263 {
265 EField = F;
266 }
267
268 EField /= c_light;
269
271 u *= inv_momentum_magnitude;
272
273 G4double udb = anomaly*beta*gamma/(1.+gamma) * (BField * u);
274 G4double ucb = (anomaly+1./gamma)/beta;
275 G4double uce = anomaly + 1./(gamma+1.);
276
278
280 if (charge == 0.)
281 {
282 pcharge = 1.;
283 }
284 else
285 {
286 pcharge = charge;
287 }
288
290 if (
Spin.mag2() != 0.)
291 {
292 if (fBfield)
293 {
294 dSpin =
295 pcharge*omegac*( ucb*(
Spin.cross(BField))-udb*(
Spin.cross(u)) );
296 }
297 if (fEfield)
298 {
299 dSpin -= pcharge*omegac*( uce*(u*(
Spin*EField) - EField*(
Spin*u)) );
300
301
302
303 }
304 }
305
306 dydx[ 9] = dSpin.x();
307 dydx[10] = dSpin.y();
308 dydx[11] = dSpin.z();
309 }
310
311 return;
312}