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

G4MagHelicalStepper is an abstract base class for integrator of particle's equation of motion, used in tracking in space dependent magnetic field, and for a set of steppers which use the helix as 'first order' solution. More...

#include <G4MagHelicalStepper.hh>

Inheritance diagram for G4MagHelicalStepper:

Public Member Functions

 G4MagHelicalStepper (G4Mag_EqRhs *EqRhs)
 ~G4MagHelicalStepper () override=default
 G4MagHelicalStepper (const G4MagHelicalStepper &)=delete
G4MagHelicalStepperoperator= (const G4MagHelicalStepper &)=delete
void Stepper (const G4double y[], const G4double dydx[], G4double h, G4double yout[], G4double yerr[]) override
virtual void DumbStepper (const G4double y[], G4ThreeVector Bfld, G4double h, G4double yout[])=0
G4double DistChord () const override
Public Member Functions inherited from G4MagIntegratorStepper
 G4MagIntegratorStepper (G4EquationOfMotion *Equation, G4int numIntegrationVariables, G4int numStateVariables=12, G4bool isFSAL=false)
virtual ~G4MagIntegratorStepper ()=default
 G4MagIntegratorStepper (const G4MagIntegratorStepper &)=delete
G4MagIntegratorStepperoperator= (const G4MagIntegratorStepper &)=delete
void NormaliseTangentVector (G4double vec[6])
void NormalisePolarizationVector (G4double vec[12])
void RightHandSide (const G4double y[], G4double dydx[]) const
void RightHandSide (const G4double y[], G4double dydx[], G4double field[]) const
G4int GetNumberOfVariables () const
G4int GetNumberOfStateVariables () const
virtual G4int IntegratorOrder () const =0
virtual G4StepperType StepperType () const
G4int IntegrationOrder ()
G4EquationOfMotionGetEquationOfMotion ()
const G4EquationOfMotionGetEquationOfMotion () const
void SetEquationOfMotion (G4EquationOfMotion *newEquation)
unsigned long GetfNoRHSCalls ()
void ResetfNORHSCalls ()
G4bool IsFSAL () const
G4bool isQSS () const
void SetIsQSS (G4bool val)

Protected Member Functions

void LinearStep (const G4double yIn[], G4double h, G4double yHelix[]) const
void AdvanceHelix (const G4double yIn[], const G4ThreeVector &Bfld, G4double h, G4double yHelix[], G4double yHelix2[]=nullptr)
void MagFieldEvaluate (const G4double y[], G4ThreeVector &Bfield)
G4double GetInverseCurve (const G4double Momentum, const G4double Bmag)
void SetAngCurve (const G4double Ang)
G4double GetAngCurve () const
void SetCurve (const G4double Curve)
G4double GetCurve () const
void SetRadHelix (const G4double Rad)
G4double GetRadHelix () const
Protected Member Functions inherited from G4MagIntegratorStepper
void SetIntegrationOrder (G4int order)
void SetFSAL (G4bool flag=true)

Detailed Description

G4MagHelicalStepper is an abstract base class for integrator of particle's equation of motion, used in tracking in space dependent magnetic field, and for a set of steppers which use the helix as 'first order' solution.

Definition at line 57 of file G4MagHelicalStepper.hh.

Constructor & Destructor Documentation

◆ G4MagHelicalStepper() [1/2]

G4MagHelicalStepper::G4MagHelicalStepper ( G4Mag_EqRhs * EqRhs)

Constructor for G4MagHelicalStepper.

Parameters
[in]EqRhsPointer to the provided equation of motion.

Definition at line 45 of file G4MagHelicalStepper.cc.

46 : G4MagIntegratorStepper(EqRhs, 6), // integrate over 6 variables only !!
47 // position & velocity
48 fPtrMagEqOfMot(EqRhs)
49{
50}
G4MagIntegratorStepper(G4EquationOfMotion *Equation, G4int numIntegrationVariables, G4int numStateVariables=12, G4bool isFSAL=false)

