32 const double r0 = CLHEP::m;
35 if (pole_number < 2 || (pole_number % 2) != 0) {
37 "Pole number must be an even integer >= 2 (2=dipole,4=quadrupole,...)");
41 const G4ThreeVector x0(pos[0], pos[1], pos[2]);
42 const G4ThreeVector x1(origin[0], origin[1], origin[2]);
45 G4ThreeVector p = x0 - x1;
46 if (rotaxis == 0) p.rotateX(-rotation_angle);
47 else if (rotaxis == 1) p.rotateY(-rotation_angle);
48 else if (rotaxis == 2) p.rotateZ(-rotation_angle);
51 double u = 0.0, v = 0.0;
65 const double r = std::hypot(u, v);
66 const double phi = std::atan2(v, u);
71 G4ThreeVector B_local(0, 0, 0);
73 case 0: B_local.setX(strength);
75 case 1: B_local.setY(strength);
77 case 2: B_local.setZ(strength);
83 G4ThreeVector B_lab = B_local;
84 if (rotaxis == 0) B_lab.rotateX(+rotation_angle);
85 else if (rotaxis == 1) B_lab.rotateY(+rotation_angle);
86 else if (rotaxis == 2) B_lab.rotateZ(+rotation_angle);
88 bfield[0] = B_lab.x();
89 bfield[1] = B_lab.y();
90 bfield[2] = B_lab.z();
92 log->
info(2,
"Axial field mode (solenoid-like). Strength: ", strength,
93 " T, Field: (", bfield[0],
", ", bfield[1],
", ", bfield[2],
")");
98 const int n = pole_number / 2;
106 bfield[0] = bfield[1] = bfield[2] = 0.0;
109 ra = std::pow(r / r0,
static_cast<double>(a));
116 const double Bu = strength * ra * std::cos(a * phi);
117 const double Bv = strength * ra * std::sin(a * phi);
120 G4ThreeVector B_local(0, 0, 0);
122 case 0: B_local.setY(Bu);
125 case 1: B_local.setZ(Bu);
128 case 2: B_local.setX(Bu);
135 G4ThreeVector B_lab = B_local;
136 if (rotaxis == 0) B_lab.rotateX(+rotation_angle);
137 else if (rotaxis == 1) B_lab.rotateY(+rotation_angle);
138 else if (rotaxis == 2) B_lab.rotateZ(+rotation_angle);
141 bfield[0] = B_lab.x();
142 bfield[1] = B_lab.y();
143 bfield[2] = B_lab.z();
145 log->
info(2,
"Pole Number: ", pole_number,
147 ", Strength: ", strength,
148 ", Requested at: (", pos[0],
", ", pos[1],
", ", pos[2],
")",
149 ", Rotation angle: ", rotation_angle,
150 ", Rotation axis: ", rotaxis,
151 ", longitudinal: ", longitudinal,
152 ", Field: (", bfield[0],
", ", bfield[1],
", ", bfield[2],
")");