File indexing completed on 2025-01-18 09:59:12
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
0039 #ifndef G4T_QUADRUPOLE_MAGFIELD_HH
0040 #define G4T_QUADRUPOLE_MAGFIELD_HH
0041
0042 #include "G4ThreeVector.hh"
0043 #include "G4RotationMatrix.hh"
0044 #include "G4MagneticField.hh"
0045
0046 static G4RotationMatrix IdentityMatrix;
0047
0048 class G4TQuadrupoleMagField : public G4MagneticField
0049 {
0050 public:
0051
0052 G4TQuadrupoleMagField(G4double pGradient)
0053 {
0054 fGradient = pGradient ;
0055 fOrigin = G4ThreeVector( 0.0, 0.0, 0.0) ;
0056 fpMatrix = &IdentityMatrix;
0057 }
0058
0059 G4TQuadrupoleMagField(G4double pGradient,
0060 G4ThreeVector pOrigin,
0061 G4RotationMatrix* pMatrix)
0062 {
0063 fGradient = pGradient ;
0064 fOrigin = pOrigin ;
0065 fpMatrix = pMatrix ;
0066 }
0067
0068 virtual ~G4TQuadrupoleMagField() {;}
0069
0070 inline void GetFieldValue(const G4double y[7],
0071 G4double B[3] ) const
0072 {
0073 G4ThreeVector r_global = G4ThreeVector(
0074 y[0] - fOrigin.x(),
0075 y[1] - fOrigin.y(),
0076 y[2] - fOrigin.z());
0077
0078 G4ThreeVector r_local = G4ThreeVector(
0079 fpMatrix->colX() * r_global,
0080 fpMatrix->colY() * r_global,
0081 fpMatrix->colZ() * r_global);
0082
0083 G4ThreeVector B_local = G4ThreeVector(
0084 fGradient * r_local.y(),
0085 fGradient * r_local.x(),
0086 0);
0087
0088 G4ThreeVector B_global = G4ThreeVector(
0089 fpMatrix->inverse().rowX() * B_local,
0090 fpMatrix->inverse().rowY() * B_local,
0091 fpMatrix->inverse().rowZ() * B_local);
0092
0093 B[0] = B_global.x() ;
0094 B[1] = B_global.y() ;
0095 B[2] = B_global.z() ;
0096 }
0097
0098 G4TQuadrupoleMagField* Clone() const
0099 {
0100
0101 return new G4TQuadrupoleMagField(this->fGradient,
0102 this->fOrigin,
0103 this->fpMatrix);
0104 }
0105
0106 private:
0107
0108 G4double fGradient;
0109 G4ThreeVector fOrigin;
0110 G4RotationMatrix* fpMatrix;
0111 };
0112 #endif
0113