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) 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 "BDSDebug.hh"
20#include "BDSIntegratorCavityFringe.hh"
21#include "BDSStep.hh"
22#include "BDSUtilities.hh"
23
24#include "globals.hh"
25#include "G4Mag_EqRhs.hh"
26#include "G4PhysicalConstants.hh"
27#include "G4SystemOfUnits.hh"
28
29BDSIntegratorCavityFringe::BDSIntegratorCavityFringe(BDSMagnetStrength const* strength,
30 G4Mag_EqRhs* eqOfMIn,
31 G4double brho,
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 G4int acceleratingFieldDirectionFactor = BDS::Sign(brho);
40 efield /= acceleratingFieldDirectionFactor;
41 rmat11 = (*strength)["rmat11"];
42 rmat21 = (*strength)["rmat21"];
43 rmat22 = (*strength)["rmat22"];
44 rmat33 = (*strength)["rmat33"];
45 rmat43 = (*strength)["rmat43"];
46 rmat44 = (*strength)["rmat44"];
47}
48
49void BDSIntegratorCavityFringe::Stepper(const G4double yIn[],
50 const G4double /*dydx*/[],
51 const G4double h,
52 G4double yOut[],
53 G4double yErr[])
54{
55 // get particle charge from reverse of how it's calculated in G4Mag_EqRhs::SetChargeMomentumMass.
56 G4double charge = eq->FCof()/(eplus*c_light);
57 G4double gammaPrime = charge*efield*std::cos(phase) * CLHEP::m;
58
59 // don't update matrix for chargeless particles - remains identity matrix
60 if (BDS::IsFinite(charge))
61 {
62 G4double sign = 1;
63 if (!(G4bool)isentrance)
64 {sign = -1;}
65
66 // set energy dependent matrix terms
67 rmat21 = sign * gammaPrime / (2 * eq->TotalEnergy(yIn));
68 rmat43 = sign * gammaPrime / (2 * eq->TotalEnergy(yIn));
69 }
70
71 // apply kick in thin rmatrix base class
72 BDSIntegratorRMatrixThin::Stepper(yIn,0,h,yOut,yErr);
73
74 // set matrix terms back to zero.
75 rmat21 = 0;
76 rmat43 = 0;
77}
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())