19#include "BDSBeamlineIntegral.hh"
20#include "BDSCavityFieldType.hh"
21#include "BDSComponentFactory.hh"
23#include "BDSException.hh"
24#include "BDSParticleDefinition.hh"
25#include "BDSUtilities.hh"
29#include "parser/element.h"
30#include "parser/elementtype.h"
32#include "CLHEP/Units/PhysicalConstants.h"
33#include "CLHEP/Units/SystemOfUnits.h"
40 G4double integratedArcLength):
41 synchronousTAtEnd(T0In),
42 synchronousTAtMiddleOfLastElement(T0In),
43 arcLength(integratedArcLength),
44 designParticle(incomingParticle)
47BDSBeamlineIntegral::~BDSBeamlineIntegral()
53 G4double thisComponentArcLength = componentAsDefined.
l*CLHEP::m;
54 arcLength += thisComponentArcLength;
56 G4double v0 = designParticle.
Velocity();
61 G4double particleCharge = designParticle.
Charge();
62 G4double phase = componentAsDefined.
phase * CLHEP::rad;
63 G4double cosPhase = std::cos(phase);
64 G4double frequency = componentAsDefined.
frequency * CLHEP::hertz;
66 switch (componentAsDefined.
type)
68 case GMAD::ElementType::_RF:
75 case BDSCavityFieldType::constantinz:
77 dEk = particleCharge * eField * thisComponentArcLength * cosPhase;
80 case BDSCavityFieldType::pillbox:
83 {
throw BDSException(__METHOD_NAME__,
"for a pillbox cavity field, the frequency must be non-zero");}
84 G4double rfWavelength = CLHEP::c_light / frequency;
85 G4double piGOverBetaLambda = CLHEP::pi * thisComponentArcLength / designParticle.
Beta() * rfWavelength;
86 G4double transitTimeFactor = std::sin(piGOverBetaLambda) / piGOverBetaLambda;
87 dEk = particleCharge * eField * thisComponentArcLength * transitTimeFactor * cosPhase;
102 G4double v1 = designParticle.
Velocity();
103 G4double vMean = (v1 + v0) / 2.0;
104 G4double dT = thisComponentArcLength / vMean;
106 G4double dTMiddle = thisComponentArcLength / ( (0.5*(v1-v0) + v0 ) / 2.0);
107 synchronousTAtMiddleOfLastElement = synchronousTAtEnd + dTMiddle;
110 synchronousTAtEnd += dT;
void Integrate(const GMAD::Element &componentAsDefined)
static G4double EFieldFromElement(GMAD::Element const *el, G4double cavityLength)
General exception with possible name of object and message.
Wrapper for particle definition.
G4double Charge() const
Accessor.
G4double Beta() const
Accessor.
G4double Velocity() const
Accessor.
void ApplyChangeInKineticEnergy(G4double dEk)
Utility function to update quantities by adding on dEK (can be negative).
Improve type-safety of native enum data type in C++.
type underlying() const
return underlying value (can be used in switch statement)
BDSCavityFieldType DetermineCavityFieldType(G4String cavityFieldType)
function to determine the enum type of the cavity field type (case-insensitive)
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())
std::string cavityFieldType
Name for type of field to use in a cavity.
double phase
phase of rf cavity (rad)
ElementType type
element enum
double frequency
frequency for rf cavity in Hz