BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSIntegratorParallelTransport.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
20#include "BDSIntegratorParallelTransport.hh"
21#include "BDSStep.hh"
22
23#include "globals.hh"
24#include "G4ThreeVector.hh"
25
26BDSIntegratorParallelTransport::BDSIntegratorParallelTransport(G4Mag_EqRhs* eqOfMIn):
27 BDSIntegratorMag(eqOfMIn, 6)
28{;}
29
30void BDSIntegratorParallelTransport::Stepper(const G4double yIn[],
31 const G4double /*dydx*/[],
32 const G4double h,
33 G4double yOut[],
34 G4double yErr[])
35{
36 G4ThreeVector pos = G4ThreeVector(yIn[0], yIn[1], yIn[2]);
37 G4ThreeVector mom = G4ThreeVector(yIn[3], yIn[4], yIn[5]);
38 G4double momMag = mom.mag();
39
40 BDSStep localPosMom = ConvertToLocal(pos, mom, h, false);
41 G4ThreeVector localPos = localPosMom.PreStepPoint();
42 G4ThreeVector localMom = localPosMom.PostStepPoint();
43 G4ThreeVector localMomUnit = localMom.unit();
44
45 G4double x0 = localPos.x();
46 G4double y0 = localPos.y();
47 G4double z0 = localPos.z();
48
49 G4double xp0 = localMomUnit.x();
50 G4double yp0 = localMomUnit.y();
51 G4double zp0 = localMomUnit.z();
52
53 // only proceed with parallal transport if particle is paraxial
54 // judged by forward momentum > 1-limit and |transverse| < limit (default limit=0.1)
55 if (zp0 < (1.0-backupStepperMomLimit) || std::abs(xp0) > backupStepperMomLimit || std::abs(yp0) > backupStepperMomLimit)
56 {
57 AdvanceDriftMag(yIn, h, yOut, yErr);
58 SetDistChord(0);
59 return;
60 }
61
62 G4double x1 = x0;
63 G4double y1 = y0;
64 G4double z1 = z0+h;
65
66 for (G4int i = 0; i < 3; i++)
67 {
68 yErr[i] = 0;
69 yErr[i+3] = 0;
70 }
71
72 G4ThreeVector localPosOut = G4ThreeVector(x1, y1, z1);
73 G4ThreeVector localMomUnitOut = G4ThreeVector(xp0, yp0, zp0);
74 ConvertToGlobal(localPosOut, localMomUnitOut, yOut, yErr, momMag);
75}
BDSStep ConvertToLocal(G4Step const *const step, G4bool useCurvilinear=true) const
void AdvanceDriftMag(const G4double yIn[], const G4double h, G4double yOut[], G4double yErr[]) const
Error array [6] all 0.
Common functionality to BDSIM integrators.
G4double backupStepperMomLimit
void SetDistChord(G4double distChordIn)
Setter for distChord to private member.
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
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