20#include "BDSFieldMag.hh"
21#include "BDSFieldMagGradient.hh"
22#include "BDSFieldMagSkew.hh"
23#include "BDSInterpolatorType.hh"
24#include "BDSMagnetStrength.hh"
27#include "G4ThreeVector.hh"
29#include "CLHEP/Units/SystemOfUnits.h"
34BDSFieldMagGradient::BDSFieldMagGradient()
37BDSFieldMagGradient::~BDSFieldMagGradient()
42 G4ThreeVector position(x, y, 0);
43 G4ThreeVector fieldAtXY = field->
GetField(position);
44 G4double by = fieldAtXY[1]/CLHEP::tesla;
55 G4double brhoinv = 1./(Brho / CLHEP::tesla / CLHEP::m);
56 G4int centreIndex = 0;
57 std::vector<G4double> d =
PrepareValues(BField, 5, 0, h, centreIndex);
58 G4int centreIndexSkew = 0;
59 std::vector<std::vector<G4double>> dskew =
PrepareSkewValues(BField,5,0,h,centreIndexSkew);
61 for (G4int o = 0; o < order; ++o)
63 (*outputstrengths)[
"k" + std::to_string(o+1)] =
Derivative(d, o+1, centreIndex, h) * brhoinv;
64 (*outputstrengths)[
"k" + std::to_string(o+1) +
"s"] =
Derivative(dskew[o], o+1, centreIndex, h) * brhoinv;
67 G4cout <<
"k" << o+1 <<
" = " << (*outputstrengths)[
"k" + std::to_string(o+1)] << G4endl;
68 G4cout <<
"k" << o+1 <<
"s"<<
" = " << (*outputstrengths)[
"k" + std::to_string(o+1) +
"s"]<< G4endl;
71 return outputstrengths;
78 G4int& centreIndex)
const
81 G4int maxN = 2*order + 1;
83 std::vector<G4double> data(2*maxN+1);
85 for (G4int i = -maxN; i <= maxN; i++)
86 {data[maxN + i] =
GetBy(field, centreX+(G4double)i*h);}
94 G4int& centreIndex)
const
96 G4double rotation[5] = {CLHEP::pi/4, CLHEP::pi/6, CLHEP::pi/8, CLHEP::pi/10, CLHEP::pi/12};
97 std::vector<std::vector<G4double>> skewValues(order);
98 for (G4int j=0; j<order; j++)
101 skewValues[j] =
PrepareValues(skewField, order, centreX, h, centreIndex);
109 const G4int startIndex,
110 const G4double h)
const
113 {
return data.at(startIndex);}
114 G4int subOrder = order-1;
115 G4double result = -
Derivative(data, subOrder,startIndex+2,h)
116 + 8*
Derivative(data, subOrder,startIndex+1, h)
117 - 8*
Derivative(data, subOrder,startIndex-1, h)
119 result /= 12*(h/CLHEP::m);
G4double Derivative(const std::vector< G4double > &data, const G4int order, const G4int startIndex, const G4double h) const
std::vector< G4double > PrepareValues(BDSFieldMag *field, G4int order, G4double centreX, G4double h, G4int ¢reIndex) const
BDSMagnetStrength * CalculateMultipoles(BDSFieldMag *BField, G4int order, G4double Brho=4)
Find the Magnet strengths of a multipole field to nth order.
std::vector< std::vector< G4double > > PrepareSkewValues(BDSFieldMag *field, G4int order, G4double centreX, G4double h, G4int ¢reIndex) const
G4double GetBy(BDSFieldMag *BField, G4double x, G4double y=0) const
Query a point on x axis (by default) for By.
A wrapper class for BDSFieldMag that rotates it.
Interface for static magnetic fields that may or may not be local.
virtual G4ThreeVector GetField(const G4ThreeVector &position, const G4double t=0) const =0
Efficient storage of magnet strengths.