44 m_magdistance( distanceConstField ),
77 G4double R[4] = { P[0], P[1] , P[2], P[7] };
78 G4double A[3] = {dPdS[0], dPdS[1], dPdS[2]};
86 const G4double S6 = Step * one_sixth;
94 G4double newmom2 = (P[3]*P[3]+P[4]*P[4]+P[5]*P[5]);
96 if( std::fabs(newmom2 - oldmom2) > perMillion * oldmom2 )
98 m_mom = std::sqrt(newmom2) ;
114 G4double p[4] = {R[0]+S5*(A[0]+S4*K1[0]),
115 R[1]+S5*(A[1]+S4*K1[1]),
116 R[2]+S5*(A[2]+S4*K1[2]),
120 G4double A2[3] = {A[0]+S5*K1[0],A[1]+S5*K1[1],A[2]+S5*K1[2]};
123 (A2[0]*m_lastField[1]-A2[1]*m_lastField[0])*
m_cof};
125 m_mPoint[0]=p[0]; m_mPoint[1]=p[1]; m_mPoint[2]=p[2];
129 G4double A3[3] = {A[0]+S5*K2[0],A[1]+S5*K2[1],A[2]+S5*K2[2]};
130 G4double K3[3] = {(A3[1]*m_lastField[2]-A3[2]*m_lastField[1])*
m_cof,
131 (A3[2]*m_lastField[0]-A3[0]*m_lastField[2])*
m_cof,
132 (A3[0]*m_lastField[1]-A3[1]*m_lastField[0])*
m_cof};
136 p[0] = R[0]+S*(A[0]+S5*K3[0]);
137 p[1] = R[1]+S*(A[1]+S5*K3[1]);
138 p[2] = R[2]+S*(A[2]+S5*K3[2]);
142 G4double A4[3] = {A[0]+S*K3[0],A[1]+S*K3[1],A[2]+S*K3[2]};
143 G4double K4[3] = {(A4[1]*m_lastField[2]-A4[2]*m_lastField[1])*
m_cof,
144 (A4[2]*m_lastField[0]-A4[0]*m_lastField[2])*
m_cof,
145 (A4[0]*m_lastField[1]-A4[1]*m_lastField[0])*
m_cof};
149 Po[0] = P[0]+S*(A[0]+S6*(K1[0]+K2[0]+K3[0]));
150 Po[1] = P[1]+S*(A[1]+S6*(K1[1]+K2[1]+K3[1]));
151 Po[2] = P[2]+S*(A[2]+S6*(K1[2]+K2[2]+K3[2]));
157 Po[3] = A[0]+S6*(K1[0]+K4[0]+2.*(K2[0]+K3[0]));
158 Po[4] = A[1]+S6*(K1[1]+K4[1]+2.*(K2[1]+K3[1]));
159 Po[5] = A[2]+S6*(K1[2]+K4[2]+2.*(K2[2]+K3[2]));
163 Err[3] = S*std::fabs(K1[0]-K2[0]-K3[0]+K4[0]);
164 Err[4] = S*std::fabs(K1[1]-K2[1]-K3[1]+K4[1]);
165 Err[5] = S*std::fabs(K1[2]-K2[2]-K3[2]+K4[2]);
175 G4double normF = m_mom/std::sqrt(Po[3]*Po[3]+Po[4]*Po[4]+Po[5]*Po[5]);
176 Po [3]*=normF; Po[4]*=normF; Po[5]*=normF;
179 Po[6]=P[6]; Po[7]=P[7];
193 G4double dx = m_mPoint[0]-m_iPoint[0];
194 G4double dy = m_mPoint[1]-m_iPoint[1];
195 G4double dz = m_mPoint[2]-m_iPoint[2];
200 G4double ds = (ax*dx+ay*dy+az*dz)/d2;
205 return std::sqrt(dx*dx+dy*dy+dz*dz);
215 G4double P4vec[4]= { P[0], P[1], P[2], P[7] };
217 m_mom = std::sqrt(P[3]*P[3]+P[4]*P[4]+P[5]*P[5]) ;
224 dPdS[3] =
m_cof*(P[4]*m_lastField[2]-P[5]*m_lastField[1]) ;
225 dPdS[4] =
m_cof*(P[5]*m_lastField[0]-P[3]*m_lastField[2]) ;
226 dPdS[5] =
m_cof*(P[3]*m_lastField[1]-P[4]*m_lastField[0]) ;
238 G4double dx = Position[0] - lastPosition[0];
239 G4double dy = Position[1] - lastPosition[1];
240 G4double dz = Position[2] - lastPosition[2];
241 G4double distMag2 = dx*dx+dy*dy+dz*dz;
245 G4double dist= std::sqrt( distMag2 );
247 message <<
"Moved from correct field position by " << dist
248 <<
"( larger than allowed = " << allowedDist <<
" ) ";
265 G4double new_mom2= (PosMom[3]*PosMom[3]
267 +PosMom[5]*PosMom[5]);
268 G4double new_mom= std::sqrt(new_mom2);
269 if( std::fabs(new_mom - savedMom ) > perThousand * savedMom )
272 message <<
"Momentum magnitude is invalid / has changed !" <<
G4endl
273 <<
" new value (p-mag) = " << new_mom <<
G4endl
274 <<
" cached value (p-mag) = " << savedMom;
277 message <<
"; ratio (new/old) = " << new_mom / savedMom;
G4bool CheckCachedMomemtum(const G4double PosMom[6], G4double savedMom)
virtual void ComputeRightHandSide(const G4double P[], G4double dPdS[])
void message(RunManager *runmanager)
G4bool CheckFieldPosition(const G4double Position[3], const G4double lastPosition[3])
static constexpr double perMillion
double A(double temperature)
G4double DistChord() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
void Stepper(const G4double P[], const G4double dPdS[], G4double step, G4double Po[], G4double Err[])
G4NystromRK4(G4Mag_EqRhs *EquationMotion, G4double distanceConstField=0.0)
G4double m_fldPosition[4]
void getField(const G4double P[4])
static constexpr double perThousand