BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSIntegratorMag.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 "BDSGlobalConstants.hh"
19#include "BDSIntegratorMag.hh"
20#include "BDSMagnetStrength.hh"
21#include "BDSStep.hh"
22#include "BDSUtilities.hh"
23
24#include "globals.hh" // geant4 types / globals
25#include "G4ClassicalRK4.hh"
26
27G4double BDSIntegratorMag::thinElementLength = -1; // mm
30
31BDSIntegratorMag::BDSIntegratorMag(G4Mag_EqRhs* eqOfMIn,
32 G4int nVariablesIn):
33 G4MagIntegratorStepper(eqOfMIn, nVariablesIn),
34 eqOfM(eqOfMIn),
35 nVariables(nVariablesIn),
36 zeroStrength(false),
37 distChordPrivate(0)
38{
39 backupStepper = new G4ClassicalRK4(eqOfMIn, nVariablesIn);
40 backupStepperMomLimit = BDSGlobalConstants::Instance()->BackupStepperMomLimit();
41
42 if (thinElementLength < 0)
43 {thinElementLength = BDSGlobalConstants::Instance()->ThinElementLength();}
44
45 if (nominalMatrixRelativeMomCut < 0)
46 {nominalMatrixRelativeMomCut = BDSGlobalConstants::Instance()->NominalMatrixRelativeMomCut();}
47}
48
49BDSIntegratorMag::~BDSIntegratorMag()
50{
51 delete backupStepper;
52}
53
54void BDSIntegratorMag::ConvertToGlobal(const G4ThreeVector& localPos,
55 const G4ThreeVector& localMom,
56 G4double yOut[],
57 G4double yErr[],
58 const G4double momScaling)
59{
60 BDSStep globalPosDir = ConvertToGlobalStep(localPos, localMom, false);
61 G4ThreeVector globalPos = globalPosDir.PreStepPoint();
62 G4ThreeVector globalMom = globalPosDir.PostStepPoint();
63 globalMom*=momScaling; // multiply the unit direction by magnitude to get momentum
64
65 yOut[0] = globalPos.x();
66 yOut[1] = globalPos.y();
67 yOut[2] = globalPos.z();
68
69 yOut[3] = globalMom.x();
70 yOut[4] = globalMom.y();
71 yOut[5] = globalMom.z();
72
73 // errors
74 const G4double standardError = 1e-8;
75 G4ThreeVector momUnit = globalMom.unit();
76 momUnit *= standardError;
77 for (G4int i = 0; i < 3; i++)
78 {
79 yErr[i] = momUnit[i];
80 yErr[i + 3] = 1e-40;
81 }
82}
83
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:32
G4ThreeVector PostStepPoint() const
Accessor.
Definition BDSStep.hh:42
G4ThreeVector PreStepPoint() const
Accessor.
Definition BDSStep.hh:41