BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldEMGlobal.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 "BDSDebug.hh"
20#include "BDSFieldEM.hh"
21#include "BDSFieldEMGlobal.hh"
22
23#include "G4ThreeVector.hh"
24#include "G4Types.hh"
25
26#include <utility>
27
28BDSFieldEMGlobal::BDSFieldEMGlobal(BDSFieldEM* fieldIn):
29 field(fieldIn)
30{
31 finiteStrength = field->FiniteStrength();
32}
33
34BDSFieldEMGlobal::~BDSFieldEMGlobal()
35{
36 delete field;
37}
38
39std::pair<G4ThreeVector,G4ThreeVector> BDSFieldEMGlobal::GetFieldTransformed(const G4ThreeVector& position,
40 const G4double t) const
41{
42 if (!finiteStrength)
43 {return std::make_pair(G4ThreeVector(),G4ThreeVector());} // quicker than query
44 else
45 {return GetField(position, t);}
46}
47
48std::pair<G4ThreeVector,G4ThreeVector> BDSFieldEMGlobal::GetField(const G4ThreeVector& position,
49 const G4double t) const
50{
51 G4ThreeVector localPosition = ConvertToLocal(position);
52 auto localField = field->GetFieldTransformed(localPosition, t);
53 auto globalField = ConvertAxisToGlobal(localField);
54 return globalField;
55}
G4ThreeVector ConvertAxisToGlobal(const G4ThreeVector &localAxis, const G4bool useCurvilinear=true) const
BDSStep ConvertToLocal(G4Step const *const step, G4bool useCurvilinear=true) const
virtual std::pair< G4ThreeVector, G4ThreeVector > GetField(const G4ThreeVector &position, const G4double t) const
BDSFieldEM * field
The field on which this is based.
virtual std::pair< G4ThreeVector, G4ThreeVector > GetFieldTransformed(const G4ThreeVector &position, const G4double t) const
Interface for BDSIM electro-magnetic fields that may or may not be local.
Definition: BDSFieldEM.hh:41
virtual std::pair< G4ThreeVector, G4ThreeVector > GetFieldTransformed(const G4ThreeVector &position, const G4double t) const
Get the field value after applying transform for local offset.
Definition: BDSFieldEM.cc:44
G4bool finiteStrength
Flag to cache whether finite nor not.
Definition: BDSFieldEM.hh:88