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