BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSIntegratorMag.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
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 "BDSGlobalConstants.hh"
20#include "BDSIntegratorMag.hh"
21#include "BDSMagnetStrength.hh"
22#include "BDSStep.hh"
23#include "BDSUtilities.hh"
24
25#include "globals.hh" // geant4 types / globals
26#include "G4ClassicalRK4.hh"
27
28G4double BDSIntegratorMag::thinElementLength = -1; // mm
31
32BDSIntegratorMag::BDSIntegratorMag(G4Mag_EqRhs* eqOfMIn,
33 G4int nVariablesIn):
34 G4MagIntegratorStepper(eqOfMIn, nVariablesIn),
35 eqOfM(eqOfMIn),
36 nVariables(nVariablesIn),
37 zeroStrength(false),
38 distChordPrivate(0)
39{
40 backupStepper = new G4ClassicalRK4(eqOfMIn, nVariablesIn);
41 backupStepperMomLimit = BDSGlobalConstants::Instance()->BackupStepperMomLimit();
42
43 if (thinElementLength < 0)
44 {thinElementLength = BDSGlobalConstants::Instance()->ThinElementLength();}
45
46 if (nominalMatrixRelativeMomCut < 0)
47 {nominalMatrixRelativeMomCut = BDSGlobalConstants::Instance()->NominalMatrixRelativeMomCut();}
48}
49
50BDSIntegratorMag::~BDSIntegratorMag()
51{
52 delete backupStepper;
53}
54
55void BDSIntegratorMag::ConvertToGlobal(const G4ThreeVector& localPos,
56 const G4ThreeVector& localMom,
57 G4double yOut[],
58 G4double yErr[],
59 const G4double momScaling)
60{
61 BDSStep globalPosDir = ConvertToGlobalStep(localPos, localMom, false);
62 G4ThreeVector globalPos = globalPosDir.PreStepPoint();
63 G4ThreeVector globalMom = globalPosDir.PostStepPoint();
64 globalMom*=momScaling; // multiply the unit direction by magnitude to get momentum
65
66 yOut[0] = globalPos.x();
67 yOut[1] = globalPos.y();
68 yOut[2] = globalPos.z();
69
70 yOut[3] = globalMom.x();
71 yOut[4] = globalMom.y();
72 yOut[5] = globalMom.z();
73
74 // errors
75 const G4double standardError = 1e-8;
76 G4ThreeVector momUnit = globalMom.unit();
77 momUnit *= standardError;
78 for (G4int i = 0; i < 3; i++)
79 {
80 yErr[i] = momUnit[i];
81 yErr[i + 3] = 1e-40;
82 }
83}
84
BDSStep ConvertToGlobalStep(const G4ThreeVector &localPosition, const G4ThreeVector &localDirection, const G4bool useCurvilinear=true) const
static BDSGlobalConstants * Instance()
Access method.
static G4double nominalMatrixRelativeMomCut
static G4double thinElementLength
static G4bool currentTrackIsPrimary
void ConvertToGlobal(const G4ThreeVector &localPos, const G4ThreeVector &localMom, G4double yOut[], G4double yErr[], const G4double momScaling=1.0)
scaling of momentum in case localMom is a unit vector
G4MagIntegratorStepper * backupStepper
BDSIntegratorMag()=delete
Private default constructor to force use of specific constructor.
A simple class to represent the positions of a step.
Definition: BDSStep.hh:33
G4ThreeVector PostStepPoint() const
Accessor.
Definition: BDSStep.hh:43
G4ThreeVector PreStepPoint() const
Accessor.
Definition: BDSStep.hh:42