20#include "BDSIntegratorQuadrupole.hh"
21#include "BDSMagnetStrength.hh"
23#include "BDSUtilities.hh"
25#include "G4Mag_EqRhs.hh"
26#include "G4MagIntegratorStepper.hh"
27#include "G4ThreeVector.hh"
29#include "CLHEP/Units/SystemOfUnits.h"
37 G4double minimumRadiusOfCurvatureIn):
39 minimumRadiusOfCurvature(minimumRadiusOfCurvatureIn)
44 bPrime = std::abs(brho) * (*strength)[
"k1"] / CLHEP::m2;
48 G4cout << __METHOD_NAME__ <<
"B' = " << bPrime << G4endl;
53 const G4double dydx[],
59 const G4double fcof =
eqOfM->FCof();
67 G4ThreeVector mom = G4ThreeVector(yIn[3], yIn[4], yIn[5]);
68 G4double momMag = mom.mag();
74 G4double kappa = fcof*
bPrime/momMag;
77 if(std::abs(kappa) < 1e-20)
84 G4ThreeVector pos = G4ThreeVector(yIn[0], yIn[1], yIn[2]);
85 G4ThreeVector momUnit = mom.unit();
90 G4double xp = localMomUnit.x();
91 G4double yp = localMomUnit.y();
92 G4double zp = localMomUnit.z();
103 G4double x0 = localPos.x();
104 G4double y0 = localPos.y();
105 G4double z0 = localPos.z();
108 G4ThreeVector localA;
111 localA.setZ( x0*xp - y0*yp);
114 G4double localAMag = localA.mag();
115 G4double radiusOfCurvature = std::numeric_limits<double>::max();
117 {radiusOfCurvature = 1./localAMag;}
138 G4double dc = h2/(8*radiusOfCurvature);
144 G4double rootK = std::sqrt(std::abs(kappa*zp));
145 if (std::isnan(rootK))
147 G4double rootKh = rootK*h*zp;
148 G4double X11=0,X12=0,X21=0,X22=0;
149 G4double Y11=0,Y12=0,Y21=0,Y22=0;
153 X11 = std::cos(rootKh);
154 X12 = std::sin(rootKh)/rootK;
155 X21 =-std::abs(kappa)*X12;
158 Y11 = std::cosh(rootKh);
159 Y12 = std::sinh(rootKh)/rootK;
160 Y21 = std::abs(kappa)*Y12;
166 X12 = sinh(rootKh)/rootK;
167 X21 = std::abs(kappa)*X12;
170 Y11 = std::cos(rootKh);
171 Y12 = std::sin(rootKh)/rootK;
172 Y21 = -std::abs(kappa)*Y12;
176 x1 = X11*x0 + X12*xp;
177 xp1 = X21*x0 + X22*xp;
179 y1 = Y11*y0 + Y12*yp;
180 yp1 = Y21*y0 + Y22*yp;
183 zp1 = std::sqrt(1 - xp1*xp1 - yp1*yp1);
188 G4double z1 = z0 + std::sqrt(h2 - std::pow(x1-x0,2) - std::pow(y1-y0,2));
193 localMomUnit.setX(xp1);
194 localMomUnit.setY(yp1);
195 localMomUnit.setZ(zp1);
198 G4ThreeVector localMomOut = localMomUnit * momMag;
201 BDSStep globalPosMom = CurvilinearToGlobal(localPos, localMomOut,
true);
202 G4ThreeVector globalPosOut = globalPosMom.
PreStepPoint();
206 G4ThreeVector globalMomOutU = globalMomOut.unit();
207 globalMomOutU *= 1e-8;
210 for (G4int i = 0; i < 3; i++)
212 yOut[i] = globalPosOut[i];
213 yOut[i+3] = globalMomOut[i];
214 yErr[i] = globalMomOutU[i]*1e-10;
BDSStep GlobalToCurvilinear(const G4double fieldArcLength, const G4ThreeVector &unitField, const G4double angle, const G4ThreeVector &position, const G4ThreeVector &unitMomentum, const G4double h, const G4bool useCurvilinearWorld, const G4double FCof, const G4double tilt=0)
void AdvanceDriftMag(const G4double yIn[], const G4double h, G4double yOut[], G4double yErr[]) const
Error array [6] all 0.
Common functionality to BDSIM integrators.
G4double backupStepperMomLimit
void SetDistChord(G4double distChordIn)
Setter for distChord to private member.
G4MagIntegratorStepper * backupStepper
virtual void Stepper(const G4double y[], const G4double dydx[], const G4double h, G4double yOut[], G4double yErr[])
BDSIntegratorQuadrupole()
Private default constructor to enforce use of supplied constructor.
G4double bPrime
B Field Gradient.
G4double minimumRadiusOfCurvature
Efficient storage of magnet strengths.
A simple class to represent the positions of a step.
G4ThreeVector PostStepPoint() const
Accessor.
G4ThreeVector PreStepPoint() const
Accessor.
G4bool IsFiniteStrength(G4double variable)