71 bool backBeam,
bool backTrack):
122 bunch->push_back(part);
335 double Ex = scale * sep.
getEx();
336 double Ey = scale * sep.
getEy();
359 double C =
cos(ks * length);
360 double S =
sin(ks * length);
363 double yt = C * itsOrbit[
Y] - S * itsOrbit[
X];
364 double pxt = C * itsOrbit[
PX] + S * itsOrbit[
PY];
365 double pyt = C * itsOrbit[
PY] - S * itsOrbit[
PX];
367 itsOrbit[
X] = C * xt + (S / ks) * pxt;
368 itsOrbit[
Y] = C * yt + (S / ks) * pyt;
369 itsOrbit[
PX] = C * pxt - (S * ks) * xt;
370 itsOrbit[
PY] = C * pyt - (S * ks) * yt;
373 itsOrbit[
T] += length * itsOrbit[
PT] * kin * kin;
406 itsOrbit[
Y] += length * itsOrbit[
PY];
407 itsOrbit[
T] += length * itsOrbit[
PT] * kin * kin;
413 double hx = scale * field.
normal(1);
414 double ex = hx *
tan(edge);
415 double ey = hx *
tan(edge + itsOrbit[
PX]);
416 itsOrbit[
PX] += ex * itsOrbit[
X];
417 itsOrbit[
PY] -= ey * itsOrbit[
Y];
423 double hx = scale * field.
normal(1);
424 double ex = hx *
tan(edge);
425 double ey = hx *
tan(edge - itsOrbit[
PX]);
426 itsOrbit[
PX] += ex * itsOrbit[
X];
427 itsOrbit[
PY] -= ey * itsOrbit[
Y];
432 (
double length,
double refLength,
double h,
435 double x = itsOrbit[
X];
436 double px = itsOrbit[
PX];
437 double y = itsOrbit[
Y];
438 double py = itsOrbit[
PY];
439 double pt = itsOrbit[
PT];
440 double pt1 = 1.0 - pt;
445 double kx = Fx[1] * pt1;
446 double ks = (Fx[2] - Fy[1]) * (pt1 / 2.0);
447 double ky = - Fy[2] * pt1;
448 double hx = h - Fx[0] * pt1;
449 double hy = Fy[0] * pt1;
452 double kin = itsReference.getM() / itsReference.getE();
453 double refTime = refLength * kin * kin;
458 double cx, sx, dx, fx, cy, sy, dy, fy;
459 makeFocus(kx, length, cx, sx, dx, fx);
460 makeFocus(ky, length, cy, sy, dy, fy);
463 itsOrbit[
X] = sx * px + dx * hx;
464 itsOrbit[
PX] = cx * px + sx * hx;
465 itsOrbit[
Y] = sy * py + dy * hy;
466 itsOrbit[
PY] = cy * py + sy * hy;
467 itsOrbit[
T] += h * (dx * px + fx * hx);
470 double s1 = (kx + ky) / 2.0;
471 double d1 = (kx - ky) / 2.0;
472 double root =
sqrt(d1 * d1 + ks * ks);
473 double c2 = d1 / root;
474 double s2 = ks / root;
477 double cu, su, du, fu, cv, sv, dv, fv;
478 double ku = s1 + (d1 * d1 - ks * ks) / root;
479 double kv = s1 - (d1 * d1 - ks * ks) / root;
480 makeFocus(ku, length, cu, su, du, fu);
481 makeFocus(kv, length, cv, sv, dv, fv);
484 double pu = c2 * px - s2 * py;
485 double pv = c2 * py + s2 * px;
486 double hu = c2 * (h + hx) - s2 * hy;
487 double hv = c2 * hy + s2 * (h + hx);
490 itsOrbit[
X] = ((su + sv) * px + (su - sv) * pu +
491 (du + dv) * hx + (du - dv) * hu) / 2.0;
492 itsOrbit[
PX] = ((cu + cv) * px + (cu - cv) * pu +
493 (su + sv) * hx + (su - sv) * hu) / 2.0;
494 itsOrbit[
Y] = ((su + sv) * py - (su - sv) * pv +
495 (du + dv) * hy - (du - dv) *
hv) / 2.0;
496 itsOrbit[
PY] = ((cu + cv) * py - (cu - cv) * pv +
497 (su + sv) * hy - (su - sv) *
hv) / 2.0;
498 itsOrbit[
T] += ((du + dv) * px + (du - dv) * pu +
499 (fu + fv) * hx + (fu - fv) * hu) * (h / 2.0);
505 itsOrbit[
T] += refTime * pt + length * h * x;
514 int order = field.
order();
527 Fx = Fxt + field.
normal(order);
528 Fy = Fyt - field.
skew(order);
563 int order = field.
order();
566 double x = itsOrbit[
X];
567 double y = itsOrbit[
Y];
568 double kx = + field.
normal(order);
569 double ky = - field.
skew(order);
572 double kxt = x * kx - y * ky;
573 double kyt = x * ky + y * kx;
574 kx = kxt + field.
normal(order);
575 ky = kyt - field.
skew(order);
578 itsOrbit[
PX] -= kx * factor;
579 itsOrbit[
PY] += ky * factor;
589 double pz1 =
sqrt(pt * pt - px1 * px1 - py1 * py1);
591 itsOrbit[
PX] = euclid.
M(0, 0) * px1 + euclid.
M(1, 0) * py1 + euclid.
M(2, 0) * pz1;
592 itsOrbit[
PY] = euclid.
M(0, 1) * px1 + euclid.
M(1, 1) * py1 + euclid.
M(2, 1) * pz1;
593 double pz2 = euclid.
M(0, 2) * px1 + euclid.
M(1, 2) * py1 + euclid.
M(2, 2) * pz1;
598 euclid.
M(0, 0) * x + euclid.
M(1, 0) * y + euclid.
M(2, 0) * euclid.
getZ();
600 euclid.
M(0, 1) * x + euclid.
M(1, 1) * y + euclid.
M(2, 1) * euclid.
getZ();
602 euclid.
M(0, 2) * x + euclid.
M(1, 2) * y + euclid.
M(2, 2) * euclid.
getZ();
603 double sByPz = s2 / pz2;
606 double E =
sqrt(pt * pt + kin * kin);
609 itsOrbit[
Y] = y2 - sByPz * itsOrbit[
PY];
610 itsOrbit[
T] += pt * (- refTime / E + sByPz);
619 std::cerr <<
" <*** ERROR ***> in LinearMapper::buildSBendVectorPotential():\n"
620 <<
" attempt to use an infinite radius of curvature." <<
std::endl;
621 throw DomainError(
"buildSBendVectorPotential(const BMultipoleField &, double)");
624 int order = field.
order();
639 Ae = Ae * x + field.
normal(i);
640 Ao = Ao * x - field.
skew(i);
647 Ae = + (Ae * hx1).integral(0);
664 if(++k > order)
break;
668 Ao = Ao.derivative(0);
672 if(++k > order)
break;
688 (
double k,
double L,
double &
c,
double &s,
double &d,
double &f) {
689 double t = k * L * L;
692 s = L * (1.0 - t / 6.0);
693 d = L * L * (0.5 - t / 24.0);
694 f = L * L * L * ((1.0 / 6.0) - t / 120.0);
702 double r =
sqrt(- k);
virtual void visitSolenoid(const Solenoid &)
Apply the algorithm to a solenoid.
virtual void visitCCollimator(const CCollimator &)
Apply the algorithm to a collimator.
double & py()
Get reference to vertical momentum (no dimension).
virtual double getExitFaceRotation() const =0
Get exit pole face rotation.
virtual void visitRBend(const RBend &)
Apply the algorithm to a rectangular bend.
virtual ElementBase * getElement() const
Return the contained element.
virtual double getArcLength() const
Get arc length.
Euclid3D & offset() const
Return the offset.
virtual BMultipoleField & getField() override=0
Get multipole expansion of field.
virtual void visitCorrector(const Corrector &)
Apply the algorithm to a corrector.
virtual void visitDegrader(const Degrader &)
Apply the algorithm to a drift.
virtual void visitBeamBeam(const BeamBeam &)
Apply the algorithm to a beam-beam.
PETE_TUTree< FnAbs, typename T::PETE_Expr_t > abs(const PETE_Expr< T > &l)
double getX() const
Get displacement.
virtual BDipoleField & getField()=0
Return the corrector field.
virtual void visitSBend(const SBend &)
Apply the algorithm to a sector bend.
constexpr double e
The value of .
Track particles or bunches.
int getMaxOrder() const
Get maximum order.
virtual double getAmplitude() const =0
Get RF amplitude.
double normal(int) const
Get component.
The field of a magnetic dipole.
virtual BMultipoleField & getField() override=0
Get multipole expansion of field.
Interface for septum magnet.
virtual BMultipoleField & getField() override=0
Get multipole field.
Interface for electrostatic separator.
Euclid3D getExitPatch() const
Get patch.
virtual double getArcLength() const
Get arc length.
void applySBendBody(double length, double refLength, double h, const BMultipoleField &field, double scale)
Apply thin multipole kick (integrated over length) to all particles.
virtual double getPhase() const =0
Get RF phase.
Interface for beam position monitors.
Interface for RF Quadrupole.
A simple arc in the XZ plane.
FVector< double, 6 > itsOrbit
Tps< T > sin(const Tps< T > &x)
Sine.
double & x()
Get reference to horizontal position in m.
virtual double getBz() const =0
Get solenoid field Bz in Teslas.
Define the position of a misaligned element.
virtual void visitParallelPlate(const ParallelPlate &)
Apply the algorithm to a ParallelPlate.
double getZ() const
Get displacement.
virtual double getElementLength() const override
Get design length.
virtual void visitRFQuadrupole(const RFQuadrupole &)
Apply the algorithm to a RF quadrupole.
virtual Euclid3D getEntranceTransform() const
Get entrance patch.
virtual void visitMonitor(const Monitor &)
Apply the algorithm to a monitor.
virtual double getEx() const =0
Get horizontal component Ex of field in V/m.
Interface for general corrector.
virtual double getEy() const =0
Get vertical component Ey of field in V/m.
Interface for beam diagnostics.
Euclid3D getEntrancePatch() const
Get patch.
virtual double getBy() const
Get vertical component.
void applyTransform(const Euclid3D &, double refLength)
Apply transform.
virtual PlanarArcGeometry & getGeometry() override=0
Get SBend geometry.
virtual void visitMarker(const Marker &)
Apply the algorithm to a marker.
Tps< T > tan(const Tps< T > &x)
Tangent.
virtual double getEntryFaceRotation() const =0
Get pole entry face rotation.
Interface for drift space.
virtual void visitAlignWrapper(const AlignWrapper &)
Apply the algorithm to an align wrapper..
double getBeta() const
The relativistic beta per particle.
double M(int row, int col) const
Get component.
Interface for general multipole.
virtual void visitSeparator(const Separator &)
Apply the algorithm to a separator.
void setOrbit(const FVector< double, 6 > orbit)
Reset the current orbit.
static Euclid3D YRotation(double angle)
Make rotation.
void applyLinearMap(double length, double refLength, double h, const FTps< double, 2 > &Fx, const FTps< double, 2 > &Fy)
Apply linear map, defined by the linear expansions Fx and Fy.
T deg(T x)
Convert radians to degrees.
Euclid3D Inverse(const Euclid3D &t)
Euclidean inverse.
virtual double getElementLength() const override
Get design length.
Tps< T > cosh(const Tps< T > &x)
Hyperbolic cosine.
virtual double getExitFaceRotation() const =0
Get exit pole face rotation.
double getBendAngle() const
Get angle.
virtual Euclid3D getExitTransform() const
Get exit patch.
virtual void visitProbe(const Probe &prob)
Apply the algorithm to a probe.
double skew(int) const
Get component.
double getQ() const
The constant charge per particle.
virtual void accept(BeamlineVisitor &visitor) const =0
Apply visitor.
virtual double getElementLength() const
Get design length.
virtual void visitComponent(const Component &)
Apply the algorithm to an arbitrary component.
void applyThinMultipole(const BMultipoleField &field, double factor)
Thin multipole kick.
virtual double getFrequency() const =0
Get RF frequencey.
constexpr double c
The velocity of light in m/s.
virtual void trackBunch(PartBunchBase< double, 3 > *bunch, const PartData &, bool revBeam, bool revTrack) const
Track particle bunch.
Interface for cyclotron collimator.
Displacement and rotation in space.
Abstract beam-beam interaction.
void applyDrift(double length)
Apply drift length.
void applyExitFringe(double edge, const BMultipoleField &field, double scale)
bool isIdentity() const
Test for identity.
Interface for cyclotron valley.
virtual double getBx() const
Get horizontal component.
virtual void visitDiagnostic(const Diagnostic &)
Apply the algorithm to a diagnostic.
virtual double getElementLength() const
Get element length.
An abstract sequence of beam line components.
virtual void visitRFCavity(const RFCavity &)
Apply the algorithm to a RF cavity.
const PartData itsReference
The reference information.
virtual void visitSeptum(const Septum &)
Apply the algorithm to a septum.
FTps substitute(const FMatrix< T, N, N > &M, int n) const
Substitute.
virtual double getElementLength() const
Get element length.
double & pt()
Get reference to relative momentum error (no dimension).
Tps< T > sqrt(const Tps< T > &x)
Square root.
FTps< double, 2 > buildSBendVectorPotential(const BMultipoleField &, double h)
Construct the vector potential for a SBend.
virtual void visitPatch(const Patch &pat)
Apply the algorithm to a patch.
virtual void visitFlexibleCollimator(const FlexibleCollimator &)
Apply the algorithm to a flexible collimator.
virtual double getEntryFaceRotation() const =0
Get pole entry face rotation.
FTps derivative(int var) const
Partial derivative.
The geometry for a RBend element.
double getP() const
The constant reference momentum per particle.
The magnetic field of a multipole.
virtual void visitLambertson(const Lambertson &)
Apply the algorithm to a Lambertson.
double getM() const
The constant mass per particle.
void applyMultipoleBody(double length, double refLength, const BMultipoleField &field, double scale)
Apply body of SBend.
Tps< T > cos(const Tps< T > &x)
Cosine.
virtual void visitMultipole(const Multipole &)
Apply the algorithm to a multipole.
virtual void visitBeamStripping(const BeamStripping &)
Apply the algorithm to a beam stripping.
FTps< double, 2 > Series2
double & y()
Get reference to vertical displacement in m.
const FVector< double, 6 > & getOrbit() const
Return the current orbit.
void applyEntranceFringe(double edge, const BMultipoleField &field, double scale)
Transforms fringing fields.
double getCurvature() const
Get curvature.
double & t()
Get reference to longitudinal displacement c*t in m.
virtual void visitCyclotronValley(const CyclotronValley &)
Apply the algorithm to a CyclotronValley.
virtual RBendGeometry & getGeometry() override=0
Get RBend geometry.
virtual double getBendAngle() const
Get angle.
static void makeFocus(double k, double L, double &c, double &s, double &d, double &f)
Helper function for finding first-order coefficients.
void setTruncOrder(int order)
Set truncation order.
double & px()
Get reference to horizontal momentum (no dimension).
Truncated power series in N variables of type T.
Interface for a geometric patch.
Interface for a single beam element.
virtual const Euclid3D & getPatch() const =0
Get patch transform.
double getY() const
Get displacement.
virtual void visitDrift(const Drift &)
Apply the algorithm to a drift.
Tps< T > sinh(const Tps< T > &x)
Hyperbolic sine.
Vector truncated power series in n variables.
static FTps makeVariable(int var)
Make variable.
int order() const
Return order.
Inform & endl(Inform &inf)
Interface for a Lambertson septum.