Referenced by G4ExactHelixStepper::G4ExactHelixStepper(), G4HelixExplicitEuler::G4HelixExplicitEuler(), G4HelixHeum::G4HelixHeum(), G4HelixImplicitEuler::G4HelixImplicitEuler(), G4HelixMixedStepper::G4HelixMixedStepper(), G4HelixSimpleRunge::G4HelixSimpleRunge(), G4MagHelicalStepper(), and operator=().

◆ ~G4MagHelicalStepper()

G4MagHelicalStepper::~G4MagHelicalStepper ( )
overridedefault

Default Destructor.

◆ G4MagHelicalStepper() [2/2]

G4MagHelicalStepper::G4MagHelicalStepper ( const G4MagHelicalStepper & )
delete

Copy constructor and assignment operator not allowed.

Member Function Documentation

◆ AdvanceHelix()

void G4MagHelicalStepper::AdvanceHelix ( const G4double yIn[],
const G4ThreeVector & Bfld,
G4double h,
G4double yHelix[],
G4double yHelix2[] = nullptr )
protected

A first order Step along a helix inside the field.

Definition at line 53 of file G4MagHelicalStepper.cc.

58{
59 // const G4int nvar = 6;
60
61 // OLD const G4double approc_limit = 0.05;
62 // OLD approc_limit = 0.05 gives max.error=x^5/5!=(0.05)^5/5!=2.6*e-9
63 // NEW approc_limit = 0.005 gives max.error=x^5/5!=2.6*e-14
64
65 const G4double approc_limit = 0.005;
66 G4ThreeVector Bnorm, B_x_P, vperp, vpar;
67
68 G4double B_d_P;
69 G4double B_v_P;
70 G4double Theta;
71 G4double R_1;
72 G4double R_Helix;
73 G4double CosT2, SinT2, CosT, SinT;
74 G4ThreeVector positionMove, endTangent;
75
76 G4double Bmag = Bfld.mag();
77 const G4double* pIn = yIn+3;
78 G4ThreeVector initVelocity = G4ThreeVector( pIn[0], pIn[1], pIn[2]);
79 G4double velocityVal = initVelocity.mag();
80 G4ThreeVector initTangent = (1.0/velocityVal) * initVelocity;
81
82 R_1 = GetInverseCurve(velocityVal,Bmag);
83
84 // for too small magnetic fields there is no curvature
85 // (include momentum here) FIXME
86
87 if( (std::fabs(R_1) < 1e-10)||(Bmag<1e-12) )
88 {
89 LinearStep( yIn, h, yHelix );
90
91 // Store and/or calculate parameters for chord distance
92
93 SetAngCurve(1.);
94 SetCurve(h);
95 SetRadHelix(0.);
96 }
97 else
98 {
99 Bnorm = (1.0/Bmag)*Bfld;
100
101 // calculate the direction of the force
102
103 B_x_P = Bnorm.cross(initTangent);
104
105 // parallel and perp vectors
106
107 B_d_P = Bnorm.dot(initTangent); // this is the fraction of P parallel to B
108
109 vpar = B_d_P * Bnorm; // the component parallel to B
110 vperp= initTangent - vpar; // the component perpendicular to B
111
112 B_v_P = std::sqrt( 1 - B_d_P * B_d_P); // Fraction of P perp to B
113
114 // calculate the stepping angle
115
116 Theta = R_1 * h; // * B_v_P;
117
118 // Trigonometrix
119
120 if( std::fabs(Theta) > approc_limit )
121 {
122 SinT = std::sin(Theta);
123 CosT = std::cos(Theta);
124 }
125 else
126 {
127 G4double Theta2 = Theta*Theta;
128 G4double Theta3 = Theta2 * Theta;
129 G4double Theta4 = Theta2 * Theta2;
130 SinT = Theta - 1.0/6.0 * Theta3;
131 CosT = 1 - 0.5 * Theta2 + 1.0/24.0 * Theta4;
132 }
133
134 // the actual "rotation"
135
136 G4double R = 1.0 / R_1;
137
138 positionMove = R * ( SinT * vperp + (1-CosT) * B_x_P) + h * vpar;
139 endTangent = CosT * vperp + SinT * B_x_P + vpar;
140
141 // Store the resulting position and tangent
142
143 yHelix[0] = yIn[0] + positionMove.x();
144 yHelix[1] = yIn[1] + positionMove.y();
145 yHelix[2] = yIn[2] + positionMove.z();
146 yHelix[3] = velocityVal * endTangent.x();
147 yHelix[4] = velocityVal * endTangent.y();
148 yHelix[5] = velocityVal * endTangent.z();
149
150 // Store 2*h step Helix if exist
151
152 if(yHelix2 != nullptr)
153 {
154 SinT2 = 2.0 * SinT * CosT;
155 CosT2 = 1.0 - 2.0 * SinT * SinT;
156 endTangent = (CosT2 * vperp + SinT2 * B_x_P + vpar);
157 positionMove = R * ( SinT2 * vperp + (1-CosT2) * B_x_P) + h*2 * vpar;
158
159 yHelix2[0] = yIn[0] + positionMove.x();
160 yHelix2[1] = yIn[1] + positionMove.y();
161 yHelix2[2] = yIn[2] + positionMove.z();
162 yHelix2[3] = velocityVal * endTangent.x();
163 yHelix2[4] = velocityVal * endTangent.y();
164 yHelix2[5] = velocityVal * endTangent.z();
165 }
166
167 // Store and/or calculate parameters for chord distance
168
169 G4double ptan=velocityVal*B_v_P;
170
171 G4double particleCharge = fPtrMagEqOfMot->FCof() / (eplus*c_light);
172 R_Helix =std::abs( ptan/(fUnitConstant * particleCharge*Bmag));
173
174 SetAngCurve(std::abs(Theta));
175 SetCurve(std::abs(R));
176 SetRadHelix(R_Helix);
177 }
178}
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition G4Types.hh:83
double z() const
double x() const
double y() const
Hep3Vector cross(const Hep3Vector &) const
double dot(const Hep3Vector &) const
double mag() const
void SetCurve(const G4double Curve)
void SetRadHelix(const G4double Rad)
G4double GetInverseCurve(const G4double Momentum, const G4double Bmag)
void LinearStep(const G4double yIn[], G4double h, G4double yHelix[]) const
void SetAngCurve(const G4double Ang)

