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