30#include <gsl/gsl_sf_gamma.h>
49 boundingBoxLength_m(0.0),
51 horizontalApert_m(0.5) {
56 fringeField_l(right.fringeField_l),
57 fringeField_r(right.fringeField_r),
58 maxOrder_m(right.maxOrder_m),
59 transMaxOrder_m(right.transMaxOrder_m),
60 transProfile_m(right.transProfile_m),
61 length_m(right.length_m),
62 entranceAngle_m(right.entranceAngle_m),
63 rotation_m(right.rotation_m),
64 boundingBoxLength_m(right.boundingBoxLength_m),
65 verticalApert_m(right.verticalApert_m),
66 horizontalApert_m(right.horizontalApert_m),
83 B[0] =
getBx(R_prime);
84 B[1] =
getBz(R_prime);
85 B[2] =
getBs(R_prime);
91 for(
int i = 0; i < 3; i++) {
111 R_pprime[1] = R_prime[1];
131 const double &lambda_l,
132 const double &lambda_r) {
150 Bz = Bz * R[1] * R[1] +
getFn(n, R[0], R[2])
151 / gsl_sf_fact(2 * n);
165 / gsl_sf_fact(2 * n + 1);
180 / gsl_sf_fact(2 * n + 1);
202 if (n > transMaxOrder) {
206 for(std::size_t i = 1; i <= n; i++) {
207 for(std::size_t j = 0; j <= transMaxOrder; j++) {
209 temp[j] = temp[j + 1] * (j + 1);
215 std::size_t k = transMaxOrder - n + 1;
218 func = func * x + temp[k];
230 double stepSize = 1
e-3;
231 deriv += 1. *
getFn(n, x - 2. * stepSize, s);
232 deriv += -8. *
getFn(n, x - stepSize, s);
233 deriv += 8. *
getFn(n, x + stepSize, s);
234 deriv += -1. *
getFn(n, x + 2. * stepSize, s);
235 deriv /= 12 * stepSize;
246 double stepSize = 1
e-3;
247 deriv += 1. *
getFn(n, x, s - 2. * stepSize);
248 deriv += -8. *
getFn(n, x, s - stepSize);
249 deriv += 8. *
getFn(n, x, s + stepSize);
250 deriv += -1. *
getFn(n, x, s + 2. * stepSize);
251 deriv /= 12 * stepSize;
double integrate(const double &a, const double &s0, const double &lambdaleft, const double &lambdaright, const int &n)
Perform Cauchy's integral to find derivative.
constexpr double e
The value of.
Interface for a single beam element.
PartBunch_t * RefPartBunch_m
bool getFlagDeleteOnTransverseExit() const
Calculate the Tanh function (e.g.
double getNegTanh(double x, int n) const
Returns the value of tanh((x-x0)/lambda) or its derivative.
double getTanh(double x, int n) const
Returns the value of tanh((x+x0)/lambda) or its derivative.
~MultipoleTBase()
Destructor.
std::size_t getTransMaxOrder() const
Get the maximum order in the given transverse profile.
bool insideAperture(const Vector_t< double, 3 > &R)
Tests if inside the magnet.
virtual double getFn(const std::size_t &n, const double &x, const double &s)=0
Calculate fn(x, s) by expanding the differential operator (from Laplacian and scalar potential) in te...
virtual void transformCoords(Vector_t< double, 3 > &R)=0
Transform to Frenet-Serret coordinates for sector magnets.
virtual void transformBField(Vector_t< double, 3 > &B, const Vector_t< double, 3 > &R)=0
Transform B-field from Frenet-Serret coordinates to lab coordinates.
endfieldmodel::Tanh fringeField_l
std::size_t maxOrder_m
Number of terms in z expansion used in calculating field components.
virtual double getBx(const Vector_t< double, 3 > &R)
Returns the radial component of the field Returns zero far outside fringe field .
std::size_t getMaxOrder() const
Get the number of terms used in calculation of field components.
virtual double getBs(const Vector_t< double, 3 > &R)
Returns the component of the field along the central axis Returns zero far outside fringe field .
endfieldmodel::Tanh fringeField_r
std::vector< double > getTransProfile() const
Get all terms of transverse profile.
Vector_t< double, 3 > rotateFrame(const Vector_t< double, 3 > &R)
Rotate frame for skew elements Consecutive rotations: 1st -> about central axis 2nd -> azimuthal rot...
double getTransDeriv(const std::size_t &n, const double &x)
Returns the value of the transverse field n-th derivative at x Transverse field is a polynomial in x...
double getBz(const Vector_t< double, 3 > &R)
Returns the vertical field component Returns zero far outside fringe field .
MultipoleTBase()
Default constructor.
bool apply(const Vector_t< double, 3 > &R, const Vector_t< double, 3 > &P, const double &t, Vector_t< double, 3 > &E, Vector_t< double, 3 > &B)
Calculate the field at some arbitrary position If particle is outside field map true is returned,...
virtual double getScaleFactor(const double &x, const double &s)=0
Returns the scale factor .
std::size_t transMaxOrder_m
Highest power in given mid-plane field.
double getFnDerivX(const std::size_t &n, const double &x, const double &s)
Calculate partial derivative of fn wrt x using a 5-point finite difference formula Error of order ste...
bool setFringeField(const double &s0, const double &lambda_left, const double &lambda_right)
Set fringe field model Tanh model used here .
double getFringeDeriv(const std::size_t &n, const double &s)
Returns the value of the fringe field n-th derivative at s.
Vector_t< double, 3 > rotateFrameInverse(Vector_t< double, 3 > &B)
Inverse of the 1st rotation in rotateFrame() method Used to rotate B field back to global coordinate...
double getFnDerivS(const std::size_t &n, const double &x, const double &s)
Calculate partial derivative of fn wrt s using a 5-point finite difference formula Error of order ste...