File indexing completed on 2026-07-18 08:35:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #ifndef G4T_QUADRUPOLE_MAGFIELD_HH
0039 #define G4T_QUADRUPOLE_MAGFIELD_HH
0040
0041 #include "G4ThreeVector.hh"
0042 #include "G4RotationMatrix.hh"
0043 #include "G4MagneticField.hh"
0044
0045
0046
0047
0048
0049 class G4TQuadrupoleMagField : public G4MagneticField
0050 {
0051 public:
0052
0053 G4TQuadrupoleMagField(G4double pGradient)
0054 {
0055 fGradient = pGradient ;
0056 fOrigin = G4ThreeVector( 0.0, 0.0, 0.0) ;
0057 fpMatrix = &IdentityMatrix;
0058 }
0059
0060 G4TQuadrupoleMagField(G4double pGradient,
0061 G4ThreeVector pOrigin,
0062 G4RotationMatrix* pMatrix)
0063 {
0064 fGradient = pGradient ;
0065 fOrigin = pOrigin ;
0066 fpMatrix = pMatrix ;
0067 }
0068
0069 virtual ~G4TQuadrupoleMagField() = default;
0070
0071 inline void GetFieldValue(const G4double y[7],
0072 G4double B[3] ) const
0073 {
0074 G4ThreeVector r_global = G4ThreeVector(
0075 y[0] - fOrigin.x(),
0076 y[1] - fOrigin.y(),
0077 y[2] - fOrigin.z());
0078
0079 G4ThreeVector r_local = G4ThreeVector(
0080 fpMatrix->colX() * r_global,
0081 fpMatrix->colY() * r_global,
0082 fpMatrix->colZ() * r_global);
0083
0084 G4ThreeVector B_local = G4ThreeVector(
0085 fGradient * r_local.y(),
0086 fGradient * r_local.x(),
0087 0);
0088
0089 G4ThreeVector B_global = G4ThreeVector(
0090 fpMatrix->inverse().rowX() * B_local,
0091 fpMatrix->inverse().rowY() * B_local,
0092 fpMatrix->inverse().rowZ() * B_local);
0093
0094 B[0] = B_global.x() ;
0095 B[1] = B_global.y() ;
0096 B[2] = B_global.z() ;
0097 }
0098
0099 G4TQuadrupoleMagField* Clone() const
0100 {
0101
0102 return new G4TQuadrupoleMagField(this->fGradient,
0103 this->fOrigin,
0104 this->fpMatrix);
0105 }
0106
0107 private:
0108
0109 static G4RotationMatrix IdentityMatrix;
0110
0111 G4double fGradient;
0112 G4ThreeVector fOrigin;
0113 G4RotationMatrix* fpMatrix;
0114 };
0115
0116 #endif
0117