Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4RepleteEofM Class Reference

G4RepleteEofM is the right-hand side of equation of motion in a combined field, including: magnetic, electric, gravity, and gradient B field, as well as spin tracking. More...

#include <G4RepleteEofM.hh>

Inheritance diagram for G4RepleteEofM:

Public Member Functions

 G4RepleteEofM (G4Field *field, G4int nvar=8)
 ~G4RepleteEofM () override=default
void SetChargeMomentumMass (G4ChargeState particleCharge, G4double MomentumXc, G4double mass) override
void EvaluateRhsGivenB (const G4double y[], const G4double Field[], G4double dydx[]) const override
void SetAnomaly (G4double a)
G4double GetAnomaly () const
void SetBField ()
void SetEField ()
void SetgradB ()
void SetSpin ()
Public Member Functions inherited from G4EquationOfMotion
 G4EquationOfMotion (G4Field *Field)
virtual ~G4EquationOfMotion ()=default
virtual void EvaluateRhsGivenB (const G4double y[], const G4double B[3], G4double dydx[]) const =0
virtual G4EquationType GetEquationType () const
void RightHandSide (const G4double y[], G4double dydx[]) const
void EvaluateRhsReturnB (const G4double y[], G4double dydx[], G4double Field[]) const
void GetFieldValue (const G4double Point[4], G4double Field[]) const
const G4FieldGetFieldObj () const
G4FieldGetFieldObj ()
void SetFieldObj (G4Field *pField)

Detailed Description

G4RepleteEofM is the right-hand side of equation of motion in a combined field, including: magnetic, electric, gravity, and gradient B field, as well as spin tracking.

Definition at line 50 of file G4RepleteEofM.hh.

Constructor & Destructor Documentation

◆ G4RepleteEofM()

G4RepleteEofM::G4RepleteEofM ( G4Field * field,
G4int nvar = 8 )

Constructor for G4EquationOfMotion.

Parameters
[in]fieldPointer to the field.
[in]nvarThe number of integration variables.

Definition at line 40 of file G4RepleteEofM.cc.

41 : G4EquationOfMotion( field ), fNvar(nvar)
42{
43 fGfield = field->IsGravityActive();
44}
G4EquationOfMotion(G4Field *Field)
G4bool IsGravityActive() const
Definition G4Field.hh:121

◆ ~G4RepleteEofM()

G4RepleteEofM::~G4RepleteEofM ( )
overridedefault

Default Destructor.

Member Function Documentation

◆ EvaluateRhsGivenB()

void G4RepleteEofM::EvaluateRhsGivenB ( const G4double y[],
const G4double Field[],
G4double dydx[] ) const
override

Calculates the value of the derivative, given the value of the field.

Parameters
[in]yCoefficients array.
[in]FieldField value.
[out]dydxDerivatives array.

Definition at line 79 of file G4RepleteEofM.cc.

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

◆ GetAnomaly()

G4double G4RepleteEofM::GetAnomaly ( ) const
inline

Definition at line 91 of file G4RepleteEofM.hh.

91{ return anomaly; }

◆ SetAnomaly()

void G4RepleteEofM::SetAnomaly ( G4double a)
inline

Setter and getter for the magnetic anomaly.

Definition at line 90 of file G4RepleteEofM.hh.

90{ anomaly = a; }

◆ SetBField()

void G4RepleteEofM::SetBField ( )
inline

Modifiers.

Definition at line 96 of file G4RepleteEofM.hh.

96{ fBfield = true; }

◆ SetChargeMomentumMass()

void G4RepleteEofM::SetChargeMomentumMass ( G4ChargeState particleCharge,
G4double MomentumXc,
G4double mass )
overridevirtual

Sets the charge, momentum and mass of the current particle. Used to set the equation's coefficients.

Parameters
[in]particleChargeMagnetic charge and moments in e+ units.
[in]MomentumXcParticle momentum.
[in]massParticle mass.

Implements G4EquationOfMotion.

Definition at line 47 of file G4RepleteEofM.cc.

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}
G4double GetCharge() const
G4double GetMagneticDipoleMoment() const
G4double GetSpin() const
T sqr(const T &x)
Definition templates.hh:128

◆ SetEField()

void G4RepleteEofM::SetEField ( )
inline

Definition at line 97 of file G4RepleteEofM.hh.

97{ fEfield = true; }

◆ SetgradB()

void G4RepleteEofM::SetgradB ( )
inline

Definition at line 98 of file G4RepleteEofM.hh.

98{ fgradB = true; }

◆ SetSpin()

void G4RepleteEofM::SetSpin ( )
inline

Definition at line 99 of file G4RepleteEofM.hh.

99{ fSpin = true; }

The documentation for this class was generated from the following files: