BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSFieldMagInterpolated2Layer.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 "BDSException.hh"
20#include "BDSExtent.hh"
21#include "BDSFieldMagInterpolated.hh"
22#include "BDSFieldMagInterpolated2Layer.hh"
23
24#include "G4ThreeVector.hh"
25
26BDSFieldMagInterpolated2Layer::BDSFieldMagInterpolated2Layer(BDSFieldMagInterpolated* mainFieldIn,
27 BDSFieldMagInterpolated* subFieldIn):
28 mainField(mainFieldIn),
29 subField(subFieldIn),
30 subFieldExtent(subFieldIn->Extent())
31{
32 if (!mainField->ExtentNoOffset().Encompasses(subFieldIn->ExtentNoOffset()))
33 {throw BDSException(__METHOD_NAME__, "sub field in field map is bigger than main field.");}
34}
35
36BDSFieldMagInterpolated2Layer::~BDSFieldMagInterpolated2Layer()
37{
38 delete mainField;
39 delete subField;
40}
41
42G4ThreeVector BDSFieldMagInterpolated2Layer::GetField(const G4ThreeVector& position,
43 const G4double t) const
44{
45 // transformations in these objects are only the transform of the field definition,
46 // not w.r.t. the beam line which is done already on the incoming position for this instance
47 if (subFieldExtent.Encompasses(position))
48 {return subField->GetFieldTransformed(position, t);}
49 else
50 {return mainField->GetFieldTransformed(position, t);}
51}
52
54{
55 return mainField->TimeVarying() || subField->TimeVarying();
56}
General exception with possible name of object and message.
G4bool Encompasses(const G4ThreeVector &point) const
Return whether the extent encompasses the point. True if point lies inside the extent.
Definition BDSExtent.cc:189
virtual G4ThreeVector GetField(const G4ThreeVector &position, const G4double t=0) const
Return the interpolated field value at a given point.
Class to provide scaling and a base class pointer for interpolator fields.
virtual G4bool TimeVarying() const
BDSExtent ExtentNoOffset() const
Extent of field without any offset (ie in its own coordinate frame).
virtual G4ThreeVector GetFieldTransformed(const G4ThreeVector &position, const G4double t) const
Get the field value after applying transform for local offset.