2 #include "CLHEP/Units/PhysicalConstants.h"
5 #include "G4ThreeVector.hh"
11 #include "gutilities.h"
28 G4ThreeVector x0(pos[0], pos[1], pos[2]);
29 G4ThreeVector x1(origin[0], origin[1], origin[2]);
31 G4ThreeVector x0_local;
33 x2 = G4ThreeVector(0 * CLHEP::cm, 0 * CLHEP::cm, 1 * CLHEP::cm).rotateX(rotation_angle) + x1;
34 x0_local = (x0 - x1).rotateX(-rotation_angle);
35 }
else if (rotaxis == 1) {
36 x2 = G4ThreeVector(0 * CLHEP::cm, 0 * CLHEP::cm, 1 * CLHEP::cm).rotateY(rotation_angle) + x1;
37 x0_local = (x0 - x1).rotateY(-rotation_angle);
38 }
else if (rotaxis == 2) {
39 x2 = G4ThreeVector(0 * CLHEP::cm, 0 * CLHEP::cm, 1 * CLHEP::cm).rotateZ(rotation_angle) + x1;
40 x0_local = (x0 - x1).rotateZ(-rotation_angle);
43 G4double r = (x2 - x1).cross(x1 - x0).mag() / (x2 - x1).mag();
44 G4double phi = atan2(x0_local.y(), x0_local.x());
46 G4ThreeVector B_local;
47 if (pole_number == 2) {
49 B_local.setY(strength);
51 }
else if (pole_number > 0) {
52 int a = pole_number / 2 - 1;
53 B_local.setX(strength * pow(r / CLHEP::m, a) * sin(a * phi));
54 B_local.setY(strength * pow(r / CLHEP::m, a) * cos(a * phi));
57 cout <<
GFIELDLOGHEADER <<
"GField_MultipolesFactory::GetFieldValue: Pole number " + to_string(pole_number) +
" not supported. Exiting." << endl;
61 G4ThreeVector B_lab = B_local;
62 if (rotaxis == 0) { B_lab.rotateX(rotation_angle); }
63 else if (rotaxis == 1) { B_lab.rotateY(rotation_angle); }
64 else if (rotaxis == 2) { B_lab.rotateZ(rotation_angle); }
66 bfield[0] = B_lab.x();
67 bfield[1] = B_lab.y();
68 bfield[2] = B_lab.z();
85 gfield_definitions = gfd;
87 pole_number = get_field_parameter_int(
"pole_number");
88 origin[0] = get_field_parameter_double(
"vx");
89 origin[1] = get_field_parameter_double(
"vy");
90 origin[2] = get_field_parameter_double(
"vz");
91 rotation_angle = get_field_parameter_double(
"rotation_angle");
92 if( gfield_definitions.field_parameters[
"rotaxis"] ==
"X") {
94 }
else if( gfield_definitions.field_parameters[
"rotaxis"] ==
"Y") {
96 }
else if( gfield_definitions.field_parameters[
"rotaxis"] ==
"Z") {
99 cout <<
GFIELDLOGHEADER <<
"GField_MultipolesFactory::load_field_definitions: Rotation axis " + gfield_definitions.field_parameters[
"rotaxis"] +
" not supported. Exiting." << endl;
102 strength = get_field_parameter_double(
"strength");
Factory class for creating and managing multipole magnetic fields.
void GetFieldValue(const G4double pos[4], G4double *bfield) const override
Calculates the magnetic field at a given position.
void load_field_definitions(GFieldDefinition gfd) override
Sets the field definition for the field.
Abstract base class representing a magnetic field.
#define EC__WRONG_FIELD_ROTATION
#define EC__WRONG_POLE_NUMBER
GField * GFieldFactory(void)
Utility struct to load GFields from options.