BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldMagDipole.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 "BDSDebug.hh"
19#include "BDSFieldMagDipole.hh"
20#include "BDSMagnetStrength.hh"
21#include "BDSUtilities.hh"
22
23#include "globals.hh"
24#include "G4ThreeVector.hh"
25
26BDSFieldMagDipole::BDSFieldMagDipole(const G4ThreeVector& field):
27 localField(field)
28{
30#ifdef BDSDEBUG
31 G4cout << __METHOD_NAME__ << "B (local) = " << localField << G4endl;
32#endif
33}
34
36{
37 G4double field = (*strength)["field"];
38 G4double bx = (*strength)["bx"];
39 G4double by = (*strength)["by"];
40 G4double bz = (*strength)["bz"];
41
42 if (!BDS::IsFinite(bx) && !BDS::IsFinite(by) && !BDS::IsFinite(bz) && BDS::IsFinite(field))
43 {localField = G4ThreeVector(0,1,0) * field;}
44 else
45 {localField = G4ThreeVector(bx,by,bz).unit() * field;}
46
48#ifdef BDSDEBUG
49 G4cout << __METHOD_NAME__ << "B (local) (T) = " << localField / CLHEP::tesla << G4endl;
50#endif
51}
52
53G4ThreeVector BDSFieldMagDipole::GetField(const G4ThreeVector& /*position*/,
54 const G4double /*t*/) const
55{
56 return localField;
57}
G4ThreeVector localField
BDSFieldMagDipole()
Private default constructor to ensure use of supplied constructor.
virtual G4ThreeVector GetField(const G4ThreeVector &position, const G4double t=0) const
Access the field value.
G4bool finiteStrength
Flag to cache whether finite nor not.
Efficient storage of magnet strengths.
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())