19#include "BDSFieldMagMultipoleOuterOld.hh"
22#include "G4RotationMatrix.hh"
23#include "G4ThreeVector.hh"
24#include "G4TwoVector.hh"
26#include "CLHEP/Units/PhysicalConstants.h"
31BDSFieldMagMultipoleOuterOld::BDSFieldMagMultipoleOuterOld(G4int orderIn,
32 G4double poleTipRadiusIn,
35 G4double arbitraryScaling):
38 positiveField(kPositive),
39 poleTipRadius(poleTipRadiusIn)
41 G4int nPoles = 2*order;
44 G4TwoVector firstCurrent(poleTipRadius, 0);
45 for (G4int i = 0; i < nPoles; ++i)
47 G4TwoVector c = firstCurrent;
48 c.rotate((G4double)i*CLHEP::twopi / nPoles);
49 currents.push_back(c);
53 G4ThreeVector poleTipPoint = G4ThreeVector(0, poleTipRadius, 0);
54 G4double angleOffset = CLHEP::twopi/(G4double)nPoles;
55 poleTipPoint.rotateZ(0.5*angleOffset);
56 G4ThreeVector fieldAtPoleTip = innerFieldIn->
GetField(poleTipPoint,0);
57 G4double fieldAtPoleTipMag = fieldAtPoleTip.mag();
62 G4ThreeVector rawOuterlFieldAtPoleTip = GetField(poleTipPoint);
63 G4double rawOuterlFieldAtPoleTipMag = rawOuterlFieldAtPoleTip.mag();
66 normalisation = arbitraryScaling * fieldAtPoleTipMag / rawOuterlFieldAtPoleTipMag;
67 if (!std::isfinite(normalisation))
70 finiteStrength =
false;
75 const G4double )
const
77 G4TwoVector pos(position.x(), position.y());
82 G4double cToPosMag = 0;
83 G4double reciprocal = 0;
84 G4TwoVector cToPosPerp;
88 const G4double spatialLimit = 6;
89 G4bool closeToPole =
false;
93 cToPosMag = cToPos.mag();
94 if (cToPosMag < spatialLimit)
98 pos += cToPos.unit() * spatialLimit;
100 cToPosMag = cToPos.mag();
104 reciprocal = 1/cToPosMag;
105 if (!std::isnormal(reciprocal))
107 cToPosPerp = G4TwoVector(-cToPos.y(), cToPos.x());
108 G4TwoVector val = std::pow(-1, pole+1)*cToPosPerp.unit() * reciprocal;
109 if (std::isfinite(val.x()) && std::isfinite(val.y()))
116 {result = result.unit()*0.1;}
125 return G4ThreeVector(result.x(), result.y(), 0);
G4bool positiveField
Sign of magnetic field.
virtual G4ThreeVector GetField(const G4ThreeVector &position, const double t=0) const
Access the field value.
std::vector< G4TwoVector > currents
Locations of inifite wire current sources.
G4double normalisation
Storage of the overal normalisation factor.
Interface for static magnetic fields that may or may not be local.
virtual G4ThreeVector GetField(const G4ThreeVector &position, const G4double t=0) const =0