32 const double r0 = CLHEP::m;
35 if (pole_number < 2 || (pole_number % 2) != 0) {
38 "Pole number must be an even integer >= 2 (2=dipole,4=quadrupole,...)");
42 const G4ThreeVector x0(pos[0], pos[1], pos[2]);
43 const G4ThreeVector x1(origin[0], origin[1], origin[2]);
46 G4ThreeVector p = x0 - x1;
47 if (rotaxis == 0) p.rotateX(-rotation_angle);
48 else if (rotaxis == 1) p.rotateY(-rotation_angle);
49 else if (rotaxis == 2) p.rotateZ(-rotation_angle);
52 double u = 0.0, v = 0.0;
66 const double r = std::hypot(u, v);
67 const double phi = std::atan2(v, u);
72 G4ThreeVector B_local(0, 0, 0);
74 case 0: B_local.setX(strength);
76 case 1: B_local.setY(strength);
78 case 2: B_local.setZ(strength);
84 G4ThreeVector B_lab = B_local;
85 if (rotaxis == 0) B_lab.rotateX(+rotation_angle);
86 else if (rotaxis == 1) B_lab.rotateY(+rotation_angle);
87 else if (rotaxis == 2) B_lab.rotateZ(+rotation_angle);
89 bfield[0] = B_lab.x();
90 bfield[1] = B_lab.y();
91 bfield[2] = B_lab.z();
94 2,
"Axial field mode (solenoid-like). Strength: %1 T, Field: (%2, %3, %4)", strength, bfield[0],
95 bfield[1], bfield[2]);
100 const int n = pole_number / 2;
108 bfield[0] = bfield[1] = bfield[2] = 0.0;
111 ra = std::pow(r / r0,
static_cast<double>(a));
118 const double Bu = strength * ra * std::cos(a * phi);
119 const double Bv = strength * ra * std::sin(a * phi);
122 G4ThreeVector B_local(0, 0, 0);
124 case 0: B_local.setY(Bu);
127 case 1: B_local.setZ(Bu);
130 case 2: B_local.setX(Bu);
137 G4ThreeVector B_lab = B_local;
138 if (rotaxis == 0) B_lab.rotateX(+rotation_angle);
139 else if (rotaxis == 1) B_lab.rotateY(+rotation_angle);
140 else if (rotaxis == 2) B_lab.rotateZ(+rotation_angle);
143 bfield[0] = B_lab.x();
144 bfield[1] = B_lab.y();
145 bfield[2] = B_lab.z();
149 "Pole Number: %1, n: %2, Strength: %3, Requested at: (%4, %5, %6), Rotation angle: %7, Rotation "
150 "axis: %8, longitudinal: %9, Field: (%10, %11, %12)", pole_number, n, strength, pos[0], pos[1], pos[2],
151 rotation_angle, rotaxis, longitudinal, bfield[0], bfield[1], bfield[2]);