BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldMagDetectorSolenoid.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "BDSFieldMagDetectorSolenoid.hh"
20
21#include "globals.hh" // geant4 types / globals
22#include "G4ThreeVector.hh"
23
24#include <cmath>
25
26BDSFieldMagDetectorSolenoid::BDSFieldMagDetectorSolenoid(G4double BIn,
27 G4double BOut,
28 G4double radiusIn,
29 G4double radiusOut,
30 G4double zMin,
31 G4double zMax):
32 itsBIn(BIn),
33 itsBOut(BOut),
34 itsRadiusIn(radiusIn),
35 itsRadiusOut(radiusOut),
36 itsZMin(zMin),
37 itsZMax(zMax)
38{;}
39
40G4ThreeVector BDSFieldMagDetectorSolenoid::GetField(const G4ThreeVector &position,
41 const G4double /*t*/) const
42{
43 G4ThreeVector result(0,0,0);
44 G4double zField = 0;
45 G4double localRad = std::hypot(position.y(),position.x());
46
47 if( (position.z() > itsZMin) && (position.z() < itsZMax) )
48 {
49 if(localRad<itsRadiusIn)
50 {zField = itsBIn;}
51 else if(localRad<itsRadiusOut)
52 {zField = itsBOut;}
53 else
54 {zField=0;}
55 }
56 else
57 {zField=0;}
58
59 result[2] = zField;
60 return result;
61}
62
63
64
virtual G4ThreeVector GetField(const G4ThreeVector &position, const G4double t=0) const
Get the magnetic field vector in local coordinates.