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