19#include "BDSCavityInfo.hh"
21#include "BDSException.hh"
22#include "BDSFieldEMRFCavity.hh"
23#include "BDSMagnetStrength.hh"
24#include "BDSUtilities.hh"
26#include "CLHEP/Units/PhysicalConstants.h"
28#include "G4ThreeVector.hh"
41 (*strength)[
"frequency"],
43 (*strength)[
"equatorradius"],
44 (*strength)[
"synchronousT0"])
47BDSFieldEMRFCavity::BDSFieldEMRFCavity(G4double eFieldAmplitude,
50 G4double cavityRadiusIn,
51 G4double synchronousTIn):
52 eFieldMax(eFieldAmplitude),
54 cavityRadius(cavityRadiusIn),
55 synchronousT(synchronousTIn),
56 normalisedCavityRadius(j0FirstZero/cavityRadius),
57 angularFrequency(CLHEP::twopi * frequencyIn)
60 if (!
BDS::IsFinite(cavityRadiusIn) || std::isnan(normalisedCavityRadius) || std::isinf(normalisedCavityRadius))
61 {
throw BDSException(__METHOD_NAME__,
"no cavity radius supplied - required for pill box model");}
65 const G4double t)
const
68 G4double phi = std::atan2(position.y(),position.x());
69 G4double r = std::hypot(position.x(),position.y());
77 G4double J0r = TMath::BesselJ0(rNormalised);
78 G4double J1r = TMath::BesselJ1(rNormalised);
82 G4double Bmax = hMax * CLHEP::mu0;
86 G4double Ez =
eFieldMax * J0r * std::cos(arg);
87 G4double Bphi = Bmax * J1r * std::sin(arg);
90 G4TwoVector bxby(0,Bphi);
92 G4double Bx = bxby.x();
93 G4double By = bxby.y();
96 G4ThreeVector LocalB = G4ThreeVector(Bx, By, 0);
97 G4ThreeVector LocalE = G4ThreeVector(0, 0, Ez);
99 auto result = std::make_pair(LocalB, LocalE);
108 G4double rfWavelength = CLHEP::c_light / frequency;
109 G4double piGOverBetaLambda = (CLHEP::pi * zLength) / (beta * rfWavelength);
110 G4double transitTimeFactor = std::sin(piGOverBetaLambda +
phase) / piGOverBetaLambda;
111 return transitTimeFactor;
General exception with possible name of object and message.
Pill box cavity electromagnetic field.
virtual std::pair< G4ThreeVector, G4ThreeVector > GetField(const G4ThreeVector &position, const G4double t) const
Accessor to get B and E field.
const G4double angularFrequency
Angular frequency calculated from frequency - cached to avoid repeated calculation.
G4double phase
Phase offset of the oscillator.
static const G4double j0FirstZero
X coordinate of first 0 point for bessel J0.
static const G4double Z0
Impedance of free space.
G4double eFieldMax
Maximum field in V/m.
const G4double normalisedCavityRadius
Pre-calculated normalised calculated radius w.r.t. bessel first 0.
static G4double TransitTimeFactor(G4double frequency, G4double phase, G4double zLength, G4double beta)
General function put here as it represents the equations in this class.
Efficient storage of magnet strengths.
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())