18#include "BDSBeamlineIntegral.hh"
19#include "BDSCavityFieldType.hh"
20#include "BDSComponentFactory.hh"
22#include "BDSException.hh"
23#include "BDSFieldEMRFCavity.hh"
24#include "BDSGlobalConstants.hh"
25#include "BDSParticleDefinition.hh"
26#include "BDSUtilities.hh"
30#include "parser/element.h"
31#include "parser/elementtype.h"
33#include "CLHEP/Units/PhysicalConstants.h"
34#include "CLHEP/Units/SystemOfUnits.h"
40 G4double integratedArcLength,
41 G4bool integrateKineticEnergyIn):
42 integrateKineticEnergy(integrateKineticEnergyIn),
43 synchronousTAtEnd(T0In),
44 synchronousTAtMiddleOfLastElement(T0In),
45 arcLength(integratedArcLength),
46 designParticle(incomingParticle),
47 changeOfEnergyEncountered(false),
51BDSBeamlineIntegral::~BDSBeamlineIntegral()
57 G4double thisComponentArcLength = componentAsDefined.
l*CLHEP::m;
58 if (componentAsDefined.
type == GMAD::ElementType::_RBEND)
60 G4double componentChordLength;
64 designParticle.
BRho(),
65 thisComponentArcLength,
70 arcLength += thisComponentArcLength;
72 G4double v0 = designParticle.
Velocity();
77 switch (componentAsDefined.
type)
79 case GMAD::ElementType::_RF:
81 G4double particleCharge = designParticle.
Charge();
82 G4double phase = componentAsDefined.
phase * CLHEP::rad;
83 G4double frequency = componentAsDefined.
frequency * CLHEP::hertz;
88 BDSFieldType fieldType = BDS::FieldTypeFromCavityFieldType(tp);
92 case BDSCavityFieldType::constantinz:
94 dEk = particleCharge * eField * thisComponentArcLength * std::cos(phase);
97 case BDSCavityFieldType::pillbox:
100 {
throw BDSException(__METHOD_NAME__,
"for a pillbox cavity field, the frequency must be non-zero");}
102 dEk = particleCharge * eField * thisComponentArcLength * transitTimeFactor;
114 G4bool changeOfEnergyEncounteredThisTime =
BDS::IsFinite(dEk, 1e-7);
115 changeOfEnergyEncountered = changeOfEnergyEncountered || changeOfEnergyEncounteredThisTime;
117 if (changeOfEnergyEncounteredThisTime)
124 G4double v1 = designParticle.
Velocity();
125 G4double vMean = (v1 + v0) / 2.0;
126 G4double dT = thisComponentArcLength / vMean;
128 G4double dTMiddle = 0.5*thisComponentArcLength / (0.5*(v1-v0) + v0);
129 synchronousTAtMiddleOfLastElement = synchronousTAtEnd + dTMiddle;
132 synchronousTAtEnd += dT;
139 G4double synchronousTAtMiddle = copy.synchronousTAtMiddleOfLastElement;
140 return synchronousTAtMiddle;
147 G4double synchronousTAtEndLocal = copy.synchronousTAtEnd;
148 return synchronousTAtEndLocal;
A class that holds the current integrated quantities along a beam line.
void Integrate(const GMAD::Element &componentAsDefined)
G4bool integrateKineticEnergy
On by default, but allow control to not integrate it for old behaviour.
G4double ProvideSynchronousTAtEndOfNextElement(const GMAD::Element *el) const
G4int rigidityCount
Which change in rigidity we're at. Starts at 0, +1 after each change. Used for naming.
G4double ProvideSynchronousTAtCentreOfNextElement(const GMAD::Element *el) const
static void CalculateAngleAndFieldRBend(const GMAD::Element *el, G4double brhoIn, G4double &arcLength, G4double &chordLength, G4double &field, G4double &angle)
static G4double EFieldFromElement(GMAD::Element const *el, BDSFieldType fieldType, G4double cavityLength, const BDSParticleDefinition &incomingParticle)
General exception with possible name of object and message.
static G4double TransitTimeFactor(G4double frequency, G4double phase, G4double zLength, G4double beta)
General function put here as it represents the equations in this class.
static BDSGlobalConstants * Instance()
Access method.
Wrapper for particle definition.
G4double Charge() const
Accessor.
G4double BRho() 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