3 #include <phparameter/PHParameters.h>
10 #include <Geant4/G4ChordFinder.hh>
11 #include <Geant4/G4ClassicalRK4.hh>
12 #include <Geant4/G4FieldManager.hh>
13 #include <Geant4/G4LogicalVolume.hh>
14 #include <Geant4/G4Mag_UsualEqRhs.hh>
15 #include <Geant4/G4MagneticField.hh>
16 #include <Geant4/G4PVPlacement.hh>
17 #include <Geant4/G4PhysicalConstants.hh>
18 #include <Geant4/G4QuadrupoleMagField.hh>
19 #include <Geant4/G4RotationMatrix.hh>
20 #include <Geant4/G4String.hh>
21 #include <Geant4/G4SystemOfUnits.hh>
22 #include <Geant4/G4ThreeVector.hh>
23 #include <Geant4/G4Transform3D.hh>
24 #include <Geant4/G4Tubs.hh>
25 #include <Geant4/G4Types.hh>
26 #include <Geant4/G4UniformMagField.hh>
27 #include <Geant4/G4VisAttributes.hh>
29 #include <CLHEP/Units/SystemOfUnits.h>
45 , magnet_physi(nullptr)
46 , cylinder_physi(nullptr)
66 G4VisAttributes *fieldVis =
new G4VisAttributes();
68 fieldVis->SetVisibility(
false);
69 fieldVis->SetForceSolid(
false);
71 G4VisAttributes *siliconVis =
new G4VisAttributes();
75 siliconVis->SetVisibility(
false);
76 siliconVis->SetForceSolid(
false);
81 siliconVis->SetVisibility(
true);
82 siliconVis->SetForceSolid(
true);
91 G4RotationMatrix *rotm =
new G4RotationMatrix();
97 G4MagneticField *magField =
nullptr;
100 if (magnettype ==
"dipole")
103 magField =
new G4UniformMagField(G4ThreeVector(0., fieldValue, 0.));
106 cout <<
"Creating DIPOLE with field " << fieldValue <<
" and name " <<
GetName() << endl;
108 else if (magnettype ==
"quadrupole")
115 magField =
new G4QuadrupoleMagField(fieldGradient,
origin, rotm);
120 cout <<
"Creating QUADRUPOLE with gradient " << fieldGradient <<
" and name " <<
GetName() << endl;
121 cout <<
"at x, y, z = " <<
origin.x() <<
" , " <<
origin.y() <<
" , " <<
origin.z() << endl;
122 cout <<
"with rotation around x, y, z axis by: " << rotm->phiX() <<
", " << rotm->phiY() <<
", " << rotm->phiZ() << endl;
128 cout <<
PHWHERE <<
" Aborting, no magnetic field specified for " <<
GetName() << endl;
133 G4Mag_UsualEqRhs *localEquation =
new G4Mag_UsualEqRhs(magField);
134 G4ClassicalRK4 *localStepper =
new G4ClassicalRK4(localEquation);
135 G4double minStep = 0.25 *
mm;
136 G4ChordFinder *localChordFinder =
new G4ChordFinder(magField, minStep, localStepper);
138 G4FieldManager *fieldMgr =
new G4FieldManager();
139 fieldMgr->SetDetectorField(magField);
140 fieldMgr->SetChordFinder(localChordFinder);
146 G4VSolid *magnet_solid =
new G4Tubs(
GetName(),
151 G4LogicalVolume *magnet_logic =
new G4LogicalVolume(magnet_solid,
155 magnet_logic->SetVisAttributes(fieldVis);
158 G4bool allLocal =
true;
159 magnet_logic->SetFieldManager(fieldMgr, allLocal);
171 G4VSolid *cylinder_solid =
new G4Tubs(G4String(
GetName().append(
"_Solid")),
175 G4LogicalVolume *cylinder_logic =
new G4LogicalVolume(cylinder_solid,
179 cylinder_logic->SetVisAttributes(siliconVis);
183 G4String(
GetName().append(
"_Solid")),