Referenced by G4ExactHelixStepper::DumbStepper(), G4HelixExplicitEuler::DumbStepper(), G4HelixHeum::DumbStepper(), G4HelixImplicitEuler::DumbStepper(), G4HelixMixedStepper::DumbStepper(), G4HelixSimpleRunge::DumbStepper(), G4ExactHelixStepper::Stepper(), G4HelixExplicitEuler::Stepper(), and G4HelixMixedStepper::Stepper().

◆ DistChord()

G4double G4MagHelicalStepper::DistChord ( ) const
overridevirtual

Estimates the maximum distance of curved solution and chord.

Implements G4MagIntegratorStepper.

Definition at line 231 of file G4MagHelicalStepper.cc.

232{
233 // Check whether h/R > pi !!
234 // Method DistLine is good only for < pi
235
236 G4double Ang=GetAngCurve();
237 if(Ang<=pi)
238 {
239 return GetRadHelix()*(1-std::cos(0.5*Ang));
240 }
241
242 if(Ang<twopi)
243 {
244 return GetRadHelix()*(1+std::cos(0.5*(twopi-Ang)));
245 }
246
247 // return Diameter of projected circle
248 return 2*GetRadHelix();
249}
G4double GetRadHelix() const
G4double GetAngCurve() const

◆ DumbStepper()

virtual void G4MagHelicalStepper::DumbStepper ( const G4double y[],
G4ThreeVector Bfld,
G4double h,
G4double yout[] )
pure virtual

Same as Stepper() function above, but should perform a 'dump' step without error calculation. To be implemented in concrete derived classes.

Implemented in G4ExactHelixStepper, G4HelixExplicitEuler, G4HelixHeum, G4HelixImplicitEuler, G4HelixMixedStepper, and G4HelixSimpleRunge.

