19#include "BDSBeamlineIntegral.hh"
20#include "BDSCavityFieldType.hh"
21#include "BDSComponentFactory.hh"
23#include "BDSException.hh"
24#include "BDSFieldEMRFCavity.hh"
25#include "BDSGlobalConstants.hh"
26#include "BDSParticleDefinition.hh"
27#include "BDSUtilities.hh"
31#include "parser/element.h"
32#include "parser/elementtype.h"
34#include "CLHEP/Units/PhysicalConstants.h"
35#include "CLHEP/Units/SystemOfUnits.h"
41 G4double integratedArcLength,
42 G4bool integrateKineticEnergyIn):
43 integrateKineticEnergy(integrateKineticEnergyIn),
44 synchronousTAtEnd(T0In),
45 synchronousTAtMiddleOfLastElement(T0In),
46 arcLength(integratedArcLength),
47 designParticle(incomingParticle),
48 changeOfEnergyEncountered(false),
52BDSBeamlineIntegral::~BDSBeamlineIntegral()
58 G4double thisComponentArcLength = componentAsDefined.
l*CLHEP::m;
59 if (componentAsDefined.
type == GMAD::ElementType::_RBEND)
61 G4double componentChordLength;
65 designParticle.
BRho(),
66 thisComponentArcLength,
71 arcLength += thisComponentArcLength;
73 G4double v0 = designParticle.
Velocity();
78 switch (componentAsDefined.
type)
80 case GMAD::ElementType::_RF:
82 G4double particleCharge = designParticle.
Charge();
83 G4double phase = componentAsDefined.
phase * CLHEP::rad;
84 G4double frequency = componentAsDefined.
frequency * CLHEP::hertz;
89 BDSFieldType fieldType = BDS::FieldTypeFromCavityFieldType(tp);
93 case BDSCavityFieldType::constantinz:
95 dEk = particleCharge * eField * thisComponentArcLength * std::cos(phase);
98 case BDSCavityFieldType::pillbox:
101 {
throw BDSException(__METHOD_NAME__,
"for a pillbox cavity field, the frequency must be non-zero");}
103 dEk = particleCharge * eField * thisComponentArcLength * transitTimeFactor;
115 G4bool changeOfEnergyEncounteredThisTime =
BDS::IsFinite(dEk, 1e-7);
116 changeOfEnergyEncountered = changeOfEnergyEncountered || changeOfEnergyEncounteredThisTime;
118 if (changeOfEnergyEncounteredThisTime)
125 G4double v1 = designParticle.
Velocity();
126 G4double vMean = (v1 + v0) / 2.0;
127 G4double dT = thisComponentArcLength / vMean;
129 G4double dTMiddle = 0.5*thisComponentArcLength / (0.5*(v1-v0) + v0);
130 synchronousTAtMiddleOfLastElement = synchronousTAtEnd + dTMiddle;
133 synchronousTAtEnd += dT;
140 G4double synchronousTAtMiddle = copy.synchronousTAtMiddleOfLastElement;
141 return synchronousTAtMiddle;
148 G4double synchronousTAtEndLocal = copy.synchronousTAtEnd;
149 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