28 const double r0 = CLHEP::m;
31 if (pole_number < 2 || (pole_number % 2) != 0) {
33 "Pole number must be an even integer >= 2 (2=dipole,4=quadrupole,...)");
37 const G4ThreeVector x0(pos[0], pos[1], pos[2]);
38 const G4ThreeVector x1(origin[0], origin[1], origin[2]);
41 G4ThreeVector p = x0 - x1;
42 if (rotaxis == 0) p.rotateX(-rotation_angle);
43 else if (rotaxis == 1) p.rotateY(-rotation_angle);
44 else if (rotaxis == 2) p.rotateZ(-rotation_angle);
47 double u = 0.0, v = 0.0;
61 const double r = std::hypot(u, v);
62 const double phi = std::atan2(v, u);
67 G4ThreeVector B_local(0, 0, 0);
69 case 0: B_local.setX(strength);
71 case 1: B_local.setY(strength);
73 case 2: B_local.setZ(strength);
78 G4ThreeVector B_lab = B_local;
79 if (rotaxis == 0) B_lab.rotateX(+rotation_angle);
80 else if (rotaxis == 1) B_lab.rotateY(+rotation_angle);
81 else if (rotaxis == 2) B_lab.rotateZ(+rotation_angle);
83 bfield[0] = B_lab.x();
84 bfield[1] = B_lab.y();
85 bfield[2] = B_lab.z();
87 log->info(2,
"Axial field mode (solenoid-like). Strength: ", strength,
88 " T, Field: (", bfield[0],
", ", bfield[1],
", ", bfield[2],
")");
93 const int n = pole_number / 2;
101 bfield[0] = bfield[1] = bfield[2] = 0.0;
104 ra = std::pow(r / r0,
static_cast<double>(a));
111 const double Bu = strength * ra * std::cos(a * phi);
112 const double Bv = strength * ra * std::sin(a * phi);
115 G4ThreeVector B_local(0, 0, 0);
117 case 0: B_local.setY(Bu);
120 case 1: B_local.setZ(Bu);
123 case 2: B_local.setX(Bu);
130 G4ThreeVector B_lab = B_local;
131 if (rotaxis == 0) B_lab.rotateX(+rotation_angle);
132 else if (rotaxis == 1) B_lab.rotateY(+rotation_angle);
133 else if (rotaxis == 2) B_lab.rotateZ(+rotation_angle);
136 bfield[0] = B_lab.x();
137 bfield[1] = B_lab.y();
138 bfield[2] = B_lab.z();
140 log->info(2,
"Pole Number: ", pole_number,
142 ", Strength: ", strength,
143 ", Requested at: (", pos[0],
", ", pos[1],
", ", pos[2],
")",
144 ", Rotation angle: ", rotation_angle,
145 ", Rotation axis: ", rotaxis,
146 ", longitudinal: ", longitudinal,
147 ", Field: (", bfield[0],
", ", bfield[1],
", ", bfield[2],
")");