Referenced by Stepper().

◆ GetAngCurve()

◆ GetCurve()

G4double G4MagHelicalStepper::GetCurve ( ) const
inlineprotected

◆ GetInverseCurve()

G4double G4MagHelicalStepper::GetInverseCurve ( const G4double Momentum,
const G4double Bmag )
inlineprotected

Evaluates inverse of Curvature of Track.

Referenced by AdvanceHelix(), and G4HelixMixedStepper::Stepper().

◆ GetRadHelix()

G4double G4MagHelicalStepper::GetRadHelix ( ) const
inlineprotected

◆ LinearStep()

void G4MagHelicalStepper::LinearStep ( const G4double yIn[],
G4double h,
G4double yHelix[] ) const
inlineprotected

Performs a linear Step in regions without magnetic field.

Referenced by AdvanceHelix().

◆ MagFieldEvaluate()

void G4MagHelicalStepper::MagFieldEvaluate ( const G4double y[],
G4ThreeVector & Bfield )
inlineprotected

◆ operator=()

G4MagHelicalStepper & G4MagHelicalStepper::operator= ( const G4MagHelicalStepper & )
delete

◆ SetAngCurve()

void G4MagHelicalStepper::SetAngCurve ( const G4double Ang)
inlineprotected

Modifiers and accessors for storing and using the parameters of a track: radius of curve, Stepping angle, Radius of projected helix.

Referenced by AdvanceHelix(), G4HelixExplicitEuler::Stepper(), and G4HelixMixedStepper::Stepper().

◆ SetCurve()

void G4MagHelicalStepper::SetCurve ( const G4double Curve)
inlineprotected

◆ SetRadHelix()

void G4MagHelicalStepper::SetRadHelix ( const G4double Rad)
inlineprotected

Referenced by AdvanceHelix().

◆ Stepper()

void G4MagHelicalStepper::Stepper ( const G4double y[],
const G4double dydx[],
G4double h,
G4double yout[],
G4double yerr[] )
overridevirtual

The stepper for the Runge Kutta integration. The stepsize is fixed, with the step size given by 'h'. Integrates ODE starting values y[0 to 6]. Outputs yout[] and its estimated error yerr[].

Parameters
[in]yStarting values array of integration variables.
[in]dydxDerivatives array.
[in]hThe given step size.
[out]youtIntegration output.
[out]yerrThe estimated error.

Implements G4MagIntegratorStepper.

Definition at line 184 of file G4MagHelicalStepper.cc.

189{
190 const G4int nvar = 6;
191
192 // correction for Richardson Extrapolation.
193 // G4double correction = 1. / ( (1 << IntegratorOrder()) -1 );
194
195 G4double yTemp[8], yIn[8] ;
196 G4ThreeVector Bfld_initial, Bfld_midpoint;
197
198 // Saving yInput because yInput and yOut can be aliases for same array
199 //
200 for(G4int i=0; i<nvar; ++i)
201 {
202 yIn[i]=yInput[i];
203 }
204
205 G4double h = hstep * 0.5;
206
207 MagFieldEvaluate(yIn, Bfld_initial) ;
208
209 // Do two half steps
210 //
211 DumbStepper(yIn, Bfld_initial, h, yTemp);
212 MagFieldEvaluate(yTemp, Bfld_midpoint) ;
213 DumbStepper(yTemp, Bfld_midpoint, h, yOut);
214
215 // Do a full Step
216 //
217 h = hstep ;
218 DumbStepper(yIn, Bfld_initial, h, yTemp);
219
220 // Error estimation
221 //
222 for(G4int i=0; i<nvar; ++i)
223 {
224 yErr[i] = yOut[i] - yTemp[i] ;
225 }
226
227 return;
228}
int G4int
Definition G4Types.hh:85
virtual void DumbStepper(const G4double y[], G4ThreeVector Bfld, G4double h, G4double yout[])=0
void MagFieldEvaluate(const G4double y[], G4ThreeVector &Bfield)

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