BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSIntegratorCavityFringe.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
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 "BDSDebug.hh"
21#include "BDSIntegratorCavityFringe.hh"
22#include "BDSStep.hh"
23#include "BDSUtilities.hh"
24
25#include "globals.hh"
26#include "G4Mag_EqRhs.hh"
27#include "G4PhysicalConstants.hh"
28#include "G4SystemOfUnits.hh"
29
30BDSIntegratorCavityFringe::BDSIntegratorCavityFringe(BDSMagnetStrength const* strength,
31 G4Mag_EqRhs* eqOfMIn,
32 G4double maximumRadiusIn):
33 BDSIntegratorRMatrixThin(strength, eqOfMIn, maximumRadiusIn),
34 phase((*strength)["phase"]),
35 efield((*strength)["efield"]),
36 isentrance((*strength)["isentrance"]),
37 eq(static_cast<BDSMagUsualEqRhs*>(eqOfM))
38{
39 rmat11 = (*strength)["rmat11"];
40 rmat21 = (*strength)["rmat21"];
41 rmat22 = (*strength)["rmat22"];
42 rmat33 = (*strength)["rmat33"];
43 rmat43 = (*strength)["rmat43"];
44 rmat44 = (*strength)["rmat44"];
45}
46
47void BDSIntegratorCavityFringe::Stepper(const G4double yIn[],
48 const G4double /*dydx*/[],
49 const G4double h,
50 G4double yOut[],
51 G4double yErr[])
52{
53 // get particle charge from reverse of how it's calculated in G4Mag_EqRhs::SetChargeMomentumMass.
54 G4double charge = eq->FCof()/(eplus*c_light);
55 G4double gammaPrime = charge*efield*std::cos(phase) * CLHEP::m;
56
57 // don't update matrix for chargeless particles - remains identity matrix
58 if (BDS::IsFinite(charge))
59 {
60 G4double sign = 1;
61 if (!(G4bool)isentrance)
62 {sign = -1;}
63
64 // set energy dependent matrix terms
65 rmat21 = sign * gammaPrime / (2 * eq->TotalEnergy(yIn));
66 rmat43 = sign * gammaPrime / (2 * eq->TotalEnergy(yIn));
67 }
68
69 // apply kick in thin rmatrix base class
70 BDSIntegratorRMatrixThin::Stepper(yIn,0,h,yOut,yErr);
71
72 // set matrix terms back to zero.
73 rmat21 = 0;
74 rmat43 = 0;
75}
BDSMagUsualEqRhs * eq
BDSIM's eqRhs class to give access to particle properties.
Integrator that just moves the particle parallel to the s axis.
Override G4Mag_UsualEqRhs, provides BDSIM integrators access to particle attributes.
G4double TotalEnergy(const G4double y[])
Calculate total particle energy.
G4double FCof() const
Accessor to variable for normalising to charge.
Efficient storage of magnet strengths.
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())