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