19#include "BDSFieldMag.hh"
20#include "BDSFieldMagGradient.hh"
21#include "BDSFieldMagSkew.hh"
22#include "BDSInterpolatorType.hh"
23#include "BDSMagnetStrength.hh"
26#include "G4ThreeVector.hh"
28#include "CLHEP/Units/SystemOfUnits.h"
33BDSFieldMagGradient::BDSFieldMagGradient()
36BDSFieldMagGradient::~BDSFieldMagGradient()
41 G4ThreeVector position(x, y, 0);
42 G4ThreeVector fieldAtXY = field->
GetField(position);
43 G4double by = fieldAtXY[1]/CLHEP::tesla;
54 G4double brhoinv = 1./(Brho / CLHEP::tesla / CLHEP::m);
55 G4int centreIndex = 0;
56 std::vector<G4double> d =
PrepareValues(BField, 5, 0, h, centreIndex);
57 G4int centreIndexSkew = 0;
58 std::vector<std::vector<G4double>> dskew =
PrepareSkewValues(BField,5,0,h,centreIndexSkew);
60 for (G4int o = 0; o < order; ++o)
62 (*outputstrengths)[
"k" + std::to_string(o+1)] =
Derivative(d, o+1, centreIndex, h) * brhoinv;
63 (*outputstrengths)[
"k" + std::to_string(o+1) +
"s"] =
Derivative(dskew[o], o+1, centreIndex, h) * brhoinv;
66 G4cout <<
"k" << o+1 <<
" = " << (*outputstrengths)[
"k" + std::to_string(o+1)] << G4endl;
67 G4cout <<
"k" << o+1 <<
"s"<<
" = " << (*outputstrengths)[
"k" + std::to_string(o+1) +
"s"]<< G4endl;
70 return outputstrengths;
77 G4int& centreIndex)
const
80 G4int maxN = 2*order + 1;
82 std::vector<G4double> data(2*maxN+1);
84 for (G4int i = -maxN; i <= maxN; i++)
85 {data[maxN + i] =
GetBy(field, centreX+(G4double)i*h);}
93 G4int& centreIndex)
const
95 G4double rotation[5] = {CLHEP::pi/4, CLHEP::pi/6, CLHEP::pi/8, CLHEP::pi/10, CLHEP::pi/12};
96 std::vector<std::vector<G4double>> skewValues(order);
97 for (G4int j=0; j<order; j++)
100 skewValues[j] =
PrepareValues(skewField, order, centreX, h, centreIndex);
108 const G4int startIndex,
109 const G4double h)
const
112 {
return data.at(startIndex);}
113 G4int subOrder = order-1;
114 G4double result = -
Derivative(data, subOrder,startIndex+2,h)
115 + 8*
Derivative(data, subOrder,startIndex+1, h)
116 - 8*
Derivative(data, subOrder,startIndex-1, h)
118 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.