19#include "BDSIntegratorMultipoleThin.hh"
20#include "BDSMagnetStrength.hh"
22#include "BDSUtilities.hh"
24#include "G4Mag_EqRhs.hh"
25#include "G4ThreeVector.hh"
30#include <include/BDSGlobalConstants.hh>
35 G4Mag_EqRhs* eqOfMIn):
39 b0l = (*strength)[
"field"] * brho;
40 G4double l = (*strength)[
"length"] / CLHEP::m;
46 std::vector<G4String>::iterator nkey = normKeys.begin();
47 std::vector<G4String>::iterator skey = skewKeys.begin();
48 for (G4double i = 0; i < normKeys.size(); i++, ++nkey, ++skey)
50 bnl.push_back((*strength)[*nkey] / (l*std::pow(CLHEP::m,i+1)));
51 bsl.push_back((*strength)[*skey] / (l*std::pow(CLHEP::m,i+1)));
52 nfact.push_back(Factorial(i));
55 G4bool finiteStrength =
false;
56 for (
const auto& nl : bnl)
58 for (
const auto& sl : bsl)
60 zeroStrength = !finiteStrength;
69 const G4double fcof =
eqOfM->FCof();
85 G4ThreeVector pos = G4ThreeVector(yIn[0], yIn[1], yIn[2]);
86 G4ThreeVector mom = G4ThreeVector(yIn[3], yIn[4], yIn[5]);
87 G4double momMag = mom.mag();
93 G4ThreeVector localMomUnit = localMom.unit();
104 G4ThreeVector localPosOut;
105 G4ThreeVector localMomUnitOut;
107 OneStep(localPos, localMomUnit, momMag, localPosOut, localMomUnitOut, h);
110 G4double zp1 = localMomUnitOut.z();
123 const G4ThreeVector& momUIn,
124 const G4double momIn,
125 G4ThreeVector& posOut,
126 G4ThreeVector& momOut,
129 G4double x0 = posIn.x();
130 G4double y0 = posIn.y();
131 G4double z0 = posIn.z();
132 G4double xp = momUIn.x();
133 G4double yp = momUIn.y();
134 G4double zp = momUIn.z();
139 G4double z1 = z0 + h;
146 G4complex position(x0, y0);
147 G4complex result(0,0);
155 G4double ratio =
eqOfM->FCof() * std::abs(
brho) / momIn;
158 std::list<double>::const_iterator kn =
bnl.begin();
161 for (; kn !=
bnl.end(); n++, ++kn)
165 knReal = (*kn) * ratio * std::pow(position,n).real() /
nfact[n];
166 knImag = (*kn) * ratio * std::pow(position,n).imag() /
nfact[n];
167 if (!std::isnan(knReal))
169 if (!std::isnan(knImag))
171 result = {momx,momy};
179 G4complex skewkick(0,0);
181 std::list<double>::const_iterator ks =
bsl.begin();
182 for (; ks !=
bsl.end(); n++, ++ks)
189 ksReal = (*ks) * ratio * std::pow(position, n).real() /
nfact[n];
190 ksImag = (*ks) * ratio * std::pow(position, n).imag() /
nfact[n];
191 if (!std::isnan(ksReal))
193 if (!std::isnan(ksImag))
195 result = {momx,momy};
205 xp1 -= skewkick.imag();
206 yp1 += skewkick.real();
208 zp1 = std::sqrt(1 - std::pow(xp1,2) - std::pow(yp1,2));
212 posOut = G4ThreeVector(x1, y1, z1);
213 momOut = G4ThreeVector(xp1, yp1, zp1);
219 for (G4int i = 1; i <= n; i++)
BDSStep ConvertToLocal(G4Step const *const step, G4bool useCurvilinear=true) const
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.
static G4double thinElementLength
void ConvertToGlobal(const G4ThreeVector &localPos, const G4ThreeVector &localMom, G4double yOut[], G4double yErr[], const G4double momScaling=1.0)
scaling of momentum in case localMom is a unit vector
std::vector< G4int > nfact
Higher order components.
G4int Factorial(G4int n)
Calculate the factorial of n.
void OneStep(const G4ThreeVector &posIn, const G4ThreeVector &momUIn, const G4double momIn, G4ThreeVector &posOut, G4ThreeVector &momOut, G4double h) const
BDSIntegratorMultipoleThin()=delete
Private default constructor to enforce use of supplied constructor.
std::list< double > bsl
Higher order components.
G4double brho
Magnetic rigidity for momentum scaling.
virtual void Stepper(const G4double yIn[], const G4double dydx[], const G4double h, G4double yOut[], G4double yErr[])
std::list< double > bnl
Higher order components.
Efficient storage of magnet strengths.
static std::vector< G4String > SkewComponentKeys()
Accessor for skew component keys - k1 - k12.
static std::vector< G4String > NormalComponentKeys()
Accessor for normal component keys - k1 - k12.
A simple class to represent the positions of a step.
G4ThreeVector PostStepPoint() const
Accessor.
G4ThreeVector PreStepPoint() const
Accessor.
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())
G4bool IsFiniteStrength(G4double variable)